From 818ef6f705d63c4c201d190ff6d7a83c499eddb4 Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Mon, 11 Nov 2024 15:25:35 -0500 Subject: [PATCH 1/3] Add test to force a required block whenever there is a property with certain metadata attributes that it is forced to be required Add test to force required blocks for certain types of metadata --- tests/test_schemas.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/test_schemas.py b/tests/test_schemas.py index ff7e0f6c..5800d363 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -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) @@ -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" @@ -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"]} From eefd04624374d3e9a8572a3d2756611b62da06f4 Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Fri, 17 Jan 2025 09:45:41 -0500 Subject: [PATCH 2/3] Fix schemas that violate the new test --- src/rad/resources/schemas/ref_file-1.0.0.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rad/resources/schemas/ref_file-1.0.0.yaml b/src/rad/resources/schemas/ref_file-1.0.0.yaml index f5adb2bb..a7b84a16 100644 --- a/src/rad/resources/schemas/ref_file-1.0.0.yaml +++ b/src/rad/resources/schemas/ref_file-1.0.0.yaml @@ -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 ... From 2c32670a24917eea2af4c01dd1ba73d2db5909ff Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Mon, 11 Nov 2024 15:56:08 -0500 Subject: [PATCH 3/3] Update changes --- changes/505.feature.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changes/505.feature.rst diff --git a/changes/505.feature.rst b/changes/505.feature.rst new file mode 100644 index 00000000..16909493 --- /dev/null +++ b/changes/505.feature.rst @@ -0,0 +1,2 @@ +Require that ``archive_catalog`` and ``sdf`` marked keywords are in the ``required`` +list for the object containing those keywords.