Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ __pycache__
dist
*.egg-info
sstcore*.tar.gz
.venv/
2 changes: 1 addition & 1 deletion src/ahp_graph/Device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions tests/Devices.py
Original file line number Diff line number Diff line change
@@ -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 *

Expand Down Expand Up @@ -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
15 changes: 15 additions & 0 deletions tests/test_Device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading