1# UserString is a wrapper around the native builtin string type. 2# UserString instances should behave similar to builtin string objects. 3 4import unittest 5from test import string_tests 6 7from collections import UserString 8 9class UserStringTest( 10 string_tests.CommonTest, 11 string_tests.MixinStrUnicodeUserStringTest, 12 unittest.TestCase 13 ): 14 15 type2test = UserString 16 17 # Overwrite the three testing methods, because UserString 18 # can't cope with arguments propagated to UserString 19 # (and we don't test with subclasses) 20 def checkequal(self, result, object, methodname, *args, **kwargs): 21 result = self.fixtype(result) 22 object = self.fixtype(object) 23 # we don't fix the arguments, because UserString can't cope with it 24 realresult = getattr(object, methodname)(*args, **kwargs) 25 self.assertEqual( 26 result, 27 realresult 28 ) 29 30 def checkraises(self, exc, obj, methodname, *args): 31 obj = self.fixtype(obj) 32 # we don't fix the arguments, because UserString can't cope with it 33 with self.assertRaises(exc) as cm: 34 getattr(obj, methodname)(*args) 35 self.assertNotEqual(str(cm.exception), '') 36 37 def checkcall(self, object, methodname, *args): 38 object = self.fixtype(object) 39 # we don't fix the arguments, because UserString can't cope with it 40 getattr(object, methodname)(*args) 41 42 43if __name__ == "__main__": 44 unittest.main() 45