File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -219,7 +219,7 @@ def __getitem__(self, uri: URI) -> Resource[D]:
219219 except exceptions .NoSuchResource :
220220 raise
221221 except Exception :
222- raise exceptions .NoSuchResource (ref = uri )
222+ raise exceptions .Unretrievable (ref = uri )
223223
224224 def __iter__ (self ) -> Iterator [URI ]:
225225 """
@@ -414,6 +414,8 @@ def lookup(self, ref: URI) -> Resolved[D]:
414414 resource = registry [uri ]
415415 except exceptions .NoSuchResource :
416416 raise exceptions .Unresolvable (ref = ref ) from None
417+ except exceptions .Unretrievable :
418+ raise exceptions .Unresolvable (ref = ref )
417419
418420 if fragment .startswith ("/" ):
419421 return resource .pointer (
Original file line number Diff line number Diff line change @@ -17,6 +17,20 @@ class NoSuchResource(KeyError):
1717
1818 ref : URI
1919
20+ def __eq__ (self , other : Any ) -> bool :
21+ if self .__class__ is not other .__class__ :
22+ return NotImplemented
23+ return attrs .astuple (self ) == attrs .astuple (other )
24+
25+
26+ @frozen
27+ class Unretrievable (KeyError ):
28+ """
29+ The given URI is not present in a registry, and retrieving it failed.
30+ """
31+
32+ ref : URI
33+
2034
2135@frozen
2236class CannotDetermineSpecification (Exception ):
Original file line number Diff line number Diff line change @@ -174,6 +174,12 @@ def test_dict_conversion(self):
174174 .crawl ()
175175 )
176176
177+ def test_no_such_resource (self ):
178+ registry = Registry ()
179+ with pytest .raises (exceptions .NoSuchResource ) as e :
180+ registry ["urn:bigboom" ]
181+ assert e .value == exceptions .NoSuchResource (ref = "urn:bigboom" )
182+
177183 def test_combine (self ):
178184 one = Resource .opaque (contents = {})
179185 two = ID_AND_CHILDREN .create_resource ({"foo" : "bar" })
@@ -388,7 +394,7 @@ def retrieve(uri):
388394
389395 registry = Registry (retrieve = retrieve )
390396 assert registry ["urn:succeed" ] == {}
391- with pytest .raises (exceptions .NoSuchResource ):
397+ with pytest .raises (exceptions .Unretrievable ):
392398 registry ["urn:uhoh" ]
393399
394400 def test_retrieve_already_available_resource (self ):
You can’t perform that action at this time.
0 commit comments