-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe37dec
commit 8e4aa62
Showing
2 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from math import log10 | ||
|
||
import pytest | ||
|
||
from roman_datamodels import dqflags | ||
|
||
|
||
def _is_power_of_two(x): | ||
return (log10(x) / log10(2)) % 1 == 0 | ||
|
||
|
||
def test_pixel_uniqueness(): | ||
""" | ||
Test that there are no duplicate names in dqflags.pixel | ||
Note: The @unique decorator should ensure that no flag names have the | ||
same value as another in the enum raising an error at first import | ||
of this module. However, this test is just a sanity check on this. | ||
""" | ||
|
||
assert len(dqflags.pixel) == len(dqflags.pixel.__members__) | ||
|
||
|
||
@pytest.mark.parametrize("flag", dqflags.pixel) | ||
def test_pixel_flags(flag): | ||
"""Test that each pixel flag follows the defined rules""" | ||
# Test that the pixel flags are dqflags.pixel instances | ||
assert isinstance(flag, dqflags.pixel) | ||
|
||
# Test that the pixel flags are ints | ||
assert isinstance(flag, int) | ||
|
||
# Test that the pixel flags are dict accessible | ||
assert dqflags.pixel[flag.name] is flag | ||
|
||
# Test that the pixel flag is a power of 2 | ||
if flag.name == "GOOD": | ||
# GOOD is the only non-power-of-two flag (it is 0) | ||
assert flag.value == 0 | ||
else: | ||
assert _is_power_of_two(flag.value) | ||
|
||
|
||
def test_group_uniqueness(): | ||
""" | ||
Test that there are no duplicate names in dqflags.group | ||
Note: The @unique decorator should ensure that no flag names have the | ||
same value as another in the enum raising an error at first import | ||
of this module. However, this test is just a sanity check on this. | ||
""" | ||
assert len(dqflags.group) == len(dqflags.group.__members__) | ||
|
||
|
||
@pytest.mark.parametrize("flag", dqflags.group) | ||
def test_group_flags(flag): | ||
"""Test that each group flag follows the defined rules""" | ||
# Test that the group flags are dqflags.group instances | ||
assert isinstance(flag, dqflags.group) | ||
|
||
# Test that the group flags are ints | ||
assert isinstance(flag, int) | ||
|
||
# Test that the group flags are dict accessible | ||
assert dqflags.group[flag.name] is flag | ||
|
||
# Test that each group flag matches a pixel flag of the same name | ||
assert dqflags.pixel[flag.name] == flag |