def _assert_schema_correct(path): __tracebackhide__ = True assert VALID_SCHEMA_FILENAME_RE.match( path.name ) is not None, f"{path.name} is an invalid schema filename" assert_yaml_header_and_footer(path) schema = load_yaml(path) assert "$schema" in schema, f"{path.name} is missing $schema key" assert schema[ "$schema"] == METASCHEMA_ID, f"{path.name} has wrong $schema value (expected {METASCHEMA_ID})" expected_id = path_to_id(path) expected_tag = path_to_tag(path) assert "id" in schema, f"{path.name} is missing id key (expected {expected_id})" assert schema[ "id"] == expected_id, f"{path.name} id doesn't match filename (expected {expected_id})" if "tag" in schema: assert schema[ "tag"] == expected_tag, f"{path.name} tag doesn't match filename (expected {expected_tag})" assert "title" in schema, f"{path.name} is missing title key" assert len(schema["title"].strip() ) > 0, f"{path.name} title must have content" assert "description" in schema, f"{path.name} is missing description key" assert len(schema["description"].strip() ) > 0, f"{path.name} description must have content" assert len(id_to_schema[ schema["id"]]) == 1, f"{path.name} does not have a unique id" if "tag" in schema: assert len(tag_to_schema[ schema["tag"]]) == 1, f"{path.name} does not have a unique tag" id_base, _ = split_id(schema["id"]) for example_id in list_example_ids(schema): example_id_base, _ = split_id(example_id) if example_id_base == id_base and example_id != schema["id"]: assert False, f"{path.name} contains an example with an outdated tag" for description_id in list_description_ids(schema): if len(description_id.rsplit("-", 1)) > 1: description_id_base, _ = split_id(description_id) if description_id_base == id_base and description_id != schema[ "id"]: assert False, f"{path.name} descriptioon contains an outdated ref"
def _assert_latest_schema_correct(path): __tracebackhide__ = True schema = load_yaml(path) id_base, _ = split_id(schema["id"]) if id_base in DEPRECATED_ID_BASES: return refs = [ r.split("#")[0] for r in list_refs(schema) if not r.startswith("#") and not r == METASCHEMA_ID ] for ref in refs: ref_id = ref_to_id(schema["id"], ref) assert ref_id in latest_schema_ids, ( f"{path.name} is the latest version of a schema, " f"but references {ref}, which is not latest") for example_id in list_example_ids(schema): assert example_id in latest_schema_ids, ( f"{path.name} is the latest version of a schema, " f"but its examples include {example_id}, which is not latest") for description_id in list_description_ids(schema): if len(description_id.rsplit("-", 1)) > 1: assert description_id in latest_schema_ids, ( f"{path.name} is the latest version of a schema, " f"but its description includes a ref to {description_id}, " "which is not latest")
from common import ( VERSION_MAP_PATHS, load_yaml, assert_yaml_header_and_footer, VALID_FILE_FORMAT_VERSIONS, VALID_YAML_VERSIONS, split_id, DEPRECATED_TAG_BASES, path_to_id, ) VALID_FILENAME_RE = re.compile(r"version_map-[0-9]+\.[0-9]+\.[0-9]+\.yaml") SORTED_PATHS = sorted(VERSION_MAP_PATHS, key=lambda p: StrictVersion(split_id(path_to_id(p))[1])) LATEST_PATH = SORTED_PATHS[-1] @pytest.mark.parametrize("path", VERSION_MAP_PATHS) def test_version_map(path, schema_tags): assert VALID_FILENAME_RE.match( path.name ) is not None, f"{path.name} is an invalid version map filename" assert_yaml_header_and_footer(path) vm = load_yaml(path) assert set(vm.keys()) == {"FILE_FORMAT", "YAML_VERSION", "tags"}