Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_userstring.py @ 74006:88198b93ff2f
Issue #13560: Add PyUnicode_EncodeLocale()
* Use PyUnicode_EncodeLocale() in time.strftime() if wcsftime() is not
available
* Document my last changes in Misc/NEWS
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Sat, 17 Dec 2011 04:13:41 +0100 |
| parents | 0b2660384d4e |
| children | 55383912c225 |
| rev | line source |
|---|---|
|
59522
fcfe324663a6
convert shebang lines: python -> python3
Benjamin Peterson <benjamin@python.org>
parents:
47201
diff
changeset
|
1 #!/usr/bin/env python3 |
|
12214
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 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42088
diff
changeset
|
5 import string |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
45471
diff
changeset
|
6 from test import support, string_tests |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
7 |
|
45424
a9e1fdaf413d
Move UserString to collections.
Raymond Hettinger <python@rcn.com>
parents:
42954
diff
changeset
|
8 from collections import UserString |
|
12214
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 ): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
14 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
15 type2test = UserString |
|
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 # 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
|
18 # 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
|
19 # (and we don't test with subclasses) |
|
72462
0b2660384d4e
Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents:
59522
diff
changeset
|
20 def checkequal(self, result, object, methodname, *args, **kwargs): |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
21 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
|
22 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
|
23 # we don't fix the arguments, because UserString can't cope with it |
|
72462
0b2660384d4e
Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents:
59522
diff
changeset
|
24 realresult = getattr(object, methodname)(*args, **kwargs) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
25 self.assertEqual( |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
26 result, |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
27 realresult |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
28 ) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
29 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
30 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
|
31 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
|
32 # 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
|
33 self.assertRaises( |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
34 exc, |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
35 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
|
36 *args |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
37 ) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
38 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
39 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
|
40 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
|
41 # 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
|
42 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
|
43 |
|
34609
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
44 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
45 def test_main(): |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
45471
diff
changeset
|
46 support.run_unittest(UserStringTest) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
47 |
|
12214
a216fe79ae00
UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
48 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
|
49 test_main() |
