Skip to content

Commit

Permalink
Some minor test mistakes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Feb 14, 2023
1 parent 0f07908 commit 09b273f
Showing 1 changed file with 38 additions and 34 deletions.
72 changes: 38 additions & 34 deletions referencing/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()) == []


Expand Down

0 comments on commit 09b273f

Please sign in to comment.