Skip to content

Commit f478a6f

Browse files
Add test to force a required block whenever there is a property with certain metadata attributes that it is forced to be required
1 parent a82c274 commit f478a6f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/test_schemas.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
asdf.schema.load_schema("asdf://stsci.edu/datamodels/roman/schemas/wfi_optical_element-1.0.0")["enum"]
2121
)
2222
EXPOSURE_TYPE_ELEMENTS = list(asdf.schema.load_schema("asdf://stsci.edu/datamodels/roman/schemas/exposure_type-1.0.0")["enum"])
23+
METADATA_FORCING_REQUIRED = ["archive_catalog", "sdf"]
2324

2425

2526
@pytest.fixture(scope="session", params=SCHEMA_URIS)
@@ -103,6 +104,10 @@ def callback(node):
103104

104105

105106
def test_required(schema):
107+
"""
108+
Checks that all properties are required if there is a required list.
109+
"""
110+
106111
def callback(node):
107112
if isinstance(node, Mapping) and "required" in node:
108113
assert node.get("type") == "object"
@@ -116,6 +121,22 @@ def callback(node):
116121
asdf.treeutil.walk(schema, callback)
117122

118123

124+
def test_metadata_force_required(schema):
125+
"""
126+
Test that if certain properties have certain metadata entries, that they are in a required list.
127+
"""
128+
129+
def callback(node):
130+
if isinstance(node, Mapping) and "properties" in node:
131+
for prop_name, prop in node["properties"].items():
132+
for metadata in METADATA_FORCING_REQUIRED:
133+
if isinstance(prop, Mapping) and metadata in prop:
134+
assert "required" in node
135+
assert prop_name in node["required"]
136+
137+
asdf.treeutil.walk(schema, callback)
138+
139+
119140
def test_flowstyle(schema, manifest):
120141
is_tag_schema = schema["id"] in {t["schema_uri"] for t in manifest["tags"]}
121142

0 commit comments

Comments
 (0)