diff --git a/referencing/tests/test_core.py b/referencing/tests/test_core.py index 5704f62..428e461 100644 --- a/referencing/tests/test_core.py +++ b/referencing/tests/test_core.py @@ -673,56 +673,8 @@ def test_lookup_non_existent_anchor(self): anchor="noSuchAnchor", ) - # FIXME: Ideally there'd be some way to represent the tests below in the - # referencing suite, but I can't think of ways to do so yet. - - def test_multiple_lookup(self): - """ - Continuing to lookup resources maintains the new base URI. - """ - registry = Registry( - { - "http://example.com/": Resource.opaque({}), - "http://example.com/foo/": Resource.opaque({"foo": "bar"}), - "http://example.com/foo/bar": Resource.opaque({"baz": "quux"}), - }, - ) - - resolver = registry.resolver() - first = resolver.lookup("http://example.com/") - assert first.contents == {} - - second = first.resolver.lookup("foo/") - assert second.contents == {"foo": "bar"} - - third = second.resolver.lookup("bar") - assert third.contents == {"baz": "quux"} - - def test_multiple_lookup_pointer(self): - registry = Registry( - { - "http://example.com/": Resource.opaque({}), - "http://example.com/foo/": Resource.opaque({"foo": "bar"}), - }, - ) - - resolver = registry.resolver() - first = resolver.lookup("http://example.com/foo/") - assert first.contents == {"foo": "bar"} - - second = first.resolver.lookup("#/foo") - assert second.contents == "bar" - - def test_multiple_lookup_anchor(self): - root = ID_AND_CHILDREN.create_resource({"anchors": {"foo": 12}}) - registry = Registry().with_resource("http://example.com/", root) - - resolver = registry.resolver() - first = resolver.lookup("http://example.com/") - assert first.contents == {"anchors": {"foo": 12}} - - second = first.resolver.lookup("#foo") - assert second.contents == 12 + # FIXME: The tests below aren't really representable in the current + # suite, though we should probably think of ways to do so. def test_in_subresource(self): root = ID_AND_CHILDREN.create_resource( diff --git a/referencing/tests/test_referencing_suite.py b/referencing/tests/test_referencing_suite.py index ae70776..4603b09 100644 --- a/referencing/tests/test_referencing_suite.py +++ b/referencing/tests/test_referencing_suite.py @@ -35,7 +35,7 @@ def __str__(self): for each in SUITE.glob("*/**/*.json") ], ) -def test_referencing_suite(test_path): +def test_referencing_suite(test_path, subtests): dialect_id = DIALECT_IDS[test_path.relative_to(SUITE).parts[0]] specification = referencing.jsonschema.specification_with(dialect_id) loaded = json.loads(test_path.read_text()) @@ -45,10 +45,19 @@ def test_referencing_suite(test_path): for uri, contents in loaded["registry"].items() ) for test in loaded["tests"]: - resolver = registry.resolver(base_uri=test.get("base_uri", "")) - - if test.get("error"): - with pytest.raises(Unresolvable): - resolver.lookup(test["ref"]) - else: - assert resolver.lookup(test["ref"]).contents == test["target"] + with subtests.test(test=test): + resolver = registry.resolver(base_uri=test.get("base_uri", "")) + + if test.get("error"): + with pytest.raises(Unresolvable): + resolver.lookup(test["ref"]) + else: + resolved = resolver.lookup(test["ref"]) + assert resolved.contents == test["target"] + + then = test.get("then") + while then: + with subtests.test(test=test, then=then): + resolved = resolved.resolver.lookup(then["ref"]) + assert resolved.contents == then["target"] + then = then.get("then") diff --git a/suite b/suite index 32f62ab..75a7772 160000 --- a/suite +++ b/suite @@ -1 +1 @@ -Subproject commit 32f62ab50f9b1e992ae8d7fe3358f11c52d88bec +Subproject commit 75a777262f8741c9f62079f793b89f693bd50fb7 diff --git a/test-requirements.in b/test-requirements.in index 8b8da91..5ae98d8 100644 --- a/test-requirements.in +++ b/test-requirements.in @@ -1,2 +1,3 @@ file:.#egg=referencing pytest +pytest-subtests diff --git a/test-requirements.txt b/test-requirements.txt index eb65166..72b6c1c 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -7,6 +7,7 @@ attrs==22.2.0 # via # pytest + # pytest-subtests # referencing iniconfig==2.0.0 # via pytest @@ -17,6 +18,10 @@ pluggy==1.0.0 pyrsistent==0.19.3 # via referencing pytest==7.2.1 + # via + # -r test-requirements.in + # pytest-subtests +pytest-subtests==0.10.0 # via -r test-requirements.in file:.#egg=referencing # via -r test-requirements.in