Skip to content

Commit

Permalink
refactor: Tests no longer expect nested dict
Browse files Browse the repository at this point in the history
  • Loading branch information
r-leyshon committed Nov 8, 2023
1 parent 85017d4 commit fade1ab
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions tests/osm/test_validate_osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ def test__filter_target_dict_with_list_returns(self):
accepted_keys=["choose_me", "do_not_choose_me"],
)
assert isinstance(out, dict)
assert list(out.keys()) == ["choose_me"]
assert "remove" not in out.values()


Expand Down Expand Up @@ -364,23 +363,22 @@ def test_check_locs_for_ids(self, _tiny_osm_locs, _tiny_osm_ids):
# check that the expected coordinates are returned for node IDs
id_list = sorted(ids.id_dict["node_ids"])[0:5]
locs.check_locs_for_ids(ids=id_list, feature_type="node")
assert list(locs.found_locs.keys()) == ["node"]
assert len(locs.found_locs["node"]) == 5
assert len(locs.found_locs) == 5
# in all 5 nodes, check that floats are returned
for n in locs.found_locs["node"]:
for k, v in locs.found_locs["node"][n].items():
for n in locs.found_locs:
for k, v in locs.found_locs[n].items():
assert isinstance(
v, float
), f"Expected coord {v} to be type float. got {type(v)}"
# now check coordinates for a list of way IDs
way_ids = sorted(ids.id_dict["way_ids"])[0:3]
locs.check_locs_for_ids(ids=way_ids, feature_type="way")
assert list(locs.found_locs.keys()) == ["way"]
assert len(locs.found_locs["way"]) == 3
assert len(locs.found_locs) == 3

# coords are nested deeper for ways than nodes as you need to access
# way members' coordinates
for w in locs.found_locs["way"]:
for x in locs.found_locs["way"][w]:
for w in locs.found_locs:
for x in locs.found_locs[w]:
for k, v in x.items():
for coord in list(v.values()):
assert isinstance(
Expand Down Expand Up @@ -421,7 +419,8 @@ def test_find_tags_check_tags_for_ids(self, _tiny_osm_tags, _tiny_osm_ids):
area_ids = ids.id_dict["area_ids"][0:2]
# many node IDs are empty, so check a known ID for tags instead
tags.check_tags_for_ids(ids=node_ids, feature_type="node")
target_node = tags.found_tags["node"][7728862]
target_node = tags.found_tags[7728862]

tag_value_map = {
"highway": "traffic_signals",
}
Expand All @@ -431,10 +430,9 @@ def test_find_tags_check_tags_for_ids(self, _tiny_osm_tags, _tiny_osm_ids):

# check way tags
tags.check_tags_for_ids(ids=way_ids, feature_type="way")
# raise ValueError(way_ids)
target_way = tags.found_tags["way"][4811009]
# raise ValueError(target_way)
assert len(tags.found_tags["way"]) == 4
target_way = tags.found_tags[4811009]
assert len(tags.found_tags) == 4

tag_value_map = {
"highway": "primary",
"lanes": "2",
Expand All @@ -448,8 +446,7 @@ def test_find_tags_check_tags_for_ids(self, _tiny_osm_tags, _tiny_osm_ids):
assert f == v, f"Expected way tag value {v} but found {f}"
# check relation tags
tags.check_tags_for_ids(ids=rel_ids, feature_type="relation")
target_rel = tags.found_tags["relation"][rel_ids[0]]
# raise ValueError(target_rel)
target_rel = tags.found_tags[rel_ids[0]]
tag_value_map = {
"colour": "#5d2491",
"name": "Cardiff-Newport 30",
Expand All @@ -464,8 +461,7 @@ def test_find_tags_check_tags_for_ids(self, _tiny_osm_tags, _tiny_osm_ids):

# check area tags
tags.check_tags_for_ids(ids=area_ids, feature_type="area")
target_area = tags.found_tags["area"][area_ids[0]]
# raise ValueError(target_area)
target_area = tags.found_tags[area_ids[0]]
tag_value_map = {
"highway": "primary",
"junction": "roundabout",
Expand All @@ -477,4 +473,4 @@ def test_find_tags_check_tags_for_ids(self, _tiny_osm_tags, _tiny_osm_ids):
for k, v in tag_value_map.items():
f = target_area[k]
assert f == v, f"Expected area tag value {v} but found {f}"
assert len(tags.found_tags["area"]) == 2
assert len(tags.found_tags) == 2

0 comments on commit fade1ab

Please sign in to comment.