Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 18, 2023
1 parent a227a31 commit 4ca4108
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
0.17.2 (unreleased)
===================
- Allow assignment to or creation of node attributes using dot notation of object instances
- Allow assignment to or creation of node attributes using dot notation of object instances
with validation. [#284]

- Allow DNode and LNode subclass instances to be assigned to tree attributes and support
Expand Down
5 changes: 3 additions & 2 deletions src/roman_datamodels/stnode/_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from astropy.time import Time

from roman_datamodels.validate import ValidationWarning, _check_type, _error_message, will_strict_validate, will_validate

from ._registry import SCALAR_NODE_CLASSES_BY_KEY

__all__ = ["DNode", "LNode"]
Expand Down Expand Up @@ -63,9 +64,9 @@ def _validate(attr, instance, schema, ctx):
# Note that the following checks cannot use isinstance since the TaggedObjectNode
# and TaggedListNode subclasses will break as a result. And currently there is no
# non-tagged subclasses of these classes that exist, nor are any envisioned yet.
if type(instance) == DNode: # noqa: E721
if type(instance) == DNode: # noqa: E721
instance = instance._data
elif type(instance) == LNode: # noqa: E721
elif type(instance) == LNode: # noqa: E721
instance = instance.data
tagged_tree = yamlutil.custom_tree_to_tagged_tree(instance, ctx)
return _value_change(attr, tagged_tree, schema, False, will_strict_validate(), ctx)
Expand Down
11 changes: 6 additions & 5 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,11 +641,12 @@ def test_node_assignment():
darkexp = darkmodel.meta.exposure
assert isinstance(darkexp, stnode.DNode)
darkexp.ngroups = darkexp.ngroups + 1
assert(darkexp.ngroups == 7)
assert darkexp.ngroups == 7
darkmodel.meta.exposure = darkexp


# Test that a currently undefined attribute can be assigned using dot notation
# so long as the attribute is defined in the coresponding schema.
# so long as the attribute is defined in the corresponding schema.
def test_node_new_attribute_assignment():
exp = stnode.Exposure()
with pytest.raises(AttributeError):
Expand All @@ -655,11 +656,11 @@ def test_node_new_attribute_assignment():
# Test patternProperties attribute case
photmod = utils.mk_wfi_img_photom()
phottab = photmod.phot_table
newphottab = {'F062': phottab['F062']}
newphottab = {"F062": phottab["F062"]}
photmod.phot_table = newphottab
photmod.phot_table.F213 = phottab['F213']
photmod.phot_table.F213 = phottab["F213"]
with pytest.raises(AttributeError):
photmod.phot_table.F214 = phottab['F213']
photmod.phot_table.F214 = phottab["F213"]
with pytest.raises(ValidationError):
photmod.phot_table.F106 = 0

Expand Down

0 comments on commit 4ca4108

Please sign in to comment.