Skip to content

Commit

Permalink
refactor: More succinct utility provided by SRR
Browse files Browse the repository at this point in the history
  • Loading branch information
r-leyshon committed Nov 9, 2023
1 parent 2ddfa8e commit 0a0a975
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 51 deletions.
15 changes: 2 additions & 13 deletions src/transport_performance/osm/validate_osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,7 @@ def _compile_tags(osmium_feature):
A dictionary of tag name & values.
"""
tagdict = dict()
for tag in osmium_feature.tags:
for i, tag in enumerate(tag):
if i % 2 == 0:
# even tags are keys
k = tag
v = "_placeholder"
else:
# odd tags are values
v = tag
if v != "_placeholder":
tagdict[k] = v
return tagdict
return {tag.k: tag.v for tag in osmium_feature.tags}


def _filter_target_dict_with_list(
Expand Down Expand Up @@ -298,6 +286,7 @@ def relation(self, r: osmium.Relation) -> None:
"""
# get tags for each relation
print(type(r))
tagdict = _compile_tags(r)
self.relation_tags[r.id] = tagdict

Expand Down
38 changes: 0 additions & 38 deletions tests/osm/test_validate_osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from folium import Map

from transport_performance.osm.validate_osm import (
_compile_tags,
_filter_target_dict_with_list,
FindIds,
FindLocations,
Expand Down Expand Up @@ -41,43 +40,6 @@ def _tiny_osm_tags():
return tags


class Test_CompileTags(object):
"""Tests for _compile_tags internal."""

def test__compile_tags_returns_as_expected(self):
"""Test compile_tags returns correct dictionary."""

class _mock_osm_tags:
"""Fixture classes are not currently supported.
This class presents the tags in the same format as osmium.
"""

def __init__(self) -> None:
self.tags = [
["1", "foo", "2", "bar", "3", "baz", "4", "foobar"],
["a", "fizz", "b", "buzz", "c", "fizzbuzz"],
]

osm = _mock_osm_tags()
out = _compile_tags(osm)
assert isinstance(out, dict)
assert len(out) == 7
assert out["1"] == "foo"
assert out["c"] == "fizzbuzz"
type(out.keys())
assert list(out.keys()) == ["1", "2", "3", "4", "a", "b", "c"]
assert list(out.values()) == [
"foo",
"bar",
"baz",
"foobar",
"fizz",
"buzz",
"fizzbuzz",
]


class Test_FilterTargetDictWithList(object):
"""Tests for _filter_target_dict_with_list internal."""

Expand Down

0 comments on commit 0a0a975

Please sign in to comment.