Repository: spacetelescope/rad (language: python)

Issue:
Invalid `reftype` in inverse_linearity
CRDS does not allow underscores in the `reftype`, this issue was not caught for inverse linearity:
https://github.com/spacetelescope/rad/blob/6f60c2cec3c68b6e0e722c5b96b72667cebc73e5/src/rad/resources/schemas/reference_files/inverse_linearity-1.0.0.yaml#L17

We will have to decide on a different and valid `reftype` for this case.


Discussion / hints:
I think that to be consistent with all the other `reftype` values we should probably use:
```
INVERSELINEARITY
```
or apparently:
```
INVERSE-LINEARITY
```
may also work.

Other (better) suggestions are welcome.

The reported issue is demonstrated by:
```python
In [1]: import crds

In [2]: from crds.config import is_crds_name

In [3]: is_crds_name("roman_wfi_inverse_linearity_0005.asdf")
Out[3]: False

In [4]: is_crds_name("roman_wfi_inverselinearity_0005.asdf")
Out[4]: True

In [5]: is_crds_name("roman_wfi_inverse-linearity_0005.asdf")
Out[5]: True
```

So this may not actually be a schema issue.

Fix patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index d539f11d..9ecdae60 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -3,6 +3,10 @@
 
 - Fix minor discrepancies found when looking over the schemas. [#267]
 
+
+- Bugfix for ``inverse_linearity-1.0.0``'s ``reftype`` so that it is CRDS
+  compatible. [#272]
+
 0.15.0 (2023-05-12)
 -------------------
 
diff --git a/pyproject.toml b/pyproject.toml
index 18d7cea6..42ca8608 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -21,6 +21,7 @@ dynamic = ['version']
 test = [
     'pytest>=4.6.0',
     'pytest-doctestplus>=0.11.1',
+    'crds>=11.16.16',
 ]
 docs = [
     'sphinx',
diff --git a/src/rad/resources/schemas/reference_files/inverse_linearity-1.0.0.yaml b/src/rad/resources/schemas/reference_files/inverse_linearity-1.0.0.yaml
index a155fb5e..1c638e4b 100644
--- a/src/rad/resources/schemas/reference_files/inverse_linearity-1.0.0.yaml
+++ b/src/rad/resources/schemas/reference_files/inverse_linearity-1.0.0.yaml
@@ -14,7 +14,7 @@ properties:
         properties:
           reftype:
             type: string
-            enum: [INVERSE_LINEARITY]
+            enum: [INVERSELINEARITY]
           input_units:
             title: Units of the input to the inverse linearity polynomial.
             tag: tag:astropy.org:astropy/units/unit-1.0.0


Test patch:
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/tests/conftest.py b/tests/conftest.py
index 8ebcbe46..16a3dda1 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -2,7 +2,9 @@
 import pytest
 import yaml
 
+MANIFEST = yaml.safe_load(asdf.get_config().resource_manager["asdf://stsci.edu/datamodels/roman/manifests/datamodels-1.0"])
+
 
 @pytest.fixture(scope="session")
 def manifest():
-    return yaml.safe_load(asdf.get_config().resource_manager["asdf://stsci.edu/datamodels/roman/manifests/datamodels-1.0"])
+    return MANIFEST
diff --git a/tests/test_schemas.py b/tests/test_schemas.py
index d9bf59bb..d0a22e87 100644
--- a/tests/test_schemas.py
+++ b/tests/test_schemas.py
@@ -7,10 +7,14 @@
 import asdf
 import pytest
 import yaml
+from crds.config import is_crds_name
+
+from .conftest import MANIFEST
 
 SCHEMA_URI_PREFIX = "asdf://stsci.edu/datamodels/roman/schemas/"
 METASCHEMA_URI = "asdf://stsci.edu/datamodels/roman/schemas/rad_schema-1.0.0"
 SCHEMA_URIS = [u for u in asdf.get_config().resource_manager if u.startswith(SCHEMA_URI_PREFIX) and u != METASCHEMA_URI]
+REF_FILE_SCHEMA_URIS = [u["schema_uri"] for u in MANIFEST["tags"] if "/reference_files/" in u["schema_uri"]]
 WFI_OPTICAL_ELEMENTS = list(
     asdf.schema.load_schema("asdf://stsci.edu/datamodels/roman/schemas/wfi_optical_element-1.0.0")["enum"]
 )
@@ -27,6 +31,11 @@ def schema(request):
     return yaml.safe_load(asdf.get_config().resource_manager[request.param])
 
 
+@pytest.fixture(scope="session", params=REF_FILE_SCHEMA_URIS)
+def ref_file_schema(request):
+    return yaml.safe_load(asdf.get_config().resource_manager[request.param])
+
+
 @pytest.fixture(scope="session")
 def valid_tag_uris(manifest):
     uris = {t["tag_uri"] for t in manifest["tags"]}
@@ -150,3 +159,22 @@ def test_matched_p_exptype_entries():
     r = re.compile(p_exptype)
     for element_str in EXPOSURE_TYPE_ELEMENTS:
         assert r.search(element_str + "|")
+
+
+def _get_reftype(schema):
+    """
+    Extract the reftype from the schema
+    """
+    all_of = schema["properties"]["meta"]["allOf"]
+
+    for sub_schema in all_of:
+        if "properties" in sub_schema:
+            return sub_schema["properties"]["reftype"]["enum"][0]
+
+
+def test_reftype(ref_file_schema):
+    """
+    Check that the reftype is valid for CRDS
+    """
+    reftype = _get_reftype(ref_file_schema)
+    assert is_crds_name(f"roman_wfi_{reftype.lower()}_0000.asdf")