blob: 71528223d35bb563158a20a1378c125e9b342770 [file] [log] [blame]
Fred Drakea22b5762000-04-03 03:51:50 +00001# UserString is a wrapper around the native builtin string type.
2# UserString instances should behave similar to builtin string objects.
Walter Dörwald0fd583c2003-02-21 12:53:50 +00003
Ezio Melotti0dceb562013-01-10 07:43:26 +02004import unittest
Serhiy Storchaka597d15a2016-04-24 13:45:58 +03005from test import string_tests
Walter Dörwald0fd583c2003-02-21 12:53:50 +00006
Raymond Hettingerb3a65f82008-02-21 22:11:37 +00007from collections import UserString
Fred Drakea22b5762000-04-03 03:51:50 +00008
Walter Dörwald0fd583c2003-02-21 12:53:50 +00009class UserStringTest(
10 string_tests.CommonTest,
11 string_tests.MixinStrUnicodeUserStringTest,
Ezio Melotti0dceb562013-01-10 07:43:26 +020012 unittest.TestCase
Walter Dörwald0fd583c2003-02-21 12:53:50 +000013 ):
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)
Mark Dickinson0d5f6ad2011-09-24 09:14:39 +010020 def checkequal(self, result, object, methodname, *args, **kwargs):
Walter Dörwald0fd583c2003-02-21 12:53:50 +000021 result = self.fixtype(result)
22 object = self.fixtype(object)
23 # we don't fix the arguments, because UserString can't cope with it
Mark Dickinson0d5f6ad2011-09-24 09:14:39 +010024 realresult = getattr(object, methodname)(*args, **kwargs)
Walter Dörwald0fd583c2003-02-21 12:53:50 +000025 self.assertEqual(
26 result,
27 realresult
28 )
29
Benjamin Petersonc31f12d2014-09-28 12:56:42 -040030 def checkraises(self, exc, obj, methodname, *args):
31 obj = self.fixtype(obj)
Walter Dörwald0fd583c2003-02-21 12:53:50 +000032 # we don't fix the arguments, because UserString can't cope with it
Benjamin Petersonc31f12d2014-09-28 12:56:42 -040033 with self.assertRaises(exc) as cm:
34 getattr(obj, methodname)(*args)
35 self.assertNotEqual(str(cm.exception), '')
Walter Dörwald0fd583c2003-02-21 12:53:50 +000036
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
Walter Dörwald7f791522005-02-17 22:03:31 +000042
Fred Drakea22b5762000-04-03 03:51:50 +000043if __name__ == "__main__":
Ezio Melotti0dceb562013-01-10 07:43:26 +020044 unittest.main()