Skip to content

Commit

Permalink
Fix issues with archive_catalog marked keywords not being required (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson authored Jan 17, 2025
2 parents 009e17d + 2c32670 commit 7fcc80f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changes/505.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Require that ``archive_catalog`` and ``sdf`` marked keywords are in the ``required``
list for the object containing those keywords.
1 change: 1 addition & 0 deletions src/rad/resources/schemas/ref_file-1.0.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,6 @@ properties:
archive_catalog:
datatype: nvarchar(120)
destination: [ScienceRefData.r_refpix, GuideWindow.r_refpix, WFICommon.r_refpix]
required: [crds, dark, distortion, mask, flat, gain, readnoise, linearity, inverse_linearity, photom, area, saturation, refpix]
flowStyle: block
...
36 changes: 36 additions & 0 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
)
EXPOSURE_TYPE_ELEMENTS = list(asdf.schema.load_schema("asdf://stsci.edu/datamodels/roman/schemas/exposure_type-1.0.0")["enum"])
EXPECTED_COMMON_REFERENCE = {"$ref": "asdf://stsci.edu/datamodels/roman/schemas/reference_files/ref_common-1.0.0"}
METADATA_FORCING_REQUIRED = ["archive_catalog", "sdf"]


@pytest.fixture(scope="session", params=SCHEMA_URIS)
Expand Down Expand Up @@ -105,6 +106,10 @@ def callback(node):


def test_required(schema):
"""
Checks that all properties are required if there is a required list.
"""

def callback(node):
if isinstance(node, Mapping) and "required" in node:
assert node.get("type") == "object"
Expand All @@ -118,6 +123,37 @@ def callback(node):
asdf.treeutil.walk(schema, callback)


def test_metadata_force_required(schema):
"""
Test that if certain properties have certain metadata entries, that they are in a required list.
"""
xfail_uris = (
"asdf://stsci.edu/datamodels/roman/schemas/tvac/groundtest-1.0.0",
"asdf://stsci.edu/datamodels/roman/schemas/tvac/ref_file-1.0.0",
"asdf://stsci.edu/datamodels/roman/schemas/fps/ref_file-1.0.0",
)
if schema["id"] in xfail_uris:
pytest.xfail(
reason=f"{schema['id']} is not being altered to ensure required lists for archive metadata, due to it being in either tvac or fps."
)

def callback(node):
if isinstance(node, Mapping) and "properties" in node:
for prop_name, prop in node["properties"].items():
# Test that if a subnode has a required list, that the parent has a required list
if isinstance(prop, Mapping) and "required" in prop:
assert "required" in node
assert prop_name in node["required"]

# Test that if a subnode has certain metadata entries, that the parent has a required list
for metadata in METADATA_FORCING_REQUIRED:
if isinstance(prop, Mapping) and metadata in prop:
assert "required" in node, f"metadata {metadata} in {prop_name} requires required list"
assert prop_name in node["required"]

asdf.treeutil.walk(schema, callback)


def test_flowstyle(schema, manifest):
is_tag_schema = schema["id"] in {t["schema_uri"] for t in manifest["tags"]}

Expand Down

0 comments on commit 7fcc80f

Please sign in to comment.