@@ -80,12 +80,14 @@ class subtype(self.__class__.type2test):
8080 self .assertIsNot (obj , realresult )
8181
8282 # check that obj.method(*args) raises exc
83- def checkraises (self , exc , obj , methodname , * args ):
83+ def checkraises (self , exc , obj , methodname , * args , expected_msg = None ):
8484 obj = self .fixtype (obj )
8585 args = self .fixtype (args )
8686 with self .assertRaises (exc ) as cm :
8787 getattr (obj , methodname )(* args )
8888 self .assertNotEqual (str (cm .exception ), '' )
89+ if expected_msg is not None :
90+ self .assertEqual (str (cm .exception ), expected_msg )
8991
9092 # call obj.method(*args) without any checks
9193 def checkcall (self , obj , methodname , * args ):
@@ -1195,6 +1197,10 @@ def test_subscript(self):
11951197
11961198 self .checkraises (TypeError , 'abc' , '__getitem__' , 'def' )
11971199
1200+ for idx_type in ('def' , object ()):
1201+ expected_msg = "string indices must be integers, not '{}'" .format (type (idx_type ).__name__ )
1202+ self .checkraises (TypeError , 'abc' , '__getitem__' , idx_type , expected_msg = expected_msg )
1203+
11981204 def test_slice (self ):
11991205 self .checkequal ('abc' , 'abc' , '__getitem__' , slice (0 , 1000 ))
12001206 self .checkequal ('abc' , 'abc' , '__getitem__' , slice (0 , 3 ))
0 commit comments