Skip to content

Commit

Permalink
add check that all schemas have understood keywords (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
tapastro authored Sep 16, 2024
2 parents 738e14c + 8a63a5f commit ac1ebe1
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 17 deletions.
1 change: 1 addition & 0 deletions changes/327.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix invalid abvegaoffset and coords schemas.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jwst_pipeline = "stdatamodels.jwst.transforms.integration:get_resource_mappings"
[project.optional-dependencies]
test = [
"psutil",
"pyyaml",
"pytest>=4.6.0",
"pytest-doctestplus",
"crds>=11.17.1",
Expand Down
Empty file.
81 changes: 81 additions & 0 deletions src/stdatamodels/jwst/_tests/test_schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from pathlib import Path

import asdf
import pytest
import yaml

from stdatamodels.fits_support import _get_validators
from stdatamodels.schema import walk_schema


# relative paths to schema directories
SCHEMA_RELATIVE_PATHS = [
"../datamodels/schemas",
"../transforms/resources/schemas/stsci.edu/jwst_pipeline",
]


def _get_schema_ids():
root_path = Path(__file__).parent
schema_ids = []
for schema_relative_path in SCHEMA_RELATIVE_PATHS:
path = root_path / schema_relative_path
for schema_path in path.glob("*.yaml"):
with open(schema_path, "r") as f:
schema_ids.append(yaml.load(f, yaml.SafeLoader)["id"])
return schema_ids


SCHEMA_IDS = _get_schema_ids()


@pytest.fixture(scope="module")
def known_validators():
# what validators do we understand?
# since we aren't going to use these we can feed it
# anything in place of a valid hdulist
class Foo:
pass

validators = _get_validators(Foo())[0]
known_validators = set(validators.keys())
return known_validators


@pytest.fixture(scope="module")
def valid_keywords(known_validators):
return known_validators | {
"id",
"$schema",
"title",
"description",
"default",
"examples",
"blend_table",
"blend_rule",
"fits_hdu",
"definitions",
"allow_extra_columns",
}


def test_found_schemas():
"""
Make sure we found some schemas
"""
assert SCHEMA_IDS


@pytest.mark.parametrize("schema_id", SCHEMA_IDS)
def test_schema_contains_only_known_keywords(schema_id, valid_keywords):
# load the schema from asdf instead of the file to
# verify that asdf knows about the schema
schema = asdf.schema.load_schema(schema_id)


def callback(schema, path, combiner, ctx, recurse):
extra = schema.keys() - ctx["valid_keywords"]
assert not extra, f"{extra} found at {path} in {schema_id}"

ctx = {"valid_keywords": valid_keywords}
walk_schema(schema, callback, ctx)
14 changes: 0 additions & 14 deletions src/stdatamodels/jwst/datamodels/schemas/abvegaoffset.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,4 @@ allOf:
abvega_offset:
title: Offsets to convert AB to Vega magnitudes
type: object
properties:
abvega_offset:
title: AB_mag - Vega_mag
type: number
anyOf:
detector:
title: Detector name
type: string
filter:
title: Filter wheel element name
type: string
pupil:
title: Pupil wheel element name
type: string
...
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ examples:
allOf:
- $ref: "http://stsci.edu/schemas/asdf/transform/transform-1.1.0"
- object:
- type: object
properties:
model_type:
description: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ examples:
allOf:
- $ref: "http://stsci.edu/schemas/asdf/transform/transform-1.2.0"
- object:
- type: object
properties:
model_type:
description: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ examples:
allOf:
- $ref: "http://stsci.edu/schemas/asdf/transform/transform-1.3.0"
- object:
- type: object
properties:
model_type:
description: |
Expand Down

0 comments on commit ac1ebe1

Please sign in to comment.