@@ -1163,7 +1163,7 @@ def __repr__(self):
11631163 ):
11641164 encode ({"t" : Wrapper (1 )})
11651165
1166- def test_doc_in_invalid_document_error_message (self ):
1166+ def test_doc_in_invalid_document_error_as_property (self ):
11671167 class Wrapper :
11681168 def __init__ (self , val ):
11691169 self .val = val
@@ -1173,10 +1173,11 @@ def __repr__(self):
11731173
11741174 self .assertEqual ("1" , repr (Wrapper (1 )))
11751175 doc = {"t" : Wrapper (1 )}
1176- with self .assertRaisesRegex (InvalidDocument , f "Invalid document { doc } " ) :
1176+ with self .assertRaisesRegex (InvalidDocument , "Invalid document:" ) as cm :
11771177 encode (doc )
1178+ self .assertEqual (cm .exception .document , doc )
11781179
1179- def test_doc_in_invalid_document_error_message_mapping (self ):
1180+ def test_doc_in_invalid_document_error_as_property_mapping (self ):
11801181 class MyMapping (abc .Mapping ):
11811182 def keys (self ):
11821183 return ["t" ]
@@ -1192,6 +1193,11 @@ def __len__(self):
11921193 def __iter__ (self ):
11931194 return iter (["t" ])
11941195
1196+ def __eq__ (self , other ):
1197+ if isinstance (other , MyMapping ):
1198+ return True
1199+ return False
1200+
11951201 class Wrapper :
11961202 def __init__ (self , val ):
11971203 self .val = val
@@ -1201,8 +1207,9 @@ def __repr__(self):
12011207
12021208 self .assertEqual ("1" , repr (Wrapper (1 )))
12031209 doc = MyMapping ()
1204- with self .assertRaisesRegex (InvalidDocument , f "Invalid document { doc } " ) :
1210+ with self .assertRaisesRegex (InvalidDocument , "Invalid document:" ) as cm :
12051211 encode (doc )
1212+ self .assertEqual (cm .exception .document , doc )
12061213
12071214
12081215class TestCodecOptions (unittest .TestCase ):
0 commit comments