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

Fix strange ResourceWarning #231

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: 1 addition & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ testpaths = ['tests']
filterwarnings = [
# This error replaces pytest-openfiles
"error::ResourceWarning",
# Sometimes turning ResourceWarnings into errors creates an unraisable exception
# e.g. when pyest catches another exception, this will block the turning of
# ResourceWarnings into errors
# Disabled until issue #150 is resolved.
# "error::pytest.PytestUnraisableExceptionWarning",
"error::pytest.PytestUnraisableExceptionWarning",
]
env = [
"ROMAN_VALIDATE=true",
Expand Down
113 changes: 56 additions & 57 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,20 +438,22 @@ def test_make_readnoise():
def test_add_model_attribute(tmp_path):
# First make test reference file
file_path = tmp_path / "testreadnoise.asdf"
utils.mk_readnoise(filepath=file_path)
readnoise = datamodels.open(file_path)
readnoise["new_attribute"] = 77
assert readnoise.new_attribute == 77
with pytest.raises(ValueError):
readnoise["_underscore"] = "bad"
file_path2 = tmp_path / "testreadnoise2.asdf"
readnoise.save(file_path2)
readnoise2 = datamodels.open(file_path2)
assert readnoise2.new_attribute == 77
readnoise2.new_attribute = 88
assert readnoise2.new_attribute == 88
with pytest.raises(ValidationError):
readnoise["data"] = "bad_data_value"

utils.mk_readnoise(filepath=file_path)
with datamodels.open(file_path) as readnoise:
readnoise["new_attribute"] = 77
assert readnoise.new_attribute == 77
with pytest.raises(ValueError):
readnoise["_underscore"] = "bad"
readnoise.save(file_path2)

with datamodels.open(file_path2) as readnoise2:
assert readnoise2.new_attribute == 77
readnoise2.new_attribute = 88
assert readnoise2.new_attribute == 88
with pytest.raises(ValidationError):
readnoise["data"] = "bad_data_value"


# Saturation tests
Expand Down Expand Up @@ -584,64 +586,61 @@ def test_datamodel_info_search(capsys):
wfi_science_raw = utils.mk_level1_science_raw(shape=(2, 8, 8))
af = asdf.AsdfFile()
af.tree = {"roman": wfi_science_raw}
dm = datamodels.open(af)
dm.info(max_rows=200)
captured = capsys.readouterr()
assert "optical_element" in captured.out
result = dm.search("optical_element")
assert "F158" in repr(result)
assert result.node == "F158"
with datamodels.open(af) as dm:
dm.info(max_rows=200)
captured = capsys.readouterr()
assert "optical_element" in captured.out
result = dm.search("optical_element")
assert "F158" in repr(result)
assert result.node == "F158"


def test_datamodel_schema_info():
wfi_science_raw = utils.mk_level1_science_raw(shape=(2, 8, 8))
af = asdf.AsdfFile()
af.tree = {"roman": wfi_science_raw}
dm = datamodels.open(af)

info = dm.schema_info("archive_catalog")
assert info["roman"]["meta"]["aperture"] == {
"name": {
"archive_catalog": (
{
"datatype": "nvarchar(40)",
"destination": [
"ScienceCommon.aperture_name",
"GuideWindow.aperture_name",
],
},
dm.meta.aperture.name,
),
},
"position_angle": {
"archive_catalog": (
{
"datatype": "float",
"destination": [
"ScienceCommon.position_angle",
"GuideWindow.position_angle",
],
},
30.0,
)
},
}
with datamodels.open(af) as dm:
info = dm.schema_info("archive_catalog")
assert info["roman"]["meta"]["aperture"] == {
"name": {
"archive_catalog": (
{
"datatype": "nvarchar(40)",
"destination": [
"ScienceCommon.aperture_name",
"GuideWindow.aperture_name",
],
},
dm.meta.aperture.name,
),
},
"position_angle": {
"archive_catalog": (
{
"datatype": "float",
"destination": [
"ScienceCommon.position_angle",
"GuideWindow.position_angle",
],
},
30.0,
)
},
}


def test_crds_parameters(tmp_path):
# CRDS uses meta.exposure.start_time to compare to USEAFTER
file_path = tmp_path / "testwfi_image.asdf"
utils.mk_level2_image(filepath=file_path)
wfi_image = datamodels.open(file_path)

crds_pars = wfi_image.get_crds_parameters()
assert "roman.meta.exposure.start_time" in crds_pars
with datamodels.open(file_path) as wfi_image:
crds_pars = wfi_image.get_crds_parameters()
assert "roman.meta.exposure.start_time" in crds_pars

utils.mk_ramp(filepath=file_path)
ramp = datamodels.open(file_path)

crds_pars = ramp.get_crds_parameters()
assert "roman.meta.exposure.start_time" in crds_pars
with datamodels.open(file_path) as ramp:
crds_pars = ramp.get_crds_parameters()
assert "roman.meta.exposure.start_time" in crds_pars


def test_model_validate_without_save():
Expand Down
12 changes: 6 additions & 6 deletions tests/test_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ def test_opening_model(tmp_path, node_class):
file_path = tmp_path / "test.asdf"

utils.mk_node(node_class, filepath=file_path, shape=(2, 8, 8))
model = datamodels.open(file_path)
if node_class == stnode.Associations:
assert model.asn_type == "image"
else:
assert model.meta.instrument.optical_element == "F158"
assert isinstance(model, datamodels.MODEL_REGISTRY[node_class])
with datamodels.open(file_path) as model:
if node_class == stnode.Associations:
assert model.asn_type == "image"
else:
assert model.meta.instrument.optical_element == "F158"
assert isinstance(model, datamodels.MODEL_REGISTRY[node_class])


def test_read_pattern_properties():
Expand Down