Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RCAL-695 generalize attribute assignment and creation #284

Merged
merged 6 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
relocated one test to test_stnode.py
  • Loading branch information
perrygreenfield authored and WilliamJamieson committed Nov 16, 2023
commit 830791a330b6fae75d3e36bb1360fa91a5ee6700
19 changes: 0 additions & 19 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,25 +644,6 @@ def test_node_assignment():
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.
def test_node_new_attribute_assignment():
exp = stnode.Exposure()
with pytest.raises(AttributeError):
exp.bozo = 0
exp.ngroups = 5
assert exp.ngroups == 5
# Test patternProperties attribute case
photmod = utils.mk_wfi_img_photom()
phottab = photmod.phot_table
newphottab = {'F062': phottab['F062']}
photmod.phot_table = newphottab
photmod.phot_table.F213 = phottab['F213']
with pytest.raises(AttributeError):
photmod.phot_table.F214 = phottab['F213']
with pytest.raises(ValidationError):
photmod.phot_table.F106 = 0


# WFI Level 3 Mosaic tests
def test_make_level3_mosaic():
Expand Down
22 changes: 22 additions & 0 deletions tests/test_stnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
from contextlib import nullcontext

import asdf
from asdf.exceptions import ValidationError
import astropy.units as u
import pytest

from roman_datamodels import maker_utils as utils
from roman_datamodels import datamodels, maker_utils, stnode, validate
from roman_datamodels.testing import assert_node_equal, assert_node_is_copy, wraps_hashable

Expand Down Expand Up @@ -181,6 +183,26 @@ def test_set_pattern_properties():
mdl.phot_table.F062.pixelareasr = None


# Test that a currently undefined attribute can be assigned using dot notation
# so long as the attribute is defined in the coresponding schema.
def test_node_new_attribute_assignment():
exp = stnode.Exposure()
with pytest.raises(AttributeError):
exp.bozo = 0
exp.ngroups = 5
assert exp.ngroups == 5
# Test patternProperties attribute case
photmod = utils.mk_wfi_img_photom()
phottab = photmod.phot_table
newphottab = {'F062': phottab['F062']}
photmod.phot_table = newphottab
photmod.phot_table.F213 = phottab['F213']
with pytest.raises(AttributeError):
photmod.phot_table.F214 = phottab['F213']
with pytest.raises(ValidationError):
photmod.phot_table.F106 = 0


VALIDATION_CASES = ("true", "yes", "1", "True", "Yes", "TrUe", "YeS", "foo", "Bar", "BaZ")


Expand Down