From e5eb795f606a1a851bdbb776873770f846b96c65 Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Sun, 25 Aug 2024 17:25:34 -0700 Subject: [PATCH 1/6] fix: generated schema id should not be same as tag id follows "${schema.tag}/schema" --- asdf_pydantic/schema.py | 2 +- tests/test_model.py | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/asdf_pydantic/schema.py b/asdf_pydantic/schema.py index c8ad21f..952a695 100644 --- a/asdf_pydantic/schema.py +++ b/asdf_pydantic/schema.py @@ -32,7 +32,7 @@ def generate(self, schema, mode="validation"): if self.tag_uri: json_schema["$schema"] = self.schema_dialect - json_schema["id"] = self.tag_uri + json_schema["id"] = f"{self.tag_uri}/schema" json_schema["tag"] = f"tag:{self.tag_uri.split('://', maxsplit=2)[-1]}" # TODO: Convert jsonschema 2020-12 to ASDF schema diff --git a/tests/test_model.py b/tests/test_model.py index 0566ab5..29bb5fe 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -1,13 +1,13 @@ import pytest +import yaml from asdf.extension import TagDefinition from asdf_pydantic import AsdfPydanticModel -def tag(request): - return request.param - - +######################################################################################## +# TAGS +######################################################################################## @pytest.mark.parametrize( "tag", ( @@ -49,3 +49,16 @@ class TestModel(AsdfPydanticModel): _tag = tag assert TestModel.get_tag_uri() + + +######################################################################################## +# SCHEMA +######################################################################################## +def test_generated_schema_id_uses_tag_in_pattern(): + class TestModel(AsdfPydanticModel): + _tag = "asdf://asdf-pydantic/tags/test-0.0.1" + + assert ( + yaml.safe_load(TestModel.model_asdf_schema())["id"] + == "asdf://asdf-pydantic/tags/test-0.0.1/schema" + ) From 21962f90395fde84bee43e31d0a69fe63e066313 Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Sun, 25 Aug 2024 18:33:11 -0700 Subject: [PATCH 2/6] fix: ordering of generated schema --- .pre-commit-config.yaml | 6 ++++++ asdf_pydantic/model.py | 2 +- asdf_pydantic/schema.py | 22 +++++++++++++++++++++- tests/test_model.py | 17 ++++++++++++++++- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 29196e9..2e401e3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,6 +21,12 @@ repos: hooks: - id: black + - repo: https://github.com/compilerla/conventional-pre-commit + rev: v3.4.0 + hooks: + - id: conventional-pre-commit + stages: [commit-msg] + ci: # autofix_commit_msg: | # [pre-commit.ci] auto fixes from pre-commit.com hooks diff --git a/asdf_pydantic/model.py b/asdf_pydantic/model.py index 09663a0..b7c3f42 100644 --- a/asdf_pydantic/model.py +++ b/asdf_pydantic/model.py @@ -72,7 +72,7 @@ def model_asdf_schema( ) json_schema = schema_generator_instance.generate(cls.__pydantic_core_schema__) - return f"%YAML 1.1\n---\n{yaml.safe_dump(json_schema)}" + return f"%YAML 1.1\n---\n{yaml.safe_dump(json_schema, sort_keys=False)}" @classmethod @deprecated( diff --git a/asdf_pydantic/schema.py b/asdf_pydantic/schema.py index 952a695..2adc6ab 100644 --- a/asdf_pydantic/schema.py +++ b/asdf_pydantic/schema.py @@ -3,6 +3,17 @@ from pydantic.json_schema import GenerateJsonSchema DEFAULT_ASDF_SCHEMA_REF_TEMPLATE = "#/definitions/{model}" +DESIRED_ASDF_SCHEMA_KEY_ORDER = ( + "$schema", + "id", + "title", + "type", + "properties", + "allOf", + "anyOf", + "required", + "$defs", +) class GenerateAsdfSchema(GenerateJsonSchema): @@ -33,7 +44,16 @@ def generate(self, schema, mode="validation"): if self.tag_uri: json_schema["$schema"] = self.schema_dialect json_schema["id"] = f"{self.tag_uri}/schema" - json_schema["tag"] = f"tag:{self.tag_uri.split('://', maxsplit=2)[-1]}" + + # Order keys + json_schema = { + **{ + key: json_schema[key] + for key in DESIRED_ASDF_SCHEMA_KEY_ORDER + if key in json_schema + }, + **json_schema, # Rest of the keys not in order list + } # TODO: Convert jsonschema 2020-12 to ASDF schema return json_schema diff --git a/tests/test_model.py b/tests/test_model.py index 29bb5fe..9f78227 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -52,8 +52,23 @@ class TestModel(AsdfPydanticModel): ######################################################################################## -# SCHEMA +# GENERATED SCHEMA ######################################################################################## +def test_generated_schema_keys_in_order(): + class TestModel(AsdfPydanticModel): + _tag = "asdf://asdf-pydantic/tags/test-0.0.1" + foo: str + + assert list(yaml.safe_load(TestModel.model_asdf_schema()).keys()) == [ + "$schema", + "id", + "title", + "type", + "properties", + "required", + ] + + def test_generated_schema_id_uses_tag_in_pattern(): class TestModel(AsdfPydanticModel): _tag = "asdf://asdf-pydantic/tags/test-0.0.1" From c72ab5f0e133b6cbe5b38ef5765e5772b101adae Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Sun, 25 Aug 2024 15:01:41 -0700 Subject: [PATCH 3/6] test: add test for example node --- .pre-commit-config.yaml | 1 + tests/examples/test_node.py | 117 ++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 tests/examples/test_node.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2e401e3..76fadfc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,6 @@ # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks +default_install_hook_types: [pre-commit, pre-push, commit-msg] repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 diff --git a/tests/examples/test_node.py b/tests/examples/test_node.py new file mode 100644 index 0000000..d863f80 --- /dev/null +++ b/tests/examples/test_node.py @@ -0,0 +1,117 @@ +"""Tests example asdf-pydantic model for nodes of a graph/tree.""" + +from __future__ import annotations + +import textwrap + +import asdf +import asdf.exceptions +import asdf.schema +import pytest +import yaml +from asdf.extension import Extension + +from asdf_pydantic import AsdfPydanticConverter, AsdfPydanticModel + + +class AsdfNode(AsdfPydanticModel): + """Model for a node in a graph/tree. + + Nodes introduce self-referential types. Notice the type of the `child` + attribute it the node type itself. The ASDF schema for this model will require + self-referencing syntax. We assumes this form is valid for ASDF schemas: + + ```yaml + --- + type: object + anyOf: + - $ref: "#/definitions/AsdfNode" + definitions: + AsdfNode: + type: object + properties: + name: + type: string + child: + anyOf: + - $ref: "#/definitions/AsdfNode" + - type: null + ``` + + The self-reference happens in ``definitions[AsdfNode].properties.child.anyOf[0]`` + where the `$ref` is a special JSONSchema syntax that referes to the value, + `#/definitions/AsdfNode`. This value is a json path where `#` denotes "this + schema". + """ + + _tag = "asdf://asdf-pydantic/examples/tags/node-1.0.0" + + name: str + child: AsdfNode | None = None + + +@pytest.fixture() +def asdf_extension(): + """Registers an ASDF extension containing models for this test.""" + AsdfPydanticConverter.add_models(AsdfNode) + + class TestExtension(Extension): + extension_uri = "asdf://asdf-pydantic/examples/extensions/test-1.0.0" + + converters = [AsdfPydanticConverter()] # type: ignore + tags = [AsdfNode.get_tag_definition()] # type: ignore + + with asdf.config_context() as asdf_config: + asdf_config.add_resource_mapping( + { + yaml.safe_load(AsdfNode.model_asdf_schema())[ + "id" + ]: AsdfNode.model_asdf_schema() + } + ) + asdf_config.add_extension(TestExtension()) + yield asdf_config + + +@pytest.mark.usefixtures("asdf_extension") +def test_can_write_valid_asdf_file(tmp_path): + """Tests using the model to write an ASDF file validates its own schema.""" + af = asdf.AsdfFile() + af["root"] = AsdfNode(name="foo", child=None) + af.validate() + af.write_to(tmp_path / "test.asdf") + + with asdf.open(tmp_path / "test.asdf") as af: + assert af.tree + + +@pytest.mark.usefixtures("asdf_extension") +def test_errors_reading_invalid_asdf_file(tmp_path): + """Tests validation fails when ASDF file does not match the schema.""" + content = """\ + #ASDF 1.0.0 + #ASDF_STANDARD 1.5.0 + %YAML 1.1 + %TAG ! tag:stsci.edu:asdf/ + --- !core/asdf-1.1.0 + asdf_library: !core/software-1.0.0 {author: The ASDF Developers, homepage: 'http://github.com/asdf-format/asdf', + name: asdf, version: 3.4.0} + history: + extensions: + - !core/extension_metadata-1.0.0 + extension_class: asdf.extension._manifest.ManifestExtension + extension_uri: asdf://asdf-format.org/core/extensions/core-1.5.0 + manifest_software: !core/software-1.0.0 {name: asdf_standard, version: 1.1.1} + software: !core/software-1.0.0 {name: asdf, version: 3.4.0} + - !core/extension_metadata-1.0.0 {extension_class: tests.examples.test_node.setup_module..TestExtension, + extension_uri: 'asdf://asdf-pydantic/examples/extensions/test-1.0.0'} + root: ! + child: None + ... + """ + with open(tmp_path / "test.asdf", "wb") as f: + f.write(textwrap.dedent(content).encode("utf-8")) + + with pytest.raises(asdf.exceptions.ValidationError): + with asdf.open(tmp_path / "test.asdf") as af: + assert af.tree From 588b35330cef8ef2447462382ff04d9b184d00a5 Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Sun, 25 Aug 2024 20:01:48 -0700 Subject: [PATCH 4/6] test: add tests for example rectangle --- tests/examples/test_node.py | 8 +- tests/examples/test_rectangle.py | 124 +++++++++++++++++++------------ 2 files changed, 83 insertions(+), 49 deletions(-) diff --git a/tests/examples/test_node.py b/tests/examples/test_node.py index d863f80..828f8d0 100644 --- a/tests/examples/test_node.py +++ b/tests/examples/test_node.py @@ -3,6 +3,7 @@ from __future__ import annotations import textwrap +from unittest.mock import MagicMock, patch import asdf import asdf.exceptions @@ -86,8 +87,9 @@ def test_can_write_valid_asdf_file(tmp_path): @pytest.mark.usefixtures("asdf_extension") +@patch.object(AsdfNode, "model_validate", MagicMock()) # Ignore pydantic validation def test_errors_reading_invalid_asdf_file(tmp_path): - """Tests validation fails when ASDF file does not match the schema.""" + """Tests ASDF validation fails when ASDF file does not match the schema.""" content = """\ #ASDF 1.0.0 #ASDF_STANDARD 1.5.0 @@ -109,8 +111,8 @@ def test_errors_reading_invalid_asdf_file(tmp_path): child: None ... """ - with open(tmp_path / "test.asdf", "wb") as f: - f.write(textwrap.dedent(content).encode("utf-8")) + with open(tmp_path / "test.asdf", "w") as f: + f.write(textwrap.dedent(content)) with pytest.raises(asdf.exceptions.ValidationError): with asdf.open(tmp_path / "test.asdf") as af: diff --git a/tests/examples/test_rectangle.py b/tests/examples/test_rectangle.py index bd24368..77adefc 100644 --- a/tests/examples/test_rectangle.py +++ b/tests/examples/test_rectangle.py @@ -1,58 +1,90 @@ +import textwrap +from unittest.mock import MagicMock, patch + import asdf import pytest +import yaml from asdf.extension import Extension -from asdf.schema import check_schema, load_schema -from yaml.scanner import ScannerError -from asdf_pydantic import AsdfPydanticConverter -from asdf_pydantic.examples.shapes import AsdfRectangle +from asdf_pydantic import AsdfPydanticConverter, AsdfPydanticModel + + +class AsdfRectangle(AsdfPydanticModel): + _tag = "asdf://asdf-pydantic/examples/tags/rectangle-1.0.0" + width: float + height: float -def setup_module(): +@pytest.fixture() +def asdf_extension(): + """Registers an ASDF extension containing models for this test.""" AsdfPydanticConverter.add_models(AsdfRectangle) class TestExtension(Extension): - extension_uri = "asdf://asdf-pydantic/examples/extensions/test-1.0.0" # type: ignore + extension_uri = "asdf://asdf-pydantic/examples/extensions/test-1.0.0" - tags = [*AsdfPydanticConverter().tags] # type: ignore converters = [AsdfPydanticConverter()] # type: ignore + tags = [AsdfRectangle.get_tag_definition()] # type: ignore + + with asdf.config_context() as asdf_config: + asdf_config.add_resource_mapping( + { + yaml.safe_load(AsdfRectangle.model_asdf_schema())[ + "id" + ]: AsdfRectangle.model_asdf_schema() + } + ) + asdf_config.add_extension(TestExtension()) + yield asdf_config + + +@pytest.mark.usefixtures("asdf_extension") +def test_can_write_valid_asdf_file(tmp_path): + """Tests using the model to write an ASDF file validates its own schema.""" + af = asdf.AsdfFile() + af["root"] = AsdfRectangle(width=42, height=10) + af.validate() + af.write_to(tmp_path / "test.asdf") + + with asdf.open(tmp_path / "test.asdf") as af: + assert af.tree + + +@pytest.mark.usefixtures("asdf_extension") +@patch.object( + AsdfRectangle, "model_validate", MagicMock() +) # Ignore pydantic validation +def test_errors_reading_invalid_asdf_file(tmp_path): + """Tests validation fails when ASDF file does not match the schema.""" + content = """\ + #ASDF 1.0.0 + #ASDF_STANDARD 1.5.0 + %YAML 1.1 + %TAG ! tag:stsci.edu:asdf/ + --- !core/asdf-1.1.0 + asdf_library: !core/software-1.0.0 { + author: The ASDF Developers, + homepage: 'http://github.com/asdf-format/asdf', + name: asdf, + version: 2.14.3} + history: + extensions: + - !core/extension_metadata-1.0.0 + extension_class: asdf.extension.BuiltinExtension + software: !core/software-1.0.0 { + name: asdf, + version: 2.14.3} + - !core/extension_metadata-1.0.0 { + extension_class: mypackage.shapes.ShapesExtension, + extension_uri: 'asdf://asdf-pydantic/shapes/extensions/shapes-1.0.0'} + rect: ! + height: "10" + width: "42" + ... + """ + with open(tmp_path / "test.asdf", "w") as f: + f.write(textwrap.dedent(content)) - # HACK: The schema URI should be referenced from `AsdfRectangle._schema`. - # Then there should be a way to automatically add the schema to ASDF - # resources perhaps during AsdfPydanticConverter.add_models(). Further - # abstracting can be done later, perhaps defining a - # AsdfPydanticExtension. - asdf.get_config().add_resource_mapping( - { - "asdf://asdf-pydantic/shapes/schemas/rectangle-1.0.0": ( - AsdfRectangle.model_asdf_schema().encode("utf-8") - ) - } - ) - asdf.get_config().add_extension(TestExtension()) - - -def test_schema(): - try: - schema = load_schema("asdf://asdf-pydantic/shapes/schemas/rectangle-1.0.0") - check_schema(schema) - except ScannerError as e: - pytest.fail(f"{e}\n{AsdfRectangle.model_asdf_schema()}") - - assert schema["$schema"] == "http://stsci.edu/schemas/asdf/asdf-schema-1.0.0" - assert schema["title"] == "AsdfRectangle" - assert schema["id"] == "asdf://asdf-pydantic/examples/tags/rectangle-1.0.0" - assert schema["tag"] == "tag:asdf-pydantic/examples/tags/rectangle-1.0.0" - assert schema["type"] == "object" - assert schema["properties"] == { - "width": { - "type": "number", - "title": "Width", - }, - "height": { - "type": "number", - "title": "Height", - }, - } - - assert schema["required"] == ["width", "height"] + with pytest.raises(asdf.exceptions.ValidationError): + with asdf.open(tmp_path / "test.asdf") as af: + assert af.tree From e797202504fec93056977384ead63bb687c79d07 Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Sun, 25 Aug 2024 21:02:47 -0700 Subject: [PATCH 5/6] test: delete tests/patterns/tree_node_test.py --- tests/patterns/tree_node_test.py | 39 -------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 tests/patterns/tree_node_test.py diff --git a/tests/patterns/tree_node_test.py b/tests/patterns/tree_node_test.py deleted file mode 100644 index 28c3054..0000000 --- a/tests/patterns/tree_node_test.py +++ /dev/null @@ -1,39 +0,0 @@ -from tempfile import NamedTemporaryFile - -import asdf - -from asdf_pydantic.examples.extensions import ExampleExtension -from asdf_pydantic.examples.tree import AsdfNode, Node - - -def setup_module(): - asdf.get_config().add_extension(ExampleExtension()) - - -def test_asdf_node_root_is_AsdfNode(): - node = AsdfNode() - af = asdf.AsdfFile({"node": node}) - with NamedTemporaryFile() as tempfile: - af.write_to(tempfile.name) - with asdf.open(tempfile.name) as ff: - assert isinstance(ff["node"], AsdfNode) - - -def test_asdf_node_child_is_AsdfNode(): - node = AsdfNode(child=AsdfNode()) - af = asdf.AsdfFile({"node": node}) - with NamedTemporaryFile() as tempfile: - af.write_to(tempfile.name) - - with asdf.open(tempfile.name) as ff: - assert isinstance(ff["node"].child, AsdfNode) - - -def test_regular_node_child_is_dict(): - node = AsdfNode(child=Node()) - af = asdf.AsdfFile({"node": node}) - with NamedTemporaryFile() as tempfile: - af.write_to(tempfile.name) - - with asdf.open(tempfile.name) as ff: - assert isinstance(ff["node"].child, Node) From 7e593509bafb43823fab02b55fb0e9fb15e707eb Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Sun, 25 Aug 2024 21:07:11 -0700 Subject: [PATCH 6/6] refactor: Rename example tree node to AsdfTreeNode as it conflicts with test --- asdf_pydantic/examples/extensions.py | 4 +-- asdf_pydantic/examples/tree.py | 6 ++-- tests/convert_to_asdf_yaml_tree_test.py | 14 +++++----- tests/examples/test_node.py | 37 +++++++++++++------------ tests/schema_validation_test.py | 6 ++-- 5 files changed, 34 insertions(+), 33 deletions(-) diff --git a/asdf_pydantic/examples/extensions.py b/asdf_pydantic/examples/extensions.py index aa2a8db..b79d4d9 100644 --- a/asdf_pydantic/examples/extensions.py +++ b/asdf_pydantic/examples/extensions.py @@ -4,9 +4,9 @@ from asdf_pydantic.converter import AsdfPydanticConverter from asdf_pydantic.examples.shapes import AsdfRectangle -from asdf_pydantic.examples.tree import AsdfNode +from asdf_pydantic.examples.tree import AsdfTreeNode -AsdfPydanticConverter.add_models(AsdfRectangle, AsdfNode) +AsdfPydanticConverter.add_models(AsdfRectangle, AsdfTreeNode) class ExampleExtension(Extension): diff --git a/asdf_pydantic/examples/tree.py b/asdf_pydantic/examples/tree.py index 9d86324..d695f86 100644 --- a/asdf_pydantic/examples/tree.py +++ b/asdf_pydantic/examples/tree.py @@ -11,7 +11,7 @@ class Node(BaseModel): child: Optional[Node] = None -class AsdfNode(Node, AsdfPydanticModel): - _tag = "asdf://asdf-pydantic/examples/tags/node-1.0.0" +class AsdfTreeNode(Node, AsdfPydanticModel): + _tag = "asdf://asdf-pydantic/examples/tags/tree-node-1.0.0" - child: Optional[Union[AsdfNode, Node]] = None + child: Optional[Union[AsdfTreeNode, Node]] = None diff --git a/tests/convert_to_asdf_yaml_tree_test.py b/tests/convert_to_asdf_yaml_tree_test.py index de25ada..37825e1 100644 --- a/tests/convert_to_asdf_yaml_tree_test.py +++ b/tests/convert_to_asdf_yaml_tree_test.py @@ -1,25 +1,25 @@ from __future__ import annotations -from asdf_pydantic.examples.tree import AsdfNode, Node +from asdf_pydantic.examples.tree import AsdfTreeNode, Node def test_sanity(): - AsdfNode().asdf_yaml_tree() == {"child": None} + AsdfTreeNode().asdf_yaml_tree() == {"child": None} def test_should_not_convert_given_child_is_AsdfNode(): - AsdfNode(child=AsdfNode()).asdf_yaml_tree() == {"child": AsdfNode()} + AsdfTreeNode(child=AsdfTreeNode()).asdf_yaml_tree() == {"child": AsdfTreeNode()} def test_should_convert_given_child_is_Node(): - AsdfNode(child=Node()).asdf_yaml_tree() == {"child": {"child": None}} + AsdfTreeNode(child=Node()).asdf_yaml_tree() == {"child": {"child": None}} def test_given_mix_child_is_mix_of_AsdfNode_and_Node(): - assert AsdfNode(child=AsdfNode(child=Node())).asdf_yaml_tree() == { - "child": AsdfNode(child=Node()) + assert AsdfTreeNode(child=AsdfTreeNode(child=Node())).asdf_yaml_tree() == { + "child": AsdfTreeNode(child=Node()) } - assert AsdfNode(child=Node(child=AsdfNode())).asdf_yaml_tree() == { + assert AsdfTreeNode(child=Node(child=AsdfTreeNode())).asdf_yaml_tree() == { "child": {"child": {"child": None}} } diff --git a/tests/examples/test_node.py b/tests/examples/test_node.py index 828f8d0..8959b4b 100644 --- a/tests/examples/test_node.py +++ b/tests/examples/test_node.py @@ -22,22 +22,22 @@ class AsdfNode(AsdfPydanticModel): attribute it the node type itself. The ASDF schema for this model will require self-referencing syntax. We assumes this form is valid for ASDF schemas: - ```yaml - --- - type: object - anyOf: - - $ref: "#/definitions/AsdfNode" - definitions: - AsdfNode: - type: object - properties: - name: - type: string - child: - anyOf: - - $ref: "#/definitions/AsdfNode" - - type: null - ``` + ```yaml + --- + type: object + anyOf: + - $ref: "#/definitions/AsdfNode" + definitions: + AsdfNode: + type: object + properties: + name: + type: string + child: + anyOf: + - $ref: "#/definitions/AsdfNode" + - type: null + ``` The self-reference happens in ``definitions[AsdfNode].properties.child.anyOf[0]`` where the `$ref` is a special JSONSchema syntax that referes to the value, @@ -45,7 +45,7 @@ class AsdfNode(AsdfPydanticModel): schema". """ - _tag = "asdf://asdf-pydantic/examples/tags/node-1.0.0" + _tag = "asdf://asdf-pydantic/examples/tags/node-2.0.0" name: str child: AsdfNode | None = None @@ -108,7 +108,8 @@ def test_errors_reading_invalid_asdf_file(tmp_path): - !core/extension_metadata-1.0.0 {extension_class: tests.examples.test_node.setup_module..TestExtension, extension_uri: 'asdf://asdf-pydantic/examples/extensions/test-1.0.0'} root: ! - child: None + name: foo + child: 1 ... """ with open(tmp_path / "test.asdf", "w") as f: diff --git a/tests/schema_validation_test.py b/tests/schema_validation_test.py index 85cc05e..a5365b5 100644 --- a/tests/schema_validation_test.py +++ b/tests/schema_validation_test.py @@ -8,7 +8,7 @@ from asdf_pydantic import AsdfPydanticConverter from asdf_pydantic.examples.shapes import AsdfRectangle -from asdf_pydantic.examples.tree import AsdfNode +from asdf_pydantic.examples.tree import AsdfTreeNode def setup_module(): @@ -130,9 +130,9 @@ def test_validate_fail_on_bad_yaml_file(): def test_given_child_field_contains_asdf_object_then_schema_has_child_tag(): from asdf.schema import check_schema - schema = yaml.safe_load(AsdfNode.model_asdf_schema()) # type: ignore + schema = yaml.safe_load(AsdfTreeNode.model_asdf_schema()) # type: ignore check_schema(schema) child_schema = schema["definitions"]["AsdfNode"]["properties"]["child"] - assert {"tag": AsdfNode._tag} in child_schema["anyOf"] + assert {"tag": AsdfTreeNode._tag} in child_schema["anyOf"]