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 issues with archive_catalog marked keywords not being required #505

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
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
Loading