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
6 changes: 6 additions & 0 deletions brukerapi/jcampdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,12 @@ def __add__(self, other):
def __getitem__(self, key):
return self.params[key]

def __iter__(self):
return iter(self.params)

def __len__(self):
return len(self.params)

def __contains__(self, item):
return item in self.params

Expand Down
20 changes: 20 additions & 0 deletions test/test_jcampdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ def test_jcampdx(test_jcampdx_data):
assert value_ref == value_test


def test_jcampdx_iteration_and_length_follow_its_mapping_interface(tmp_path):
path = tmp_path / "visu_pars"
path.write_text(
"##TITLE=Parameter List\n"
"##JCAMPDX=4.24\n"
"##DATATYPE=Parameter Values\n"
"##$VisuCoreDim=2\n"
"##END=\n"
)
jcamp = JCAMPDX(path)

assert list(jcamp) == list(jcamp.keys())
assert len(jcamp) == len(jcamp.keys())
assert dict(jcamp) == {key: jcamp[key] for key in jcamp}

jcamp.unload()
assert list(jcamp) == []
assert len(jcamp) == 0


def test_a_string_is_read_without_its_delimiters():
"""Spec 2.2: `<...>` delimits a string, so the brackets are not its value.

Expand Down