blob: a0fefc3672017bd6e833f2bd11af5b8d06ffd50f [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
5import unittest
Thomas Woutersed03b412007-08-28 21:37:11 +00006import string
Walter Dörwald0fd583c2003-02-21 12:53:50 +00007from test import test_support, string_tests
8
Raymond Hettingerb3a65f82008-02-21 22:11:37 +00009from collections import UserString
Fred Drakea22b5762000-04-03 03:51:50 +000010
Walter Dörwald0fd583c2003-02-21 12:53:50 +000011class UserStringTest(
12 string_tests.CommonTest,
13 string_tests.MixinStrUnicodeUserStringTest,
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)
21 def checkequal(self, result, object, methodname, *args):
22 result = self.fixtype(result)
23 object = self.fixtype(object)
24 # we don't fix the arguments, because UserString can't cope with it
25 realresult = getattr(object, methodname)(*args)
26 self.assertEqual(
27 result,
28 realresult
29 )
30
31 def checkraises(self, exc, object, methodname, *args):
32 object = self.fixtype(object)
33 # we don't fix the arguments, because UserString can't cope with it
34 self.assertRaises(
35 exc,
36 getattr(object, methodname),
37 *args
38 )
39
40 def checkcall(self, object, methodname, *args):
41 object = self.fixtype(object)
42 # we don't fix the arguments, because UserString can't cope with it
43 getattr(object, methodname)(*args)
44
Walter Dörwald7f791522005-02-17 22:03:31 +000045
Walter Dörwald0fd583c2003-02-21 12:53:50 +000046def test_main():
Raymond Hettingerb3a65f82008-02-21 22:11:37 +000047 test_support.run_unittest(UserStringTest)
Walter Dörwald0fd583c2003-02-21 12:53:50 +000048
Fred Drakea22b5762000-04-03 03:51:50 +000049if __name__ == "__main__":
Walter Dörwald0fd583c2003-02-21 12:53:50 +000050 test_main()