@@ -1163,7 +1163,7 @@ def __repr__(self):
1163
1163
):
1164
1164
encode ({"t" : Wrapper (1 )})
1165
1165
1166
- def test_doc_in_invalid_document_error_message (self ):
1166
+ def test_doc_in_invalid_document_error_as_property (self ):
1167
1167
class Wrapper :
1168
1168
def __init__ (self , val ):
1169
1169
self .val = val
@@ -1173,10 +1173,11 @@ def __repr__(self):
1173
1173
1174
1174
self .assertEqual ("1" , repr (Wrapper (1 )))
1175
1175
doc = {"t" : Wrapper (1 )}
1176
- with self .assertRaisesRegex (InvalidDocument , f "Invalid document { doc } " ) :
1176
+ with self .assertRaisesRegex (InvalidDocument , "Invalid document:" ) as cm :
1177
1177
encode (doc )
1178
+ self .assertEqual (cm .exception .document , doc )
1178
1179
1179
- def test_doc_in_invalid_document_error_message_mapping (self ):
1180
+ def test_doc_in_invalid_document_error_as_property_mapping (self ):
1180
1181
class MyMapping (abc .Mapping ):
1181
1182
def keys (self ):
1182
1183
return ["t" ]
@@ -1192,6 +1193,11 @@ def __len__(self):
1192
1193
def __iter__ (self ):
1193
1194
return iter (["t" ])
1194
1195
1196
+ def __eq__ (self , other ):
1197
+ if isinstance (other , MyMapping ):
1198
+ return True
1199
+ return False
1200
+
1195
1201
class Wrapper :
1196
1202
def __init__ (self , val ):
1197
1203
self .val = val
@@ -1201,8 +1207,9 @@ def __repr__(self):
1201
1207
1202
1208
self .assertEqual ("1" , repr (Wrapper (1 )))
1203
1209
doc = MyMapping ()
1204
- with self .assertRaisesRegex (InvalidDocument , f "Invalid document { doc } " ) :
1210
+ with self .assertRaisesRegex (InvalidDocument , "Invalid document:" ) as cm :
1205
1211
encode (doc )
1212
+ self .assertEqual (cm .exception .document , doc )
1206
1213
1207
1214
1208
1215
class TestCodecOptions (unittest .TestCase ):
0 commit comments