diff --git a/osm/osm_types.py b/osm/osm_types.py index a8ad076..399abba 100644 --- a/osm/osm_types.py +++ b/osm/osm_types.py @@ -9,7 +9,7 @@ class OSMWay: highway: str = field(init=False, default="") area: Optional[str] = field(init=False, default=None) max_speed_str: Optional[str] = field(init=False, default=None) - max_speed_int: int = field(init=False) + max_speed_int: int = field(init=False, default=0) direction: str = field(init=False, default="") forward: bool = field(init=False, default=True) backward: bool = field(init=False, default=True) diff --git a/tests/convert_graph_test.py b/tests/convert_graph_test.py index d12c88c..6ab204a 100644 --- a/tests/convert_graph_test.py +++ b/tests/convert_graph_test.py @@ -1,3 +1,4 @@ +import importlib.util import random import string import unittest @@ -6,6 +7,8 @@ from graph.graph import Graph from graph.graph_types import Edge, EdgeData, Vertex, VertexData +networkx_available = importlib.util.find_spec("networkx") is not None + def random_string(length=8): return "".join(random.choice(string.ascii_lowercase) for i in range(length)) @@ -15,6 +18,7 @@ def random_uint(max_val=1000): return random.randint(1, max_val) +@unittest.skipUnless(networkx_available, "networkx is an optional dependency and is not installed") class TestConvertGraphTest(unittest.TestCase): def test_converting_K4_graph(self): g = self.create_graph(number_nodes=4) diff --git a/tests/integration_test.py b/tests/integration_test.py index 36152e5..e06b559 100644 --- a/tests/integration_test.py +++ b/tests/integration_test.py @@ -1,6 +1,9 @@ +import importlib.util import unittest from subprocess import call +networkx_available = importlib.util.find_spec("networkx") is not None + class IntegrationTest(unittest.TestCase): def test_python(self): @@ -21,18 +24,12 @@ def pedestrian_graph_contracted_ok(self): self.assertEqual(nmb_edges, 2039) def _execute_program(self): - returncode = call( - [ - "python3", - "run.py", - "-f", - "data/karlsruhe_small.osm", - "-n", - "p", - "-c", - "--networkx", - ] - ) + args = ["python3", "run.py", "-f", "data/karlsruhe_small.osm", "-n", "p", "-c"] + # --networkx requires the optional networkx dependency; only exercise + # it when networkx is actually installed + if networkx_available: + args.append("--networkx") + returncode = call(args) self.assertEqual(0, returncode) def _get_nmb_nodes_edges(self, path):