Skip to content

Commit

Permalink
Multiple lookup tests moved upstream, yay.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Feb 20, 2023
1 parent b4f015b commit f840c52
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 59 deletions.
52 changes: 2 additions & 50 deletions referencing/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
25 changes: 17 additions & 8 deletions referencing/tests/test_referencing_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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")
1 change: 1 addition & 0 deletions test-requirements.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
file:.#egg=referencing
pytest
pytest-subtests
5 changes: 5 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
attrs==22.2.0
# via
# pytest
# pytest-subtests
# referencing
iniconfig==2.0.0
# via pytest
Expand All @@ -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

0 comments on commit f840c52

Please sign in to comment.