Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_userstring.py @ 28646:193b8aec00ce legacy-trunk
Changes from Jonathan Riehl to allow his pgen extension (PEP 269) to
work. This includes some more code that used to be part of pgen in
the main parser; I'm okay with that. I'll see if the Windows build
needs work next.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Apr 2003 14:55:42 +0000 |
| parents | fe10ece8ba68 |
| children | 1741af48fd9f |
| rev | line source |
|---|---|
|
12214
a216fe79ae00
UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
|
a216fe79ae00
UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
2 # UserString is a wrapper around the native builtin string type. |
|
a216fe79ae00
UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
3 # UserString instances should behave similar to builtin string objects. |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
4 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
5 import unittest |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
6 from test import test_support, string_tests |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
7 |
|
12214
a216fe79ae00
UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
8 from UserString import UserString |
|
a216fe79ae00
UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
9 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
10 class UserStringTest( |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
11 string_tests.CommonTest, |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
12 string_tests.MixinStrUnicodeUserStringTest, |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
13 string_tests.MixinStrStringUserStringTest, |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
14 string_tests.MixinStrUserStringTest |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
15 ): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
16 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
17 type2test = UserString |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
18 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
19 # Overwrite the three testing methods, because UserString |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
20 # can't cope with arguments propagated to UserString |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
21 # (and we don't test with subclasses) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
22 def checkequal(self, result, object, methodname, *args): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
23 result = self.fixtype(result) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
24 object = self.fixtype(object) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
25 # we don't fix the arguments, because UserString can't cope with it |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
26 realresult = getattr(object, methodname)(*args) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
27 self.assertEqual( |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
28 result, |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
29 realresult |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
30 ) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
31 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
32 def checkraises(self, exc, object, methodname, *args): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
33 object = self.fixtype(object) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
34 # we don't fix the arguments, because UserString can't cope with it |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
35 self.assertRaises( |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
36 exc, |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
37 getattr(object, methodname), |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
38 *args |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
39 ) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
40 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
41 def checkcall(self, object, methodname, *args): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
42 object = self.fixtype(object) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
43 # we don't fix the arguments, because UserString can't cope with it |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
44 getattr(object, methodname)(*args) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
45 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
46 def test_main(): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
47 suite = unittest.TestSuite() |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
48 suite.addTest(unittest.makeSuite(UserStringTest)) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
49 test_support.run_suite(suite) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
50 |
|
12214
a216fe79ae00
UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
51 if __name__ == "__main__": |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
52 test_main() |
