@@ -380,6 +380,39 @@ def test_remove_nonexistent_uri(self):
380380 Registry ().remove ("urn:doesNotExist" )
381381 assert e .value == exceptions .NoSuchResource (ref = "urn:doesNotExist" )
382382
383+ def test_retrieve (self ):
384+ foo = Resource .opaque ({"foo" : "bar" })
385+ registry = Registry (retrieve = lambda uri : foo )
386+ assert registry ["urn:example" ] == foo
387+
388+ def test_retrieve_error (self ):
389+ def retrieve (uri ):
390+ if uri == "urn:succeed" :
391+ return {}
392+ raise Exception ("Oh no!" )
393+
394+ registry = Registry (retrieve = retrieve )
395+ assert registry ["urn:succeed" ] == {}
396+ with pytest .raises (exceptions .Unretrievable ):
397+ registry ["urn:uhoh" ]
398+
399+ def test_retrieve_already_available_resource (self ):
400+ def retrieve (uri ):
401+ raise Exception ("Oh no!" )
402+
403+ foo = Resource .opaque ({"foo" : "bar" })
404+ registry = Registry ({"urn:example" : foo })
405+ assert registry ["urn:example" ] == foo
406+
407+ def test_retrieve_crawlable_resource (self ):
408+ def retrieve (uri ):
409+ raise Exception ("Oh no!" )
410+
411+ child = ID_AND_CHILDREN .create_resource ({"ID" : "urn:child" , "foo" : 12 })
412+ root = ID_AND_CHILDREN .create_resource ({"children" : [child .contents ]})
413+ registry = Registry (retrieve = retrieve ).with_resource ("urn:root" , root )
414+ assert registry .crawl ()["urn:child" ] == child
415+
383416 def test_repr (self ):
384417 one = Resource .opaque (contents = {})
385418 two = ID_AND_CHILDREN .create_resource ({"foo" : "bar" })
@@ -519,39 +552,6 @@ def test_opaque(self):
519552 specification = Specification .OPAQUE ,
520553 )
521554
522- def test_retrieve (self ):
523- foo = Resource .opaque ({"foo" : "bar" })
524- registry = Registry (retrieve = lambda uri : foo )
525- assert registry ["urn:example" ] == foo
526-
527- def test_retrieve_error (self ):
528- def retrieve (uri ):
529- if uri == "urn:succeed" :
530- return {}
531- raise Exception ("Oh no!" )
532-
533- registry = Registry (retrieve = retrieve )
534- assert registry ["urn:succeed" ] == {}
535- with pytest .raises (exceptions .Unretrievable ):
536- registry ["urn:uhoh" ]
537-
538- def test_retrieve_already_available_resource (self ):
539- def retrieve (uri ):
540- raise Exception ("Oh no!" )
541-
542- foo = Resource .opaque ({"foo" : "bar" })
543- registry = Registry ({"urn:example" : foo })
544- assert registry ["urn:example" ] == foo
545-
546- def test_retrieve_crawlable_resource (self ):
547- def retrieve (uri ):
548- raise Exception ("Oh no!" )
549-
550- child = ID_AND_CHILDREN .create_resource ({"ID" : "urn:child" , "foo" : 12 })
551- root = ID_AND_CHILDREN .create_resource ({"children" : [child .contents ]})
552- registry = Registry (retrieve = retrieve ).with_resource ("urn:root" , root )
553- assert registry .crawl ()["urn:child" ] == child
554-
555555
556556class TestResolver :
557557 def test_lookup_exact_uri (self ):
@@ -768,11 +768,15 @@ def test_dynamic_scope(self):
768768 assert list (fourth .resolver .dynamic_scope ()) == [
769769 ("http://example.com/child/grandchild" , fourth .resolver ._registry ),
770770 ("http://example.com/child/" , fourth .resolver ._registry ),
771+ ("http://example.com/" , fourth .resolver ._registry ),
771772 ]
772773 assert list (third .resolver .dynamic_scope ()) == [
773774 ("http://example.com/child/" , third .resolver ._registry ),
775+ ("http://example.com/" , third .resolver ._registry ),
776+ ]
777+ assert list (second .resolver .dynamic_scope ()) == [
778+ ("http://example.com/" , second .resolver ._registry ),
774779 ]
775- assert list (second .resolver .dynamic_scope ()) == []
776780 assert list (first .resolver .dynamic_scope ()) == []
777781
778782
0 commit comments