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 | |
| 5 | import unittest |
| 6 | from test import test_support, string_tests |
| 7 | |
Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 8 | from UserString import UserString |
| 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, |
| 13 | string_tests.MixinStrStringUserStringTest, |
Hye-Shik Chang | 5f51259 | 2004-06-04 03:18:12 +0000 | [diff] [blame^] | 14 | string_tests.MixinStrUserStringTest, |
| 15 | string_tests.MixinUnicodeUserStringTest |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 16 | ): |
| 17 | |
| 18 | type2test = UserString |
| 19 | |
| 20 | # Overwrite the three testing methods, because UserString |
| 21 | # can't cope with arguments propagated to UserString |
| 22 | # (and we don't test with subclasses) |
| 23 | def checkequal(self, result, object, methodname, *args): |
| 24 | result = self.fixtype(result) |
| 25 | object = self.fixtype(object) |
| 26 | # we don't fix the arguments, because UserString can't cope with it |
| 27 | realresult = getattr(object, methodname)(*args) |
| 28 | self.assertEqual( |
| 29 | result, |
| 30 | realresult |
| 31 | ) |
| 32 | |
| 33 | def checkraises(self, exc, object, methodname, *args): |
| 34 | object = self.fixtype(object) |
| 35 | # we don't fix the arguments, because UserString can't cope with it |
| 36 | self.assertRaises( |
| 37 | exc, |
| 38 | getattr(object, methodname), |
| 39 | *args |
| 40 | ) |
| 41 | |
| 42 | def checkcall(self, object, methodname, *args): |
| 43 | object = self.fixtype(object) |
| 44 | # we don't fix the arguments, because UserString can't cope with it |
| 45 | getattr(object, methodname)(*args) |
| 46 | |
| 47 | def test_main(): |
Walter Dörwald | 21d3a32 | 2003-05-01 17:45:56 +0000 | [diff] [blame] | 48 | test_support.run_unittest(UserStringTest) |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 49 | |
Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 50 | if __name__ == "__main__": |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 51 | test_main() |