Skip to content

Commit f840c52

Browse files
committed
Multiple lookup tests moved upstream, yay.
1 parent b4f015b commit f840c52

File tree

5 files changed

+26
-59
lines changed

5 files changed

+26
-59
lines changed

referencing/tests/test_core.py

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -673,56 +673,8 @@ def test_lookup_non_existent_anchor(self):
673673
anchor="noSuchAnchor",
674674
)
675675

676-
# FIXME: Ideally there'd be some way to represent the tests below in the
677-
# referencing suite, but I can't think of ways to do so yet.
678-
679-
def test_multiple_lookup(self):
680-
"""
681-
Continuing to lookup resources maintains the new base URI.
682-
"""
683-
registry = Registry(
684-
{
685-
"http://example.com/": Resource.opaque({}),
686-
"http://example.com/foo/": Resource.opaque({"foo": "bar"}),
687-
"http://example.com/foo/bar": Resource.opaque({"baz": "quux"}),
688-
},
689-
)
690-
691-
resolver = registry.resolver()
692-
first = resolver.lookup("http://example.com/")
693-
assert first.contents == {}
694-
695-
second = first.resolver.lookup("foo/")
696-
assert second.contents == {"foo": "bar"}
697-
698-
third = second.resolver.lookup("bar")
699-
assert third.contents == {"baz": "quux"}
700-
701-
def test_multiple_lookup_pointer(self):
702-
registry = Registry(
703-
{
704-
"http://example.com/": Resource.opaque({}),
705-
"http://example.com/foo/": Resource.opaque({"foo": "bar"}),
706-
},
707-
)
708-
709-
resolver = registry.resolver()
710-
first = resolver.lookup("http://example.com/foo/")
711-
assert first.contents == {"foo": "bar"}
712-
713-
second = first.resolver.lookup("#/foo")
714-
assert second.contents == "bar"
715-
716-
def test_multiple_lookup_anchor(self):
717-
root = ID_AND_CHILDREN.create_resource({"anchors": {"foo": 12}})
718-
registry = Registry().with_resource("http://example.com/", root)
719-
720-
resolver = registry.resolver()
721-
first = resolver.lookup("http://example.com/")
722-
assert first.contents == {"anchors": {"foo": 12}}
723-
724-
second = first.resolver.lookup("#foo")
725-
assert second.contents == 12
676+
# FIXME: The tests below aren't really representable in the current
677+
# suite, though we should probably think of ways to do so.
726678

727679
def test_in_subresource(self):
728680
root = ID_AND_CHILDREN.create_resource(

referencing/tests/test_referencing_suite.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __str__(self):
3535
for each in SUITE.glob("*/**/*.json")
3636
],
3737
)
38-
def test_referencing_suite(test_path):
38+
def test_referencing_suite(test_path, subtests):
3939
dialect_id = DIALECT_IDS[test_path.relative_to(SUITE).parts[0]]
4040
specification = referencing.jsonschema.specification_with(dialect_id)
4141
loaded = json.loads(test_path.read_text())
@@ -45,10 +45,19 @@ def test_referencing_suite(test_path):
4545
for uri, contents in loaded["registry"].items()
4646
)
4747
for test in loaded["tests"]:
48-
resolver = registry.resolver(base_uri=test.get("base_uri", ""))
49-
50-
if test.get("error"):
51-
with pytest.raises(Unresolvable):
52-
resolver.lookup(test["ref"])
53-
else:
54-
assert resolver.lookup(test["ref"]).contents == test["target"]
48+
with subtests.test(test=test):
49+
resolver = registry.resolver(base_uri=test.get("base_uri", ""))
50+
51+
if test.get("error"):
52+
with pytest.raises(Unresolvable):
53+
resolver.lookup(test["ref"])
54+
else:
55+
resolved = resolver.lookup(test["ref"])
56+
assert resolved.contents == test["target"]
57+
58+
then = test.get("then")
59+
while then:
60+
with subtests.test(test=test, then=then):
61+
resolved = resolved.resolver.lookup(then["ref"])
62+
assert resolved.contents == then["target"]
63+
then = then.get("then")

test-requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
file:.#egg=referencing
22
pytest
3+
pytest-subtests

test-requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
attrs==22.2.0
88
# via
99
# pytest
10+
# pytest-subtests
1011
# referencing
1112
iniconfig==2.0.0
1213
# via pytest
@@ -17,6 +18,10 @@ pluggy==1.0.0
1718
pyrsistent==0.19.3
1819
# via referencing
1920
pytest==7.2.1
21+
# via
22+
# -r test-requirements.in
23+
# pytest-subtests
24+
pytest-subtests==0.10.0
2025
# via -r test-requirements.in
2126
file:.#egg=referencing
2227
# via -r test-requirements.in

0 commit comments

Comments
 (0)