From 5deff2d647aa36f0091700d4f3d2fc7f370fe4d1 Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Fri, 24 Nov 2023 12:07:33 -0500 Subject: [PATCH] Add tests to confirm that we can set the flags directly and validate without issues --- tests/test_dqflags.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/test_dqflags.py b/tests/test_dqflags.py index 21b1a4405..0b3665438 100644 --- a/tests/test_dqflags.py +++ b/tests/test_dqflags.py @@ -2,7 +2,9 @@ import pytest +from roman_datamodels import datamodels as rdm from roman_datamodels import dqflags +from roman_datamodels.maker_utils import mk_datamodel def _is_power_of_two(x): @@ -41,6 +43,23 @@ def test_pixel_flags(flag): assert _is_power_of_two(flag.value) +@pytest.mark.parametrize("flag", dqflags.pixel) +def test_write_pixel_flags(tmp_path, flag): + filename = tmp_path / "test_dq.asdf" + + ramp = mk_datamodel(rdm.RampModel, shape=(2, 8, 8)) + + # Set all pixels to the flag value + ramp.pixeldq[...] = flag + + # Check that we can write the model to disk (i.e. the flag validates) + ramp.save(filename) + + # Check that we can read the model back in and the flag is preserved + with rdm.open(filename) as dm: + assert (dm.pixeldq == flag).all() + + def test_group_uniqueness(): """ Test that there are no duplicate names in dqflags.group @@ -66,3 +85,20 @@ def test_group_flags(flag): # Test that each group flag matches a pixel flag of the same name assert dqflags.pixel[flag.name] == flag + + +@pytest.mark.parametrize("flag", dqflags.group) +def test_write_group_flags(tmp_path, flag): + filename = tmp_path / "test_dq.asdf" + + ramp = mk_datamodel(rdm.RampModel, shape=(2, 8, 8)) + + # Set all pixels to the flag value + ramp.groupdq[...] = flag + + # Check that we can write the model to disk (i.e. the flag validates) + ramp.save(filename) + + # Check that we can read the model back in and the flag is preserved + with rdm.open(filename) as dm: + assert (dm.groupdq == flag).all()