Benjamin Peterson | 90f5ba5 | 2010-03-11 22:53:45 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
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 |
Ezio Melotti | 0dceb56 | 2013-01-10 07:43:26 +0200 | [diff] [blame] | 6 | import unittest |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 7 | from test import support, string_tests |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 8 | |
Raymond Hettinger | b3a65f8 | 2008-02-21 22:11:37 +0000 | [diff] [blame] | 9 | from collections import UserString |
Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 10 | |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 11 | class UserStringTest( |
| 12 | string_tests.CommonTest, |
| 13 | string_tests.MixinStrUnicodeUserStringTest, |
Ezio Melotti | 0dceb56 | 2013-01-10 07:43:26 +0200 | [diff] [blame] | 14 | unittest.TestCase |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 15 | ): |
| 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 Dickinson | 0d5f6ad | 2011-09-24 09:14:39 +0100 | [diff] [blame] | 22 | def checkequal(self, result, object, methodname, *args, **kwargs): |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 23 | result = self.fixtype(result) |
| 24 | object = self.fixtype(object) |
| 25 | # 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] | 26 | realresult = getattr(object, methodname)(*args, **kwargs) |
Walter Dörwald | 0fd583c | 2003-02-21 12:53:50 +0000 | [diff] [blame] | 27 | 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örwald | 7f79152 | 2005-02-17 22:03:31 +0000 | [diff] [blame] | 46 | |
Fred Drake | a22b576 | 2000-04-03 03:51:50 +0000 | [diff] [blame] | 47 | if __name__ == "__main__": |
Ezio Melotti | 0dceb56 | 2013-01-10 07:43:26 +0200 | [diff] [blame] | 48 | unittest.main() |