Skip to content

Commit

Permalink
Add __repr__ for DNode objects. (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson authored Jul 20, 2023
1 parent 7b5f02f commit 3a508ff
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

- Include tests in coverage and turn testing warnings into errors. [#238]

- Add ``__repr__`` to ``DNode``. [#245]

0.16.1 (2023-06-27)
===================

Expand Down
3 changes: 3 additions & 0 deletions src/roman_datamodels/stnode/_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ def __delitem__(self, key):
def __iter__(self):
return iter(self._data)

def __repr__(self):
return repr(self._data)

def copy(self):
instance = self.__class__.__new__(self.__class__)
instance.__dict__.update(self.__dict__.copy())
Expand Down
21 changes: 21 additions & 0 deletions tests/test_stnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,24 @@ def test_will_strict_validate(env_strict_var):
del os.environ[validate.ROMAN_STRICT_VALIDATION]
assert os.getenv(validate.ROMAN_STRICT_VALIDATION) is None
assert validate.will_strict_validate() is True


@pytest.mark.parametrize("model", [mdl for mdl in datamodels.MODEL_REGISTRY.values() if "Ref" not in mdl.__name__])
def test_node_representation(model):
"""
Regression test for #244.
The DNode object was lacking the __repr__ method, which is used to return
the representation of the object. The reported issue was with ``mdl.meta.instrument``,
so that is directly checked here.
"""
mdl = maker_utils.mk_datamodel(model)

if hasattr(mdl, "meta"):
assert repr(mdl.meta.instrument) == repr(
{
"name": "WFI",
"detector": "WFI01",
"optical_element": "F158",
}
)

0 comments on commit 3a508ff

Please sign in to comment.