blob: 05381384bf6a7b581cf66ced76575da22e9212e6 [file] [log] [blame]
Fred Drakea22b5762000-04-03 03:51:50 +00001#!/usr/bin/env python
Fred Drakea22b5762000-04-03 03:51:50 +00002# UserString is a wrapper around the native builtin string type.
3# UserString instances should behave similar to builtin string objects.
Walter Dörwald0fd583c2003-02-21 12:53:50 +00004
Thomas Woutersed03b412007-08-28 21:37:11 +00005import string
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,
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)
20 def checkequal(self, result, object, methodname, *args):
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)
25 self.assertEqual(
26 result,
27 realresult
28 )
29
30 def checkraises(self, exc, object, methodname, *args):
31 object = self.fixtype(object)
32 # we don't fix the arguments, because UserString can't cope with it
33 self.assertRaises(
34 exc,
35 getattr(object, methodname),
36 *args
37 )
38
39 def checkcall(self, object, methodname, *args):
40 object = self.fixtype(object)
41 # we don't fix the arguments, because UserString can't cope with it
42 getattr(object, methodname)(*args)
43
Walter Dörwald7f791522005-02-17 22:03:31 +000044
Walter Dörwald0fd583c2003-02-21 12:53:50 +000045def test_main():
Benjamin Petersonee8712c2008-05-20 21:35:26 +000046 support.run_unittest(UserStringTest)
Walter Dörwald0fd583c2003-02-21 12:53:50 +000047
Fred Drakea22b5762000-04-03 03:51:50 +000048if __name__ == "__main__":
Walter Dörwald0fd583c2003-02-21 12:53:50 +000049 test_main()