Skip to content

Commit

Permalink
Add tests to confirm that we can set the flags
Browse files Browse the repository at this point in the history
directly and validate without issues
  • Loading branch information
WilliamJamieson committed Nov 24, 2023
1 parent e9cb25a commit 5deff2d
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/test_dqflags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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()

0 comments on commit 5deff2d

Please sign in to comment.