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]:
219
219
except exceptions .NoSuchResource :
220
220
raise
221
221
except Exception :
222
- raise exceptions .NoSuchResource (ref = uri )
222
+ raise exceptions .Unretrievable (ref = uri )
223
223
224
224
def __iter__ (self ) -> Iterator [URI ]:
225
225
"""
@@ -414,6 +414,8 @@ def lookup(self, ref: URI) -> Resolved[D]:
414
414
resource = registry [uri ]
415
415
except exceptions .NoSuchResource :
416
416
raise exceptions .Unresolvable (ref = ref ) from None
417
+ except exceptions .Unretrievable :
418
+ raise exceptions .Unresolvable (ref = ref )
417
419
418
420
if fragment .startswith ("/" ):
419
421
return resource .pointer (
Original file line number Diff line number Diff line change @@ -17,6 +17,20 @@ class NoSuchResource(KeyError):
17
17
18
18
ref : URI
19
19
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
+
20
34
21
35
@frozen
22
36
class CannotDetermineSpecification (Exception ):
Original file line number Diff line number Diff line change @@ -174,6 +174,12 @@ def test_dict_conversion(self):
174
174
.crawl ()
175
175
)
176
176
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
+
177
183
def test_combine (self ):
178
184
one = Resource .opaque (contents = {})
179
185
two = ID_AND_CHILDREN .create_resource ({"foo" : "bar" })
@@ -388,7 +394,7 @@ def retrieve(uri):
388
394
389
395
registry = Registry (retrieve = retrieve )
390
396
assert registry ["urn:succeed" ] == {}
391
- with pytest .raises (exceptions .NoSuchResource ):
397
+ with pytest .raises (exceptions .Unretrievable ):
392
398
registry ["urn:uhoh" ]
393
399
394
400
def test_retrieve_already_available_resource (self ):
You can’t perform that action at this time.
0 commit comments