blob: 71fcac25e13fe6c1ccc5c09b145614e160c2654b [file] [log] [blame]
Benjamin Peterson90f5ba52010-03-11 22:53:45 +00001#!/usr/bin/env python3
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
Ezio Melotti0dceb562013-01-10 07:43:26 +02006import unittest
Benjamin Petersonee8712c2008-05-20 21:35:26 +00007from test import support, string_tests
Walter Dörwald0fd583c2003-02-21 12:53:50 +00008
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,
Ezio Melotti0dceb562013-01-10 07:43:26 +020014 unittest.TestCase
Walter Dörwald0fd583c2003-02-21 12:53:50 +000015 ):
16
17 type2test = UserString
18
19 # Overwrite the three testing methods, because UserString
20 # can't cope with arguments propagated to UserString
21 # (and we don't test with subclasses)
Mark Dickinson0d5f6ad2011-09-24 09:14:39 +010022 def checkequal(self, result, object, methodname, *args, **kwargs):
Walter Dörwald0fd583c2003-02-21 12:53:50 +000023 result = self.fixtype(result)
24 object = self.fixtype(object)
25 # we don't fix the arguments, because UserString can't cope with it
Mark Dickinson0d5f6ad2011-09-24 09:14:39 +010026 realresult = getattr(object, methodname)(*args, **kwargs)
Walter Dörwald0fd583c2003-02-21 12:53:50 +000027 self.assertEqual(
28 result,
29 realresult
30 )
31
32 def checkraises(self, exc, object, methodname, *args):
33 object = self.fixtype(object)
34 # we don't fix the arguments, because UserString can't cope with it
35 self.assertRaises(
36 exc,
37 getattr(object, methodname),
38 *args
39 )
40
41 def checkcall(self, object, methodname, *args):
42 object = self.fixtype(object)
43 # we don't fix the arguments, because UserString can't cope with it
44 getattr(object, methodname)(*args)
45
Walter Dörwald7f791522005-02-17 22:03:31 +000046
Fred Drakea22b5762000-04-03 03:51:50 +000047if __name__ == "__main__":
Ezio Melotti0dceb562013-01-10 07:43:26 +020048 unittest.main()