File tree 2 files changed +27
-7
lines changed
2 files changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -213,11 +213,23 @@ def __str__(self):
213
213
214
214
class _WrappedReferencingError (_RefResolutionError , _Unresolvable ):
215
215
def __init__ (self , cause : _Unresolvable ):
216
- object .__setattr__ (self , "_cause " , cause )
216
+ object .__setattr__ (self , "_wrapped " , cause )
217
217
218
- def __getattribute__ (self , attr ):
219
- cause = object .__getattribute__ (self , "_cause" )
220
- return getattr (cause , attr )
218
+ def __eq__ (self , other ):
219
+ if other .__class__ is self .__class__ :
220
+ return self ._wrapped == other ._wrapped
221
+ elif other .__class__ is self ._wrapped .__class__ :
222
+ return self ._wrapped == other
223
+ return NotImplemented
224
+
225
+ def __getattr__ (self , attr ):
226
+ return getattr (self ._wrapped , attr )
227
+
228
+ def __repr__ (self ):
229
+ return f"<WrappedReferencingError { self ._wrapped !r} >"
230
+
231
+ def __str__ (self ):
232
+ return f"{ self ._wrapped .__class__ .__name__ } : { self ._wrapped } "
221
233
222
234
223
235
class UndefinedTypeCheck (Exception ):
Original file line number Diff line number Diff line change @@ -184,7 +184,10 @@ def test_catching_Unresolvable_directly(self):
184
184
validator .validate (12 )
185
185
186
186
expected = referencing .exceptions .Unresolvable (ref = "urn:nothing" )
187
- self .assertEqual (e .exception , expected )
187
+ self .assertEqual (
188
+ (e .exception , str (e .exception )),
189
+ (expected , "Unresolvable: urn:nothing" )
190
+ )
188
191
189
192
def test_catching_Unresolvable_via_RefResolutionError (self ):
190
193
"""
@@ -197,12 +200,17 @@ def test_catching_Unresolvable_via_RefResolutionError(self):
197
200
198
201
validator = validators .Draft202012Validator ({"$ref" : "urn:nothing" })
199
202
200
- with self .assertRaises (referencing .exceptions .Unresolvable ):
203
+ with self .assertRaises (referencing .exceptions .Unresolvable ) as u :
201
204
validator .validate (12 )
202
205
203
- with self .assertRaises (RefResolutionError ):
206
+ with self .assertRaises (RefResolutionError ) as e :
204
207
validator .validate (12 )
205
208
209
+ self .assertEqual (
210
+ (e .exception , str (e .exception )),
211
+ (u .exception , "Unresolvable: urn:nothing" )
212
+ )
213
+
206
214
def test_Validator_subclassing (self ):
207
215
"""
208
216
As of v4.12.0, subclassing a validator class produces an explicit
You can’t perform that action at this time.
0 commit comments