Repository: spacetelescope/rad (language: python)

Issue:
Fix Inverse Linearity RefType Discontinuity 
_Issue [RAD-131](https://jira.stsci.edu/browse/RAD-131) was created on JIRA by [Paul Huwe](https://jira.stsci.edu/secure/ViewProfile.jspa?name=phuwe):_

Issue #&#x2060;292

RefType "inverselinearity" does not match tag "inverse-linearity" and needs to be tweaked. 


Discussion / hints:

Fix patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index fd8c746a..78741d15 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -8,6 +8,8 @@
 
 - Update the steps listed in ``cal_step`` with the ``resample`` step. [#295]
 
+- Fix the URIs for ``inverselinearity`` and add consistency checks for names/uris. [#296]
+
 0.16.0 (2023-06-26)
 -------------------
 
diff --git a/src/rad/resources/manifests/datamodels-1.0.yaml b/src/rad/resources/manifests/datamodels-1.0.yaml
index 0421e767..f694575c 100644
--- a/src/rad/resources/manifests/datamodels-1.0.yaml
+++ b/src/rad/resources/manifests/datamodels-1.0.yaml
@@ -146,8 +146,8 @@ tags:
   title: Gain reference schema
   description: |-
     Gain reference schema
-- tag_uri: asdf://stsci.edu/datamodels/roman/tags/reference_files/inverse_linearity-1.0.0
-  schema_uri: asdf://stsci.edu/datamodels/roman/schemas/reference_files/inverse_linearity-1.0.0
+- tag_uri: asdf://stsci.edu/datamodels/roman/tags/reference_files/inverselinearity-1.0.0
+  schema_uri: asdf://stsci.edu/datamodels/roman/schemas/reference_files/inverselinearity-1.0.0
   title: Inverse linearity correction reference schema
   description: |-
     Inverse linearity correction reference schema
diff --git a/src/rad/resources/schemas/reference_files/inverse_linearity-1.0.0.yaml b/src/rad/resources/schemas/reference_files/inverselinearity-1.0.0.yaml
similarity index 95%
rename from src/rad/resources/schemas/reference_files/inverse_linearity-1.0.0.yaml
rename to src/rad/resources/schemas/reference_files/inverselinearity-1.0.0.yaml
index 88bdf31e..da260dec 100644
--- a/src/rad/resources/schemas/reference_files/inverse_linearity-1.0.0.yaml
+++ b/src/rad/resources/schemas/reference_files/inverselinearity-1.0.0.yaml
@@ -1,11 +1,11 @@
 %YAML 1.1
 ---
 $schema: asdf://stsci.edu/datamodels/roman/schemas/rad_schema-1.0.0
-id: asdf://stsci.edu/datamodels/roman/schemas/reference_files/inverse_linearity-1.0.0
+id: asdf://stsci.edu/datamodels/roman/schemas/reference_files/inverselinearity-1.0.0
 
 title: Inverse linearity correction reference schema
 
-datamodel_name: InverseLinearityRefModel
+datamodel_name: InverselinearityRefModel
 
 type: object
 properties:


Test patch:
diff --git a/tests/test_integration.py b/tests/test_integration.py
index 7e137054..28a5f5ee 100644
--- a/tests/test_integration.py
+++ b/tests/test_integration.py
@@ -29,3 +29,13 @@ def test_schema_integration(schema_path):
     schema = yaml.safe_load(content)
     asdf_content = asdf.get_config().resource_manager[schema["id"]]
     assert asdf_content == content
+
+
+@pytest.mark.parametrize("schema_path", (importlib_resources.files(resources) / "schemas").glob("**/*.yaml"))
+def test_schema_filename(schema_path):
+    """
+    Check the filename pattern aligns with the schema ID.
+    """
+    schema = yaml.safe_load(schema_path.read_bytes())
+    id_suffix = str(schema_path.with_suffix("")).split(str(importlib_resources.files(resources)))[-1]
+    assert schema["id"].endswith(id_suffix)
diff --git a/tests/test_manifest.py b/tests/test_manifest.py
index db117ddc..aa7f93b5 100644
--- a/tests/test_manifest.py
+++ b/tests/test_manifest.py
@@ -3,6 +3,9 @@
 to schemas that exist.
 """
 import asdf
+import pytest
+
+from .conftest import MANIFEST
 
 
 def test_manifest_valid(manifest):
@@ -13,11 +16,18 @@ def test_manifest_valid(manifest):
     assert "title" in manifest
     assert "description" in manifest
 
-    for tag in manifest["tags"]:
-        # Check that the schema exists:
-        assert tag["schema_uri"] in asdf.get_config().resource_manager
-        # These are not required by the manifest schema but we're holding ourselves
-        # to a higher standard:
-        assert "title" in tag
-        assert "description" in tag
-        assert tag["tag_uri"].startswith("asdf://stsci.edu/datamodels/roman/tags/")
+
+@pytest.mark.parametrize("entry", MANIFEST["tags"])
+def test_manifest_entries(entry):
+    # Check that the schema exists:
+    assert entry["schema_uri"] in asdf.get_config().resource_manager
+    # These are not required by the manifest schema but we're holding ourselves
+    # to a higher standard:
+    assert "title" in entry
+    assert "description" in entry
+
+    # Check the URIs
+    assert entry["tag_uri"].startswith("asdf://stsci.edu/datamodels/roman/tags/")
+    uri_suffix = entry["tag_uri"].split("asdf://stsci.edu/datamodels/roman/tags/")[-1]
+    assert entry["schema_uri"].endswith(uri_suffix)
+    assert entry["schema_uri"].startswith("asdf://stsci.edu/datamodels/roman/schemas/")
diff --git a/tests/test_schemas.py b/tests/test_schemas.py
index d0a22e87..dcacd034 100644
--- a/tests/test_schemas.py
+++ b/tests/test_schemas.py
@@ -36,6 +36,11 @@ def ref_file_schema(request):
     return yaml.safe_load(asdf.get_config().resource_manager[request.param])
 
 
+@pytest.fixture(scope="session", params=[entry for entry in MANIFEST["tags"] if "/reference_files/" in entry["schema_uri"]])
+def ref_file_uris(request):
+    return request.param["tag_uri"], request.param["schema_uri"]
+
+
 @pytest.fixture(scope="session")
 def valid_tag_uris(manifest):
     uris = {t["tag_uri"] for t in manifest["tags"]}
@@ -139,6 +144,23 @@ def callback(node):
     asdf.treeutil.walk(schema, callback)
 
 
+def _model_name_from_schema_uri(schema_uri):
+    schema_name = schema_uri.split("/")[-1].split("-")[0]
+    class_name = "".join([p.capitalize() for p in schema_name.split("_")])
+    if schema_uri.startswith("asdf://stsci.edu/datamodels/roman/schemas/reference_files/"):
+        class_name += "Ref"
+
+    if class_name.startswith("Wfi") and "Ref" not in class_name:
+        class_name = class_name.split("Wfi")[-1]
+
+    return f"{class_name}Model"
+
+
+def test_datamodel_name(schema):
+    if "datamodel_name" in schema:
+        assert _model_name_from_schema_uri(schema["id"]) == schema["datamodel_name"]
+
+
 # Confirm that the optical_element filter in wfi_img_photom.yml matches WFI_OPTICAL_ELEMENTS
 def test_matched_optical_element_entries():
     phot_table_keys = list(
@@ -178,3 +200,17 @@ def test_reftype(ref_file_schema):
     """
     reftype = _get_reftype(ref_file_schema)
     assert is_crds_name(f"roman_wfi_{reftype.lower()}_0000.asdf")
+
+
+def test_reftype_tag(ref_file_uris):
+    """
+    Check that the URIs match the reftype for a valid CRDS check
+    """
+    tag_uri = ref_file_uris[0]
+    schema_uri = ref_file_uris[1]
+
+    schema = yaml.safe_load(asdf.get_config().resource_manager[schema_uri])
+    reftype = _get_reftype(schema).lower()
+
+    assert asdf.util.uri_match(f"asdf://stsci.edu/datamodels/roman/tags/reference_files/*{reftype}-*", tag_uri)
+    assert asdf.util.uri_match(f"asdf://stsci.edu/datamodels/roman/schemas/reference_files/*{reftype}-*", schema_uri)