Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 2 | # UserString is a wrapper around the native builtin string type. |
| 3 | # UserString instances should behave similar to builtin string objects. |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 4 | |
Thomas Wouters | ed03b41 | 2007-08-28 21:37:11 +0000 | [diff] [blame] | 5 | import string |
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, |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 13 | ): |
| 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örwald | 7f79152 | 2005-02-17 22:03:31 +0000 | [diff] [blame] | 44 | |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 45 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 46 | support.run_unittest(UserStringTest) |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 47 | |
Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 48 | if __name__ == "__main__": |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 49 | test_main() |