Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 1 | # UserString is a wrapper around the native builtin string type. |
| 2 | # UserString instances should behave similar to builtin string objects. |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 3 | |
Thomas Wouters | ed03b41 | 2007-08-28 21:37:11 +0000 | [diff] [blame] | 4 | import string |
Ezio Melotti | 0dceb56 | 2013-01-10 07:43:26 +0200 | [diff] [blame] | 5 | import unittest |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 6 | from test import support, string_tests |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 7 | |
Raymond Hettinger | b3a65f8 | 2008-02-21 22:11:37 +0000 | [diff] [blame] | 8 | from collections import UserString |
Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 9 | |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 10 | class UserStringTest( |
| 11 | string_tests.CommonTest, |
| 12 | string_tests.MixinStrUnicodeUserStringTest, |
Ezio Melotti | 0dceb56 | 2013-01-10 07:43:26 +0200 | [diff] [blame] | 13 | unittest.TestCase |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 14 | ): |
| 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 Dickinson | 0d5f6ad | 2011-09-24 09:14:39 +0100 | [diff] [blame] | 21 | def checkequal(self, result, object, methodname, *args, **kwargs): |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 22 | result = self.fixtype(result) |
| 23 | object = self.fixtype(object) |
| 24 | # we don't fix the arguments, because UserString can't cope with it |
Mark Dickinson | 0d5f6ad | 2011-09-24 09:14:39 +0100 | [diff] [blame] | 25 | realresult = getattr(object, methodname)(*args, **kwargs) |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 26 | self.assertEqual( |
| 27 | result, |
| 28 | realresult |
| 29 | ) |
| 30 | |
Benjamin Peterson | c31f12d | 2014-09-28 12:56:42 -0400 | [diff] [blame] | 31 | def checkraises(self, exc, obj, methodname, *args): |
| 32 | obj = self.fixtype(obj) |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 33 | # we don't fix the arguments, because UserString can't cope with it |
Benjamin Peterson | c31f12d | 2014-09-28 12:56:42 -0400 | [diff] [blame] | 34 | with self.assertRaises(exc) as cm: |
| 35 | getattr(obj, methodname)(*args) |
| 36 | self.assertNotEqual(str(cm.exception), '') |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 37 | |
| 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örwald | 7f79152 | 2005-02-17 22:03:31 +0000 | [diff] [blame] | 43 | |
Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 44 | if __name__ == "__main__": |
Ezio Melotti | 0dceb56 | 2013-01-10 07:43:26 +0200 | [diff] [blame] | 45 | unittest.main() |