diff --git a/asdf/_node_info.py b/asdf/_node_info.py index 490beff80..0d820213a 100644 --- a/asdf/_node_info.py +++ b/asdf/_node_info.py @@ -46,7 +46,7 @@ def _get_subschema_for_property(schema, key): # next handle schema combiners if "not" in schema: - # since we're only concerned here with if the schema applies + # Since we're only concerned here with if the schema applies # it doesn't matter if the schema is nested in a not subschema = _get_subschema_for_property(schema["not"], key) if subschema is not None: @@ -75,10 +75,8 @@ def _get_schema_key(schema, key): applicable = [] if key in schema: applicable.append(schema[key]) - if "not" in schema: - possible = _get_schema_key(schema["not"], key) - if possible is not None: - applicable.append(possible) + # Here we don't consider any subschema under "not" to avoid + # false positives for keys like "type" etc. for combiner in ("allOf", "oneOf", "anyOf"): for combined_schema in schema.get(combiner, []): possible = _get_schema_key(combined_schema, key) diff --git a/asdf/_tests/test_info.py b/asdf/_tests/test_info.py index 469bc1b45..b3df11c96 100644 --- a/asdf/_tests/test_info.py +++ b/asdf/_tests/test_info.py @@ -4,8 +4,10 @@ import tempfile import numpy as np +import pytest import asdf +from asdf.exceptions import AsdfInfoResolutionError from asdf.extension import ExtensionManager, ExtensionProxy, ManifestExtension from asdf.resource import DirectoryResourceMapping @@ -715,3 +717,33 @@ def __str__(self): assert "(NewlineStr)\n" in captured.out assert "(CarriageReturnStr)\n" in captured.out assert "(NiceStr): nice\n" in captured.out + + +@pytest.mark.parametrize( + "schema, expected", + [ + ({"title": "foo"}, "foo"), + ({"allOf": [{"title": "foo"}]}, "foo"), + ({"oneOf": [{"title": "foo"}]}, "foo"), + ({"anyOf": [{"title": "foo"}]}, "foo"), + ({"not": {"title": "foo"}}, None), + ], +) +def test_node_info(schema, expected): + ni = asdf._node_info.NodeSchemaInfo.from_root_node("title", "root", {}, schema) + assert ni.info == expected + + +@pytest.mark.parametrize( + "schema", + [ + {"allOf": [{"title": "foo"}, {"title": "bar"}]}, + {"oneOf": [{"title": "foo"}, {"title": "bar"}]}, + {"anyOf": [{"title": "foo"}, {"title": "bar"}]}, + {"allOf": [{"title": "foo"}, {"title": "bar"}]}, + ], +) +def test_node_info_failure(schema): + ni = asdf._node_info.NodeSchemaInfo.from_root_node("title", "root", {}, schema) + with pytest.raises(AsdfInfoResolutionError): + ni.info