Skip to content

Commit

Permalink
Pass the last remaining 2019 recursive ref test.
Browse files Browse the repository at this point in the history
Something still seems slightly suspicious here, so it may pass all
the tests but still be wrong :/ -- but it seems at least more correct
that entering subresources (something done by implementations as they
'manually' process subschemas) should not affect dynamic_scope(), so
that piece seems correcter.

Whether we have precisely the right logic on when to append to the
dynamic scope... we shall see.

I think this may have a bit to do with picking a better value for
"unidentified" root schemas (those without $id) than we currently have
(where we use "").
  • Loading branch information
Julian committed Feb 14, 2023
1 parent beb23cf commit 0f07908
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions referencing/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def in_subresource(self, subresource: Resource[D]) -> Resolver[D]:
id = subresource.id()
if id is None:
return self
return self._evolve(base_uri=urljoin(self._base_uri, id))
return evolve(self, base_uri=urljoin(self._base_uri, id))

def dynamic_scope(self) -> Iterable[tuple[URI, Registry[D]]]:
"""
Expand All @@ -492,7 +492,7 @@ def _evolve(self, base_uri: str, **kwargs: Any):
Evolve, appending to the dynamic scope.
"""
previous = self._previous
if self._base_uri and base_uri != self._base_uri:
if self._base_uri and (not previous or base_uri != self._base_uri):
previous = previous.cons(self._base_uri)
return evolve(self, base_uri=base_uri, previous=previous, **kwargs)

Expand Down
22 changes: 16 additions & 6 deletions referencing/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def test_in_pointer_subresource(self):
assert third.contents == {"ID": "grandchild"}

def test_dynamic_scope(self):
root = ID_AND_CHILDREN.create_resource(
one = ID_AND_CHILDREN.create_resource(
{
"ID": "http://example.com/",
"children": [
Expand All @@ -750,19 +750,29 @@ def test_dynamic_scope(self):
],
},
)
registry = Registry().with_resource(root.id(), root)
two = ID_AND_CHILDREN.create_resource(
{
"ID": "http://example.com/two",
"children": [{"ID": "two-child/"}],
},
)
registry = Registry().with_resources(
[(one.id(), one), (two.id(), two)],
)

resolver = registry.resolver()
first = resolver.lookup("http://example.com/")
second = first.resolver.lookup("#/children/0")
third = second.resolver.lookup("grandchild")
fourth = third.resolver.lookup("http://example.com/two")
assert list(fourth.resolver.dynamic_scope()) == [
("http://example.com/child/grandchild", fourth.resolver._registry),
("http://example.com/child/", fourth.resolver._registry),
]
assert list(third.resolver.dynamic_scope()) == [
("http://example.com/child/", third.resolver._registry),
("http://example.com/", third.resolver._registry),
]
assert list(second.resolver.dynamic_scope()) == [
("http://example.com/", second.resolver._registry),
]
assert list(second.resolver.dynamic_scope()) == []
assert list(first.resolver.dynamic_scope()) == []


Expand Down

0 comments on commit 0f07908

Please sign in to comment.