Skip to content

Commit

Permalink
test: fix failing tests are config file tweak (relation key)
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Aug 5, 2024
1 parent e6f8121 commit 5c6cf72
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
13 changes: 9 additions & 4 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ def test_yaml_no_joins():
qc.parseYaml(f"{rootdir}/buildings_no_join.yaml")

selected = qc.config["select"]
assert len(selected.keys()) == 3
# Keys: nodes, ways_poly, ways_line, relationships
assert len(selected.keys()) == 4
assert len(list(selected.values())[0]) == 4

# Keys: nodes, ways_poly, ways_line, relationships
where = qc.config["where"]
assert len(where.keys()) == 3
assert len(where.keys()) == 4

nodes = list(where.values())[0]
assert len(nodes) == 4
Expand All @@ -129,11 +131,11 @@ def test_yaml_no_joins_bytesio():
qc.parseYaml(yaml_obj)

selected = qc.config["select"]
assert len(selected.keys()) == 3
assert len(selected.keys()) == 4
assert len(list(selected.values())[0]) == 4

where = qc.config["where"]
assert len(where.keys()) == 3
assert len(where.keys()) == 4

nodes = list(where.values())[0]
assert len(nodes) == 4
Expand Down Expand Up @@ -169,6 +171,7 @@ def test_yaml_bytesio_from_string():
"nodes": [{"building": {}}, {"highway": {}}, {"waterway": {}}],
"ways_poly": [{"building": {}}, {"highway": {}}, {"waterway": {}}],
"ways_line": [{"building": {}}, {"highway": {}}, {"waterway": {}}],
"relations": [],
},
"tables": ["nodes", "ways_poly", "ways_line"],
"where": {
Expand All @@ -187,9 +190,11 @@ def test_yaml_bytesio_from_string():
{"highway": ["not null"], "op": "or"},
{"waterway": ["not null"], "op": "or"},
],
"relations": [],
},
"keep": [],
}
print(config)
assert config == expected_config


Expand Down
22 changes: 5 additions & 17 deletions tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,29 @@


def test_yaml():
hits = 0
db = DatabaseAccess("underpass")
infile = open(f"{rootdir}/AOI.geojson", "r")
poly = geojson.load(infile)
qc = QueryConfig()
qc.parseYaml(f"{rootdir}/buildings.yaml")
sql = db.createSQL(qc, True)
out = "SELECT ST_AsText(geom), osm_id, version, tags->>'building', tags->>'amenity', tags->>'building:material', tags->>'roof:material' FROM nodes WHERE tags->>'building' ='yes' OR tags->>'amenity' IS NOT NULL OR tags->>'building:material' ='wood' AND tags->>'roof:material' ='metal'"
if sql[0] == out:
hits += 1
out = "SELECT ST_AsText(geom) AS geometry, osm_id, version, tags->>'building', tags->>'amenity', tags->>'building:material', tags->>'roof:material' FROM nodes WHERE tags->>'building' ='yes' OR tags->>'amenity' IS NOT NULL OR tags->>'building:material' ='wood' AND tags->>'roof:material' ='metal'"
assert sql[0] == out

qc = QueryConfig()
json = db.createJson(qc, poly, True)
geojson.loads(json)
# import epdb ; epdb.st()
# if json == out:
# hits += 1

assert hits == 1


