diff --git a/referencing/tests/test_core.py b/referencing/tests/test_core.py index e1266c4..a2738dc 100644 --- a/referencing/tests/test_core.py +++ b/referencing/tests/test_core.py @@ -380,6 +380,39 @@ def test_remove_nonexistent_uri(self): Registry().remove("urn:doesNotExist") assert e.value == exceptions.NoSuchResource(ref="urn:doesNotExist") + def test_retrieve(self): + foo = Resource.opaque({"foo": "bar"}) + registry = Registry(retrieve=lambda uri: foo) + assert registry["urn:example"] == foo + + def test_retrieve_error(self): + def retrieve(uri): + if uri == "urn:succeed": + return {} + raise Exception("Oh no!") + + registry = Registry(retrieve=retrieve) + assert registry["urn:succeed"] == {} + with pytest.raises(exceptions.Unretrievable): + registry["urn:uhoh"] + + def test_retrieve_already_available_resource(self): + def retrieve(uri): + raise Exception("Oh no!") + + foo = Resource.opaque({"foo": "bar"}) + registry = Registry({"urn:example": foo}) + assert registry["urn:example"] == foo + + def test_retrieve_crawlable_resource(self): + def retrieve(uri): + raise Exception("Oh no!") + + child = ID_AND_CHILDREN.create_resource({"ID": "urn:child", "foo": 12}) + root = ID_AND_CHILDREN.create_resource({"children": [child.contents]}) + registry = Registry(retrieve=retrieve).with_resource("urn:root", root) + assert registry.crawl()["urn:child"] == child + def test_repr(self): one = Resource.opaque(contents={}) two = ID_AND_CHILDREN.create_resource({"foo": "bar"}) @@ -519,39 +552,6 @@ def test_opaque(self): specification=Specification.OPAQUE, ) - def test_retrieve(self): - foo = Resource.opaque({"foo": "bar"}) - registry = Registry(retrieve=lambda uri: foo) - assert registry["urn:example"] == foo - - def test_retrieve_error(self): - def retrieve(uri): - if uri == "urn:succeed": - return {} - raise Exception("Oh no!") - - registry = Registry(retrieve=retrieve) - assert registry["urn:succeed"] == {} - with pytest.raises(exceptions.Unretrievable): - registry["urn:uhoh"] - - def test_retrieve_already_available_resource(self): - def retrieve(uri): - raise Exception("Oh no!") - - foo = Resource.opaque({"foo": "bar"}) - registry = Registry({"urn:example": foo}) - assert registry["urn:example"] == foo - - def test_retrieve_crawlable_resource(self): - def retrieve(uri): - raise Exception("Oh no!") - - child = ID_AND_CHILDREN.create_resource({"ID": "urn:child", "foo": 12}) - root = ID_AND_CHILDREN.create_resource({"children": [child.contents]}) - registry = Registry(retrieve=retrieve).with_resource("urn:root", root) - assert registry.crawl()["urn:child"] == child - class TestResolver: def test_lookup_exact_uri(self): @@ -768,11 +768,15 @@ def test_dynamic_scope(self): assert list(fourth.resolver.dynamic_scope()) == [ ("http://example.com/child/grandchild", fourth.resolver._registry), ("http://example.com/child/", fourth.resolver._registry), + ("http://example.com/", 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()) == []