Skip to content

Commit

Permalink
raise error for duplicated entries (#54)
Browse files Browse the repository at this point in the history
* raise and test error
* patch version bump
  • Loading branch information
JoschD committed Oct 13, 2022
1 parent 7ebe48b commit ebd9357
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sdds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
__title__ = "sdds"
__description__ = "SDDS file handling."
__url__ = "https://github.com/pylhc/sdds"
__version__ = "0.3.0"
__version__ = "0.3.1"
__author__ = "pylhc"
__author_email__ = "pylhc@github.com"
__license__ = "MIT"
Expand Down
5 changes: 5 additions & 0 deletions sdds/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ def __init__(self, version: str, description: Optional[Description],
definitions_list: List[Definition],
values_list: List[Any]) -> None:
self.version = version

name_list = [definition.name for definition in definitions_list]
if len(name_list) != len(set(name_list)):
raise ValueError("Duplicated name entries found")

self.description = description
self.definitions = {definition.name: definition for definition in definitions_list}
self.values = {definition.name: value for definition, value
Expand Down
10 changes: 10 additions & 0 deletions tests/test_sdds.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ def test_sdds_write_ascii(self):


class TestClasses:
def test_duplicated_entries(self):
with pytest.raises(ValueError) as e:
SddsFile(
version="SDDS1", description=None,
definitions_list=[Parameter(name="test", type_="int"),
Parameter(name="test", type_="str")],
values_list=[1, "hello"],
)
assert "Duplicated" in str(e)

def test_string_and_repr(self):
sdds = SddsFile(version="SDDS1", description=None, definitions_list=[], values_list=[])
assert "SDDS-File" in repr(sdds)
Expand Down

0 comments on commit ebd9357

Please sign in to comment.