add test for filtering mastermap (not working)
This commit is contained in:
parent
103300f969
commit
f6cb0c488e
1
etl/__init__.py
Normal file
1
etl/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .filter_mastermap import filter_mastermap
|
@ -14,20 +14,19 @@ csv.field_size_limit(sys.maxsize)
|
|||||||
def main(mastermap_path):
|
def main(mastermap_path):
|
||||||
mm_paths = sorted(glob.glob(os.path.join(mastermap_path, "*.gml.csv")))
|
mm_paths = sorted(glob.glob(os.path.join(mastermap_path, "*.gml.csv")))
|
||||||
for mm_path in mm_paths:
|
for mm_path in mm_paths:
|
||||||
filter(mm_path)
|
filter_mastermap(mm_path)
|
||||||
|
|
||||||
|
|
||||||
def filter(mm_path)
|
def filter_mastermap(mm_path)
|
||||||
output_path = "{}.filtered.csv".format(str(mm_path).replace(".gml.csv", ""))
|
output_path = "{}.filtered.csv".format(str(mm_path).replace(".gml.csv", ""))
|
||||||
output_fieldnames = ('WKT', 'fid', 'descriptiveGroup')
|
output_fieldnames = ('WKT', 'fid', 'descriptiveGroup')
|
||||||
# Open the input csv with all polygons, buildings and others
|
# Open the input csv with all polygons, buildings and others
|
||||||
with open(mm_path, 'r') as fh:
|
with open(mm_path, 'r') as fh:
|
||||||
r = csv.DictReader(fh)
|
r = csv.DictReader(fh)
|
||||||
# Open a new buildings csv
|
# Open a new output csv that will contain just buildings
|
||||||
with open(output_path, 'w') as output_fh:
|
with open(output_path, 'w') as output_fh:
|
||||||
w = csv.DictWriter(output_fh, fieldnames=output_fieldnames)
|
w = csv.DictWriter(output_fh, fieldnames=output_fieldnames)
|
||||||
w.writeheader()
|
w.writeheader()
|
||||||
# Then write to the output csv buildings only
|
|
||||||
for line in r:
|
for line in r:
|
||||||
if 'Building' in line['descriptiveGroup']:
|
if 'Building' in line['descriptiveGroup']:
|
||||||
w.writerow(line)
|
w.writerow(line)
|
||||||
|
8
tests/test_filter.py
Normal file
8
tests/test_filter.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import pytest
|
||||||
|
from etl import filter_mastermap
|
||||||
|
|
||||||
|
def test_filter_mastermap():
|
||||||
|
"""Test that MasterMap CSV can be correctly filtered to include only buildings."""
|
||||||
|
input_file = ""
|
||||||
|
expected_output = ""
|
||||||
|
assert filter_mastermap(input_file) == expected_output
|
Loading…
Reference in New Issue
Block a user