@@ -380,6 +380,39 @@ def test_remove_nonexistent_uri(self):
380
380
Registry ().remove ("urn:doesNotExist" )
381
381
assert e .value == exceptions .NoSuchResource (ref = "urn:doesNotExist" )
382
382
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
+
383
416
def test_repr (self ):
384
417
one = Resource .opaque (contents = {})
385
418
two = ID_AND_CHILDREN .create_resource ({"foo" : "bar" })
@@ -519,39 +552,6 @@ def test_opaque(self):
519
552
specification = Specification .OPAQUE ,
520
553
)
521
554
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
-
555
555
556
556
class TestResolver :
557
557
def test_lookup_exact_uri (self ):
@@ -768,11 +768,15 @@ def test_dynamic_scope(self):
768
768
assert list (fourth .resolver .dynamic_scope ()) == [
769
769
("http://example.com/child/grandchild" , fourth .resolver ._registry ),
770
770
("http://example.com/child/" , fourth .resolver ._registry ),
771
+ ("http://example.com/" , fourth .resolver ._registry ),
771
772
]
772
773
assert list (third .resolver .dynamic_scope ()) == [
773
774
("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 ),
774
779
]
775
- assert list (second .resolver .dynamic_scope ()) == []
776
780
assert list (first .resolver .dynamic_scope ()) == []
777
781
778
782
0 commit comments