def test_json():
hits = 0
db = DatabaseAccess("underpass")
infile = open(f"{rootdir}/AOI.geojson", "r")
geojson.load(infile)
qc = QueryConfig()
qc.parseJson(f"{rootdir}/levels.json")
sql = db.createSQL(qc, True)
out = "SELECT ST_AsText(geom), osm_id, version, tags->>'building', tags->>'ground_floor:height', tags->>'capacity:persons', tags->>'building:structure', tags->>'building:condition', tags->>'name', tags->>'admin_level', tags->>'building:material', tags->>'office', tags->>'building:roof', tags->>'backup_generator', tags->>'access:roof', tags->>'building:levels', tags->>'building:floor', tags->>'addr:full', tags->>'addr:city', tags->>'source' FROM nodes WHERE tags->>'amenity' IN ('bank', 'ferry_terminal', 'bus_station', 'fuel', 'kindergarten', 'school', 'college', 'university', 'place_of_worship', 'marketplace', 'clinic', 'hospital', 'police', 'fire_station') OR tags->>'building' IN ('bank', 'aerodrome', 'ferry_terminal', 'train_station', 'bus_station', 'pumping_station', 'power_substation', 'kindergarten', 'school', 'college', 'university', 'mosque', 'church', 'temple', 'supermarket', 'marketplace', 'clinic', 'hospital', 'police', 'fire_station', 'stadium ', 'sports_centre', 'governor_office ', 'townhall ', 'subdistrict_office ', 'village_office ', 'community_group_office', 'government_office') OR tags->>'man_made' IN ('tower', 'water_tower', 'pumping_station') OR tags->>'tower' ='communication' OR tags->>'aeroway' ='aerodrome' OR tags->>'railway' ='station' OR tags->>'emergency' ='fire_hydrant' OR tags->>'landuse' IN ('reservoir', 'recreation_gound') OR tags->>'waterway' ='floodgate' OR tags->>'natural' ='spring' OR tags->>'power' IN ('tower', 'substation') OR tags->>'shop' ='supermarket' OR tags->>'leisure' IN ('stadium ', ' sports_centre ', ' pitch ', ' swimming_pool', 'park') OR tags->>'office' ='government'"
if sql[0] == out:
hits += 1
out = "SELECT ST_AsText(geom) AS geometry, osm_id, version, tags->>'building', tags->>'ground_floor:height', tags->>'capacity:persons', tags->>'building:structure', tags->>'building:condition', tags->>'name', tags->>'admin_level', tags->>'building:material', tags->>'office', tags->>'building:roof', tags->>'backup_generator', tags->>'access:roof', tags->>'building:levels', tags->>'building:floor', tags->>'addr:full', tags->>'addr:city', tags->>'source' FROM nodes WHERE tags->>'amenity' IN ('bank', 'ferry_terminal', 'bus_station', 'fuel', 'kindergarten', 'school', 'college', 'university', 'place_of_worship', 'marketplace', 'clinic', 'hospital', 'police', 'fire_station') OR tags->>'building' IN ('bank', 'aerodrome', 'ferry_terminal', 'train_station', 'bus_station', 'pumping_station', 'power_substation', 'kindergarten', 'school', 'college', 'university', 'mosque', 'church', 'temple', 'supermarket', 'marketplace', 'clinic', 'hospital', 'police', 'fire_station', 'stadium ', 'sports_centre', 'governor_office ', 'townhall ', 'subdistrict_office ', 'village_office ', 'community_group_office', 'government_office') OR tags->>'man_made' IN ('tower', 'water_tower', 'pumping_station') OR tags->>'tower' ='communication' OR tags->>'aeroway' ='aerodrome' OR tags->>'railway' ='station' OR tags->>'emergency' ='fire_hydrant' OR tags->>'landuse' IN ('reservoir', 'recreation_gound') OR tags->>'waterway' ='floodgate' OR tags->>'natural' ='spring' OR tags->>'power' IN ('tower', 'substation') OR tags->>'shop' ='supermarket' OR tags->>'leisure' IN ('stadium ', ' sports_centre ', ' pitch ', ' swimming_pool', 'park') OR tags->>'office' ='government'"
assert sql[0] == out

qc.parseJson(f"{rootdir}/levels.json")
json = db.createJson(qc, True)
Expand All @@ -85,10 +76,7 @@ def test_json():
"police",
"fire_station",
]
if item == new["filters"]["tags"]["point"]["join_or"]["amenity"]:
hits += 1

assert hits == 2
assert item == new["filters"]["tags"]["point"]["join_or"]["amenity"]


if __name__ == "__main__":
Expand Down

0 comments on commit 5c6cf72

Please sign in to comment.