Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_userstring.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | b36cb4602e21 |
| children |
| 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 |
|
42951
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
5 import string |
|
28009
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 |
|
34606
8b4dd2c1c2a0
Add a basic test for UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
7 from UserString import UserString, MutableString |
|
47362
156746a63a5c
UserString.MutableString has been removed in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
8 import warnings |
|
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 string_tests.MixinStrStringUserStringTest, |
|
32951
024ff0ab4588
SF #989185: Drop unicode.iswide() and unicode.width() and add
Hye-Shik Chang <hyeshik@gmail.com>
parents:
32237
diff
changeset
|
14 string_tests.MixinStrUserStringTest |
|
28009
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 |
|
34606
8b4dd2c1c2a0
Add a basic test for UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
46 class MutableStringTest(UserStringTest): |
|
8b4dd2c1c2a0
Add a basic test for UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
47 type2test = MutableString |
|
8b4dd2c1c2a0
Add a basic test for UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
48 |
|
8b4dd2c1c2a0
Add a basic test for UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
49 # MutableStrings can be hashed => deactivate test |
|
8b4dd2c1c2a0
Add a basic test for UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
50 def test_hash(self): |
|
8b4dd2c1c2a0
Add a basic test for UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
51 pass |
|
8b4dd2c1c2a0
Add a basic test for UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
52 |
|
34609
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
53 def test_setitem(self): |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
54 s = self.type2test("foo") |
|
34614
ac6dfc67c77f
Add support for negative indices in UserString.MutableString.__setitem__
Walter Dörwald <walter@livinglogic.de>
parents:
34610
diff
changeset
|
55 self.assertRaises(IndexError, s.__setitem__, -4, "bar") |
|
34609
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
56 self.assertRaises(IndexError, s.__setitem__, 3, "bar") |
|
34614
ac6dfc67c77f
Add support for negative indices in UserString.MutableString.__setitem__
Walter Dörwald <walter@livinglogic.de>
parents:
34610
diff
changeset
|
57 s[-1] = "bar" |
|
ac6dfc67c77f
Add support for negative indices in UserString.MutableString.__setitem__
Walter Dörwald <walter@livinglogic.de>
parents:
34610
diff
changeset
|
58 self.assertEqual(s, "fobar") |
|
34609
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
59 s[0] = "bar" |
|
34614
ac6dfc67c77f
Add support for negative indices in UserString.MutableString.__setitem__
Walter Dörwald <walter@livinglogic.de>
parents:
34610
diff
changeset
|
60 self.assertEqual(s, "barobar") |
|
34609
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
61 |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
62 def test_delitem(self): |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
63 s = self.type2test("foo") |
|
34614
ac6dfc67c77f
Add support for negative indices in UserString.MutableString.__setitem__
Walter Dörwald <walter@livinglogic.de>
parents:
34610
diff
changeset
|
64 self.assertRaises(IndexError, s.__delitem__, -4) |
|
34610
7c5732652a23
Fix copy & paste error.
Walter Dörwald <walter@livinglogic.de>
parents:
34609
diff
changeset
|
65 self.assertRaises(IndexError, s.__delitem__, 3) |
|
34614
ac6dfc67c77f
Add support for negative indices in UserString.MutableString.__setitem__
Walter Dörwald <walter@livinglogic.de>
parents:
34610
diff
changeset
|
66 del s[-1] |
|
ac6dfc67c77f
Add support for negative indices in UserString.MutableString.__setitem__
Walter Dörwald <walter@livinglogic.de>
parents:
34610
diff
changeset
|
67 self.assertEqual(s, "fo") |
|
34609
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
68 del s[0] |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
69 self.assertEqual(s, "o") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
70 del s[0] |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
71 self.assertEqual(s, "") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
72 |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
73 def test_setslice(self): |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
74 s = self.type2test("foo") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
75 s[:] = "bar" |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
76 self.assertEqual(s, "bar") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
77 s[1:2] = "foo" |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
78 self.assertEqual(s, "bfoor") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
79 s[1:-1] = UserString("a") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
80 self.assertEqual(s, "bar") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
81 s[0:10] = 42 |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
82 self.assertEqual(s, "42") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
83 |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
84 def test_delslice(self): |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
85 s = self.type2test("foobar") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
86 del s[3:10] |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
87 self.assertEqual(s, "foo") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
88 del s[-1:10] |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
89 self.assertEqual(s, "fo") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
90 |
|
42951
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
91 def test_extended_set_del_slice(self): |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
92 indices = (0, None, 1, 3, 19, 100, -1, -2, -31, -100) |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
93 orig = string.ascii_letters + string.digits |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
94 for start in indices: |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
95 for stop in indices: |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
96 # Use indices[1:] when MutableString can handle real |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
97 # extended slices |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
98 for step in (None, 1, -1): |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
99 s = self.type2test(orig) |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
100 L = list(orig) |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
101 # Make sure we have a slice of exactly the right length, |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
102 # but with (hopefully) different data. |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
103 data = L[start:stop:step] |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
104 data.reverse() |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
105 L[start:stop:step] = data |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
106 s[start:stop:step] = "".join(data) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58605
diff
changeset
|
107 self.assertEqual(s, "".join(L)) |
|
42951
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
108 |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
109 del L[start:stop:step] |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
110 del s[start:stop:step] |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58605
diff
changeset
|
111 self.assertEqual(s, "".join(L)) |
|
42951
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
34614
diff
changeset
|
112 |
|
34609
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
113 def test_immutable(self): |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
114 s = self.type2test("foobar") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
115 s2 = s.immutable() |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
116 self.assertEqual(s, s2) |
|
58472
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
117 self.assertIsInstance(s2, UserString) |
|
34609
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
118 |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
119 def test_iadd(self): |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
120 s = self.type2test("foo") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
121 s += "bar" |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
122 self.assertEqual(s, "foobar") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
123 s += UserString("baz") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
124 self.assertEqual(s, "foobarbaz") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
125 s += 42 |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
126 self.assertEqual(s, "foobarbaz42") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
127 |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
128 def test_imul(self): |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
129 s = self.type2test("foo") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
130 s *= 1 |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
131 self.assertEqual(s, "foo") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
132 s *= 2 |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
133 self.assertEqual(s, "foofoo") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
134 s *= -1 |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
135 self.assertEqual(s, "") |
|
c60fde8b0106
Add tests for the methods added by UserString.MutableString.
Walter Dörwald <walter@livinglogic.de>
parents:
34606
diff
changeset
|
136 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
137 def test_main(): |
|
49099
ff96a313cd1c
warnings.catch_warnings() now returns a list or None instead of the custom
Brett Cannon <bcannon@gmail.com>
parents:
47362
diff
changeset
|
138 with warnings.catch_warnings(): |
|
63534
2dc0b7131c72
Merged revisions 77871,77910,77913 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49099
diff
changeset
|
139 warnings.filterwarnings("ignore", ".*MutableString has been removed", |
|
2dc0b7131c72
Merged revisions 77871,77910,77913 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49099
diff
changeset
|
140 DeprecationWarning) |
|
2dc0b7131c72
Merged revisions 77871,77910,77913 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49099
diff
changeset
|
141 warnings.filterwarnings("ignore", |
|
2dc0b7131c72
Merged revisions 77871,77910,77913 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49099
diff
changeset
|
142 ".*__(get|set|del)slice__ has been removed", |
|
47362
156746a63a5c
UserString.MutableString has been removed in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
143 DeprecationWarning) |
|
156746a63a5c
UserString.MutableString has been removed in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
144 test_support.run_unittest(UserStringTest, MutableStringTest) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
24684
diff
changeset
|
145 |
|
12214
a216fe79ae00
UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
146 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
|
147 test_main() |
