blob: 9bc8edd99d2eb9595cc4df4c5c902a9c983f144a [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
Thomas Woutersed03b412007-08-28 21:37:11 +00004import string
Ezio Melotti0dceb562013-01-10 07:43:26 +02005import unittest
Benjamin Petersonee8712c2008-05-20 21:35:26 +00006from test import support, string_tests
Walter Dörwald0fd583c2003-02-21 12:53:50 +00007
Raymond Hettingerb3a65f82008-02-21 22:11:37 +00008from collections import UserString
Fred Drakea22b5762000-04-03 03:51:50 +00009
Walter Dörwald0fd583c2003-02-21 12:53:50 +000010class UserStringTest(
11 string_tests.CommonTest,
12 string_tests.MixinStrUnicodeUserStringTest,
Ezio Melotti0dceb562013-01-10 07:43:26 +020013 unittest.TestCase
Walter Dörwald0fd583c2003-02-21 12:53:50 +000014 ):
15
16 type2test = UserString
17
18 # Overwrite the three testing methods, because UserString
19 # can't cope with arguments propagated to UserString
20 # (and we don't test with subclasses)
Mark Dickinson0d5f6ad2011-09-24 09:14:39 +010021 def checkequal(self, result, object, methodname, *args, **kwargs):
Walter Dörwald0fd583c2003-02-21 12:53:50 +000022 result = self.fixtype(result)
23 object = self.fixtype(object)
24 # we don't fix the arguments, because UserString can't cope with it
Mark Dickinson0d5f6ad2011-09-24 09:14:39 +010025 realresult = getattr(object, methodname)(*args, **kwargs)
Walter Dörwald0fd583c2003-02-21 12:53:50 +000026 self.assertEqual(
27 result,
28 realresult
29 )
30
Benjamin Petersonc31f12d2014-09-28 12:56:42 -040031 def checkraises(self, exc, obj, methodname, *args):
32 obj = self.fixtype(obj)
Walter Dörwald0fd583c2003-02-21 12:53:50 +000033 # we don't fix the arguments, because UserString can't cope with it
Benjamin Petersonc31f12d2014-09-28 12:56:42 -040034 with self.assertRaises(exc) as cm:
35 getattr(obj, methodname)(*args)
36 self.assertNotEqual(str(cm.exception), '')
Walter Dörwald0fd583c2003-02-21 12:53:50 +000037
38 def checkcall(self, object, methodname, *args):
39 object = self.fixtype(object)
40 # we don't fix the arguments, because UserString can't cope with it
41 getattr(object, methodname)(*args)
42
Walter Dörwald7f791522005-02-17 22:03:31 +000043
Fred Drakea22b5762000-04-03 03:51:50 +000044if __name__ == "__main__":
Ezio Melotti0dceb562013-01-10 07:43:26 +020045 unittest.main()