diff --git a/.gitignore b/.gitignore index f87181d..b6b156e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ __pycache__ dist *.egg-info sstcore*.tar.gz +.venv/ diff --git a/src/ahp_graph/Device.py b/src/ahp_graph/Device.py index 8394a52..0dba4c9 100644 --- a/src/ahp_graph/Device.py +++ b/src/ahp_graph/Device.py @@ -278,7 +278,7 @@ def port(self, port: str, number: int = None) -> 'DevicePort': def get_category(self) -> str: """Return the category for this Device (type, model).""" - if self.model is not None: + if self.model is not None and self.model.strip(): return f"{self.type}_{self.model}" return self.type diff --git a/tests/Devices.py b/tests/Devices.py index 15440b5..a7a6b97 100644 --- a/tests/Devices.py +++ b/tests/Devices.py @@ -1,5 +1,7 @@ """Collection of ahp_graph Devices for testing.""" +from typing import Any + from ahp_graph.Device import * from ahp_graph.DeviceGraph import * @@ -104,3 +106,8 @@ class AttributeTestDevice(Device): def __init__(self, attr: dict[str, Any], name: str = '') -> None: """Test Device with attributes.""" super().__init__(f'{self.__class__.__name__}{name}', attr=attr) + + +class AssemblyTestDevice(Device): + def expand(self, grpah: DeviceGraph) -> None: + pass diff --git a/tests/test_Device.py b/tests/test_Device.py index 1df1999..c366d45 100644 --- a/tests/test_Device.py +++ b/tests/test_Device.py @@ -128,3 +128,18 @@ def test_submodule() -> None: assert pop[0] == ltd1, 'subs' assert pop[1] == 'slotName', 'slotName' assert pop[2] is None, 'slotIndex' + + +def test_empty_model() -> None: + """Test that empty model name is not included in category (and not suffixed with '_')""" + device = AssemblyTestDevice("Name", "model") + assert device.get_category() == "AssemblyTestDevice_model" + + device = AssemblyTestDevice("Name", " ") + assert device.get_category() == "AssemblyTestDevice" + + device = AssemblyTestDevice("Name", "") + assert device.get_category() == "AssemblyTestDevice" + + device = AssemblyTestDevice("Name") + assert device.get_category() == "AssemblyTestDevice"