Mercurial > cpython-lru_cache-weakref
annotate Lib/test/string_tests.py @ 39042:c02fa187e0f4 legacy-trunk
Part of SF patch #1484695. This removes dead code. The chksum was
already verified in .frombuf() on the lines above. If there was
a problem an exception is raised, so there was no way this condition
could have been true.
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Mon, 10 Jul 2006 00:23:17 +0000 |
| parents | 67450db26f81 |
| children | 041eb6231cdc |
| rev | line source |
|---|---|
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1 """ |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
2 Common tests shared by test_str, test_unicode, test_userstring and test_string. |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
3 """ |
|
13517
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
4 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
5 import unittest, string, sys |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
6 from test import test_support |
|
13527
07c31182f237
add more tests of string.join variants to run_method_tests
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13517
diff
changeset
|
7 from UserList import UserList |
|
07c31182f237
add more tests of string.join variants to run_method_tests
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13517
diff
changeset
|
8 |
|
13517
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
9 class Sequence: |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
10 def __init__(self, seq='wxyz'): self.seq = seq |
|
13517
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
11 def __len__(self): return len(self.seq) |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
12 def __getitem__(self, i): return self.seq[i] |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
13 |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
14 class BadSeq1(Sequence): |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
15 def __init__(self): self.seq = [7, 'hello', 123L] |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
16 |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
17 class BadSeq2(Sequence): |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
18 def __init__(self): self.seq = ['a', 'b', 'c'] |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
19 def __len__(self): return 8 |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
20 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
21 class CommonTest(unittest.TestCase): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
22 # This testcase contains test that can be used in all |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
23 # stringlike classes. Currently this is str, unicode |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
24 # UserString and the string module. |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
25 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
26 # The type to be tested |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
27 # Change in subclasses to change the behaviour of fixtesttype() |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
28 type2test = None |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
29 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
30 # All tests pass their arguments to the testing methods |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
31 # as str objects. fixtesttype() can be used to propagate |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
32 # these arguments to the appropriate type |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
33 def fixtype(self, obj): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
34 if isinstance(obj, str): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
35 return self.__class__.type2test(obj) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
36 elif isinstance(obj, list): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
37 return [self.fixtype(x) for x in obj] |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
38 elif isinstance(obj, tuple): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
39 return tuple([self.fixtype(x) for x in obj]) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
40 elif isinstance(obj, dict): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
41 return dict([ |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
42 (self.fixtype(key), self.fixtype(value)) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
43 for (key, value) in obj.iteritems() |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
44 ]) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
45 else: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
46 return obj |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
47 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
48 # check that object.method(*args) returns result |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
49 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:
26625
diff
changeset
|
50 result = self.fixtype(result) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
51 object = self.fixtype(object) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
52 args = self.fixtype(args) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
53 realresult = getattr(object, methodname)(*args) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
54 self.assertEqual( |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
55 result, |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
56 realresult |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
57 ) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
58 # if the original is returned make sure that |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
59 # this doesn't happen with subclasses |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
60 if object == realresult: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
61 class subtype(self.__class__.type2test): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
62 pass |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
63 object = subtype(object) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
64 realresult = getattr(object, methodname)(*args) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
65 self.assert_(object is not realresult) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
66 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
67 # check that object.method(*args) raises exc |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
68 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:
26625
diff
changeset
|
69 object = self.fixtype(object) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
70 args = self.fixtype(args) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
71 self.assertRaises( |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
72 exc, |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
73 getattr(object, methodname), |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
74 *args |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
75 ) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
76 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
77 # call object.method(*args) without any checks |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
78 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:
26625
diff
changeset
|
79 object = self.fixtype(object) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
80 args = self.fixtype(args) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
81 getattr(object, methodname)(*args) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
82 |
|
33833
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
83 def test_hash(self): |
|
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
84 # SF bug 1054139: += optimization was not invalidating cached hash value |
|
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
85 a = self.type2test('DNSSEC') |
|
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
86 b = self.type2test('') |
|
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
87 for c in a: |
|
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
88 b += c |
|
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
89 hash(b) |
|
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
90 self.assertEqual(hash(a), hash(b)) |
|
10512ceba30c
SF bug #1054139: serious string hashing error in 2.4b1
Raymond Hettinger <python@rcn.com>
parents:
33305
diff
changeset
|
91 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
92 def test_capitalize(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
93 self.checkequal(' hello ', ' hello ', 'capitalize') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
94 self.checkequal('Hello ', 'Hello ','capitalize') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
95 self.checkequal('Hello ', 'hello ','capitalize') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
96 self.checkequal('Aaaa', 'aaaa', 'capitalize') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
97 self.checkequal('Aaaa', 'AaAa', 'capitalize') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
98 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
99 self.checkraises(TypeError, 'hello', 'capitalize', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
100 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
101 def test_count(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
102 self.checkequal(3, 'aaa', 'count', 'a') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
103 self.checkequal(0, 'aaa', 'count', 'b') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
104 self.checkequal(3, 'aaa', 'count', 'a') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
105 self.checkequal(0, 'aaa', 'count', 'b') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
106 self.checkequal(3, 'aaa', 'count', 'a') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
107 self.checkequal(0, 'aaa', 'count', 'b') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
108 self.checkequal(0, 'aaa', 'count', 'b') |
|
38492
d5bdfd120232
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
Fredrik Lundh <fredrik@pythonware.com>
parents:
38391
diff
changeset
|
109 self.checkequal(2, 'aaa', 'count', 'a', 1) |
|
d5bdfd120232
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
Fredrik Lundh <fredrik@pythonware.com>
parents:
38391
diff
changeset
|
110 self.checkequal(0, 'aaa', 'count', 'a', 10) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
111 self.checkequal(1, 'aaa', 'count', 'a', -1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
112 self.checkequal(3, 'aaa', 'count', 'a', -10) |
|
38492
d5bdfd120232
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
Fredrik Lundh <fredrik@pythonware.com>
parents:
38391
diff
changeset
|
113 self.checkequal(1, 'aaa', 'count', 'a', 0, 1) |
|
d5bdfd120232
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
Fredrik Lundh <fredrik@pythonware.com>
parents:
38391
diff
changeset
|
114 self.checkequal(3, 'aaa', 'count', 'a', 0, 10) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
115 self.checkequal(2, 'aaa', 'count', 'a', 0, -1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
116 self.checkequal(0, 'aaa', 'count', 'a', 0, -10) |
|
38492
d5bdfd120232
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
Fredrik Lundh <fredrik@pythonware.com>
parents:
38391
diff
changeset
|
117 self.checkequal(3, 'aaa', 'count', '', 1) |
|
38516
2fe3233bd426
changed count to return 0 for slices outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38514
diff
changeset
|
118 self.checkequal(1, 'aaa', 'count', '', 3) |
|
2fe3233bd426
changed count to return 0 for slices outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38514
diff
changeset
|
119 self.checkequal(0, 'aaa', 'count', '', 10) |
|
38492
d5bdfd120232
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
Fredrik Lundh <fredrik@pythonware.com>
parents:
38391
diff
changeset
|
120 self.checkequal(2, 'aaa', 'count', '', -1) |
|
d5bdfd120232
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
Fredrik Lundh <fredrik@pythonware.com>
parents:
38391
diff
changeset
|
121 self.checkequal(4, 'aaa', 'count', '', -10) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
122 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
123 self.checkraises(TypeError, 'hello', 'count') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
124 self.checkraises(TypeError, 'hello', 'count', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
125 |
|
34621
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
126 # For a variety of combinations, |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
127 # verify that str.count() matches an equivalent function |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
128 # replacing all occurrences and then differencing the string lengths |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
129 charset = ['', 'a', 'b'] |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
130 digits = 7 |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
131 base = len(charset) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
132 teststrings = set() |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
133 for i in xrange(base ** digits): |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
134 entry = [] |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
135 for j in xrange(digits): |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
136 i, m = divmod(i, base) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
137 entry.append(charset[m]) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
138 teststrings.add(''.join(entry)) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
139 teststrings = list(teststrings) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
140 for i in teststrings: |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
141 i = self.fixtype(i) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
142 n = len(i) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
143 for j in teststrings: |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
144 r1 = i.count(j) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
145 if j: |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
146 r2, rem = divmod(n - len(i.replace(j, '')), len(j)) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
147 else: |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
148 r2, rem = len(i)+1, 0 |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
149 if rem or r1 != r2: |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
150 self.assertEqual(rem, 0) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
151 self.assertEqual(r1, r2) |
|
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
152 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
153 def test_find(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
154 self.checkequal(0, 'abcdefghiabc', 'find', 'abc') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
155 self.checkequal(9, 'abcdefghiabc', 'find', 'abc', 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
156 self.checkequal(-1, 'abcdefghiabc', 'find', 'def', 4) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
157 |
|
38514
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38492
diff
changeset
|
158 self.checkequal(0, 'abc', 'find', '', 0) |
|
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38492
diff
changeset
|
159 self.checkequal(3, 'abc', 'find', '', 3) |
|
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38492
diff
changeset
|
160 self.checkequal(-1, 'abc', 'find', '', 4) |
|
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38492
diff
changeset
|
161 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
162 self.checkraises(TypeError, 'hello', 'find') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
163 self.checkraises(TypeError, 'hello', 'find', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
164 |
|
34620
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
165 # For a variety of combinations, |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
166 # verify that str.find() matches __contains__ |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
167 # and that the found substring is really at that location |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
168 charset = ['', 'a', 'b', 'c'] |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
169 digits = 5 |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
170 base = len(charset) |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
171 teststrings = set() |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
172 for i in xrange(base ** digits): |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
173 entry = [] |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
174 for j in xrange(digits): |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
175 i, m = divmod(i, base) |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
176 entry.append(charset[m]) |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
177 teststrings.add(''.join(entry)) |
|
34621
1edea4c2b011
* Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents:
34620
diff
changeset
|
178 teststrings = list(teststrings) |
|
34620
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
179 for i in teststrings: |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
180 i = self.fixtype(i) |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
181 for j in teststrings: |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
182 loc = i.find(j) |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
183 r1 = (loc != -1) |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
184 r2 = j in i |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
185 if r1 != r2: |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
186 self.assertEqual(r1, r2) |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
187 if loc != -1: |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
188 self.assertEqual(i[loc:loc+len(j)], j) |
|
556f6f1056a8
* Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents:
33833
diff
changeset
|
189 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
190 def test_rfind(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
191 self.checkequal(9, 'abcdefghiabc', 'rfind', 'abc') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
192 self.checkequal(12, 'abcdefghiabc', 'rfind', '') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
193 self.checkequal(0, 'abcdefghiabc', 'rfind', 'abcd') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
194 self.checkequal(-1, 'abcdefghiabc', 'rfind', 'abcz') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
195 |
|
38514
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38492
diff
changeset
|
196 self.checkequal(3, 'abc', 'rfind', '', 0) |
|
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38492
diff
changeset
|
197 self.checkequal(3, 'abc', 'rfind', '', 3) |
|
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38492
diff
changeset
|
198 self.checkequal(-1, 'abc', 'rfind', '', 4) |
|
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38492
diff
changeset
|
199 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
200 self.checkraises(TypeError, 'hello', 'rfind') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
201 self.checkraises(TypeError, 'hello', 'rfind', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
202 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
203 def test_index(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
204 self.checkequal(0, 'abcdefghiabc', 'index', '') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
205 self.checkequal(3, 'abcdefghiabc', 'index', 'def') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
206 self.checkequal(0, 'abcdefghiabc', 'index', 'abc') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
207 self.checkequal(9, 'abcdefghiabc', 'index', 'abc', 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
208 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
209 self.checkraises(ValueError, 'abcdefghiabc', 'index', 'hib') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
210 self.checkraises(ValueError, 'abcdefghiab', 'index', 'abc', 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
211 self.checkraises(ValueError, 'abcdefghi', 'index', 'ghi', 8) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
212 self.checkraises(ValueError, 'abcdefghi', 'index', 'ghi', -1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
213 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
214 self.checkraises(TypeError, 'hello', 'index') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
215 self.checkraises(TypeError, 'hello', 'index', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
216 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
217 def test_rindex(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
218 self.checkequal(12, 'abcdefghiabc', 'rindex', '') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
219 self.checkequal(3, 'abcdefghiabc', 'rindex', 'def') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
220 self.checkequal(9, 'abcdefghiabc', 'rindex', 'abc') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
221 self.checkequal(0, 'abcdefghiabc', 'rindex', 'abc', 0, -1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
222 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
223 self.checkraises(ValueError, 'abcdefghiabc', 'rindex', 'hib') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
224 self.checkraises(ValueError, 'defghiabc', 'rindex', 'def', 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
225 self.checkraises(ValueError, 'defghiabc', 'rindex', 'abc', 0, -1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
226 self.checkraises(ValueError, 'abcdefghi', 'rindex', 'ghi', 0, 8) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
227 self.checkraises(ValueError, 'abcdefghi', 'rindex', 'ghi', 0, -1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
228 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
229 self.checkraises(TypeError, 'hello', 'rindex') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
230 self.checkraises(TypeError, 'hello', 'rindex', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
231 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
232 def test_lower(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
233 self.checkequal('hello', 'HeLLo', 'lower') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
234 self.checkequal('hello', 'hello', 'lower') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
235 self.checkraises(TypeError, 'hello', 'lower', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
236 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
237 def test_upper(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
238 self.checkequal('HELLO', 'HeLLo', 'upper') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
239 self.checkequal('HELLO', 'HELLO', 'upper') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
240 self.checkraises(TypeError, 'hello', 'upper', 42) |
|
13517
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
241 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
242 def test_expandtabs(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
243 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
244 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
245 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 4) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
246 self.checkequal('abc\r\nab def\ng hi', 'abc\r\nab\tdef\ng\thi', 'expandtabs', 4) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
247 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
248 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
249 self.checkequal('abc\r\nab\r\ndef\ng\r\nhi', 'abc\r\nab\r\ndef\ng\r\nhi', 'expandtabs', 4) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
250 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
251 self.checkraises(TypeError, 'hello', 'expandtabs', 42, 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
252 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
253 def test_split(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
254 self.checkequal(['this', 'is', 'the', 'split', 'function'], |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
255 'this is the split function', 'split') |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
256 |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
257 # by whitespace |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
258 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d ', 'split') |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
259 self.checkequal(['a', 'b c d'], 'a b c d', 'split', None, 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
260 self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', None, 2) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
261 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None, 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
262 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None, 4) |
| 38356 | 263 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None, |
| 264 sys.maxint-1) | |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
265 self.checkequal(['a b c d'], 'a b c d', 'split', None, 0) |
|
38373
4bfeab230e38
Test for more edge strip cases; leading and trailing separator gets removed
Andrew Dalke <dalke@dalkescientific.com>
parents:
38361
diff
changeset
|
266 self.checkequal(['a b c d'], ' a b c d', 'split', None, 0) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
267 self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', None, 2) |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
268 |
|
38340
8a99cdef0c94
Added a few more test cases for whitespace split. These strings have leading whitespace.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38335
diff
changeset
|
269 self.checkequal([], ' ', 'split') |
|
8a99cdef0c94
Added a few more test cases for whitespace split. These strings have leading whitespace.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38335
diff
changeset
|
270 self.checkequal(['a'], ' a ', 'split') |
|
8a99cdef0c94
Added a few more test cases for whitespace split. These strings have leading whitespace.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38335
diff
changeset
|
271 self.checkequal(['a', 'b'], ' a b ', 'split') |
|
8a99cdef0c94
Added a few more test cases for whitespace split. These strings have leading whitespace.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38335
diff
changeset
|
272 self.checkequal(['a', 'b '], ' a b ', 'split', None, 1) |
|
8a99cdef0c94
Added a few more test cases for whitespace split. These strings have leading whitespace.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38335
diff
changeset
|
273 self.checkequal(['a', 'b c '], ' a b c ', 'split', None, 1) |
|
8a99cdef0c94
Added a few more test cases for whitespace split. These strings have leading whitespace.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38335
diff
changeset
|
274 self.checkequal(['a', 'b', 'c '], ' a b c ', 'split', None, 2) |
|
38342
5382aaf3a0da
Added split whitespace checks for characters other than space.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38340
diff
changeset
|
275 self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'split') |
| 38356 | 276 aaa = ' a '*20 |
| 277 self.checkequal(['a']*20, aaa, 'split') | |
| 278 self.checkequal(['a'] + [aaa[4:]], aaa, 'split', None, 1) | |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
279 self.checkequal(['a']*19 + ['a '], aaa, 'split', None, 19) |
|
38340
8a99cdef0c94
Added a few more test cases for whitespace split. These strings have leading whitespace.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38335
diff
changeset
|
280 |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
281 # by a char |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
282 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|') |
| 38356 | 283 self.checkequal(['a|b|c|d'], 'a|b|c|d', 'split', '|', 0) |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
284 self.checkequal(['a', 'b|c|d'], 'a|b|c|d', 'split', '|', 1) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
285 self.checkequal(['a', 'b', 'c|d'], 'a|b|c|d', 'split', '|', 2) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
286 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|', 3) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
287 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|', 4) |
| 38356 | 288 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|', |
| 289 sys.maxint-2) | |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
290 self.checkequal(['a|b|c|d'], 'a|b|c|d', 'split', '|', 0) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
291 self.checkequal(['a', '', 'b||c||d'], 'a||b||c||d', 'split', '|', 2) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
292 self.checkequal(['endcase ', ''], 'endcase |', 'split', '|') |
| 38356 | 293 self.checkequal(['', ' startcase'], '| startcase', 'split', '|') |
| 294 self.checkequal(['', 'bothcase', ''], '|bothcase|', 'split', '|') | |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
295 self.checkequal(['a', '', 'b\x00c\x00d'], 'a\x00\x00b\x00c\x00d', 'split', '\x00', 2) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
296 |
| 38356 | 297 self.checkequal(['a']*20, ('a|'*20)[:-1], 'split', '|') |
| 298 self.checkequal(['a']*15 +['a|a|a|a|a'], | |
| 299 ('a|'*20)[:-1], 'split', '|', 15) | |
| 300 | |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
301 # by string |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
302 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//') |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
303 self.checkequal(['a', 'b//c//d'], 'a//b//c//d', 'split', '//', 1) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
304 self.checkequal(['a', 'b', 'c//d'], 'a//b//c//d', 'split', '//', 2) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
305 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//', 3) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
306 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//', 4) |
| 38356 | 307 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//', |
| 308 sys.maxint-10) | |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
309 self.checkequal(['a//b//c//d'], 'a//b//c//d', 'split', '//', 0) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
310 self.checkequal(['a', '', 'b////c////d'], 'a////b////c////d', 'split', '//', 2) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
311 self.checkequal(['endcase ', ''], 'endcase test', 'split', 'test') |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
312 self.checkequal(['', ' begincase'], 'test begincase', 'split', 'test') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
313 self.checkequal(['', ' bothcase ', ''], 'test bothcase test', |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
314 'split', 'test') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
315 self.checkequal(['a', 'bc'], 'abbbc', 'split', 'bb') |
| 38356 | 316 self.checkequal(['', ''], 'aaa', 'split', 'aaa') |
| 317 self.checkequal(['aaa'], 'aaa', 'split', 'aaa', 0) | |
| 318 self.checkequal(['ab', 'ab'], 'abbaab', 'split', 'ba') | |
| 319 self.checkequal(['aaaa'], 'aaaa', 'split', 'aab') | |
| 320 self.checkequal([''], '', 'split', 'aaa') | |
| 321 self.checkequal(['aa'], 'aa', 'split', 'aaa') | |
|
38357
be7415b0a318
Test cases for off-by-one errors in string split with multicharacter pattern.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38356
diff
changeset
|
322 self.checkequal(['A', 'bobb'], 'Abbobbbobb', 'split', 'bbobb') |
|
be7415b0a318
Test cases for off-by-one errors in string split with multicharacter pattern.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38356
diff
changeset
|
323 self.checkequal(['A', 'B', ''], 'AbbobbBbbobb', 'split', 'bbobb') |
| 38356 | 324 |
| 325 self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'split', 'BLAH') | |
| 326 self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'split', 'BLAH', 19) | |
| 327 self.checkequal(['a']*18 + ['aBLAHa'], ('aBLAH'*20)[:-4], | |
| 328 'split', 'BLAH', 18) | |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
329 |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
330 # mixed use of str and unicode |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
331 self.checkequal([u'a', u'b', u'c d'], 'a b c d', 'split', u' ', 2) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
332 |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
333 # argument type |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
334 self.checkraises(TypeError, 'hello', 'split', 42, 42, 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
335 |
| 38356 | 336 # null case |
| 337 self.checkraises(ValueError, 'hello', 'split', '') | |
| 338 self.checkraises(ValueError, 'hello', 'split', '', 0) | |
| 339 | |
|
31199
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
340 def test_rsplit(self): |
|
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
341 self.checkequal(['this', 'is', 'the', 'rsplit', 'function'], |
|
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
342 'this is the rsplit function', 'rsplit') |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
343 |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
344 # by whitespace |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
345 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d ', 'rsplit') |
|
31199
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
346 self.checkequal(['a b c', 'd'], 'a b c d', 'rsplit', None, 1) |
|
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
347 self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', None, 2) |
|
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
348 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None, 3) |
|
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
349 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None, 4) |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
350 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None, |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
351 sys.maxint-20) |
|
31199
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
352 self.checkequal(['a b c d'], 'a b c d', 'rsplit', None, 0) |
|
38373
4bfeab230e38
Test for more edge strip cases; leading and trailing separator gets removed
Andrew Dalke <dalke@dalkescientific.com>
parents:
38361
diff
changeset
|
353 self.checkequal(['a b c d'], 'a b c d ', 'rsplit', None, 0) |
|
31199
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
354 self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', None, 2) |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
355 |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
356 self.checkequal([], ' ', 'rsplit') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
357 self.checkequal(['a'], ' a ', 'rsplit') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
358 self.checkequal(['a', 'b'], ' a b ', 'rsplit') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
359 self.checkequal([' a', 'b'], ' a b ', 'rsplit', None, 1) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
360 self.checkequal([' a b','c'], ' a b c ', 'rsplit', |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
361 None, 1) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
362 self.checkequal([' a', 'b', 'c'], ' a b c ', 'rsplit', |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
363 None, 2) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
364 self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'rsplit', None, 88) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
365 aaa = ' a '*20 |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
366 self.checkequal(['a']*20, aaa, 'rsplit') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
367 self.checkequal([aaa[:-4]] + ['a'], aaa, 'rsplit', None, 1) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
368 self.checkequal([' a a'] + ['a']*18, aaa, 'rsplit', None, 18) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
369 |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
370 |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
371 # by a char |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
372 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|') |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
373 self.checkequal(['a|b|c', 'd'], 'a|b|c|d', 'rsplit', '|', 1) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
374 self.checkequal(['a|b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', 2) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
375 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', 3) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
376 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', 4) |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
377 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
378 sys.maxint-100) |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
379 self.checkequal(['a|b|c|d'], 'a|b|c|d', 'rsplit', '|', 0) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
380 self.checkequal(['a||b||c', '', 'd'], 'a||b||c||d', 'rsplit', '|', 2) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
381 self.checkequal(['', ' begincase'], '| begincase', 'rsplit', '|') |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
382 self.checkequal(['endcase ', ''], 'endcase |', 'rsplit', '|') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
383 self.checkequal(['', 'bothcase', ''], '|bothcase|', 'rsplit', '|') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
384 |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
385 self.checkequal(['a\x00\x00b', 'c', 'd'], 'a\x00\x00b\x00c\x00d', 'rsplit', '\x00', 2) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
386 |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
387 self.checkequal(['a']*20, ('a|'*20)[:-1], 'rsplit', '|') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
388 self.checkequal(['a|a|a|a|a']+['a']*15, |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
389 ('a|'*20)[:-1], 'rsplit', '|', 15) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
390 |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
391 # by string |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
392 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//') |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
393 self.checkequal(['a//b//c', 'd'], 'a//b//c//d', 'rsplit', '//', 1) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
394 self.checkequal(['a//b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', 2) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
395 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', 3) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
396 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', 4) |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
397 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
398 sys.maxint-5) |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
399 self.checkequal(['a//b//c//d'], 'a//b//c//d', 'rsplit', '//', 0) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
400 self.checkequal(['a////b////c', '', 'd'], 'a////b////c////d', 'rsplit', '//', 2) |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
401 self.checkequal(['', ' begincase'], 'test begincase', 'rsplit', 'test') |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
402 self.checkequal(['endcase ', ''], 'endcase test', 'rsplit', 'test') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
403 self.checkequal(['', ' bothcase ', ''], 'test bothcase test', |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
404 'rsplit', 'test') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
405 self.checkequal(['ab', 'c'], 'abbbc', 'rsplit', 'bb') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
406 self.checkequal(['', ''], 'aaa', 'rsplit', 'aaa') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
407 self.checkequal(['aaa'], 'aaa', 'rsplit', 'aaa', 0) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
408 self.checkequal(['ab', 'ab'], 'abbaab', 'rsplit', 'ba') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
409 self.checkequal(['aaaa'], 'aaaa', 'rsplit', 'aab') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
410 self.checkequal([''], '', 'rsplit', 'aaa') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
411 self.checkequal(['aa'], 'aa', 'rsplit', 'aaa') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
412 self.checkequal(['bbob', 'A'], 'bbobbbobbA', 'rsplit', 'bbobb') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
413 self.checkequal(['', 'B', 'A'], 'bbobbBbbobbA', 'rsplit', 'bbobb') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
414 |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
415 self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'rsplit', 'BLAH') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
416 self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'rsplit', 'BLAH', 19) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
417 self.checkequal(['aBLAHa'] + ['a']*18, ('aBLAH'*20)[:-4], |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
418 'rsplit', 'BLAH', 18) |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
419 |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
420 # mixed use of str and unicode |
|
31199
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
421 self.checkequal([u'a b', u'c', u'd'], 'a b c d', 'rsplit', u' ', 2) |
|
31350
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
422 |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
423 # argument type |
|
eaa1a4b74328
[SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31252
diff
changeset
|
424 self.checkraises(TypeError, 'hello', 'rsplit', 42, 42, 42) |
|
31199
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31021
diff
changeset
|
425 |
|
38361
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
426 # null case |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
427 self.checkraises(ValueError, 'hello', 'rsplit', '') |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
428 self.checkraises(ValueError, 'hello', 'rsplit', '', 0) |
|
6533d8ae1fd9
Added more rstrip tests, including for prealloc'ed arrays
Andrew Dalke <dalke@dalkescientific.com>
parents:
38357
diff
changeset
|
429 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
430 def test_strip(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
431 self.checkequal('hello', ' hello ', 'strip') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
432 self.checkequal('hello ', ' hello ', 'lstrip') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
433 self.checkequal(' hello', ' hello ', 'rstrip') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
434 self.checkequal('hello', 'hello', 'strip') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
435 |
|
28575
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
436 # strip/lstrip/rstrip with None arg |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
437 self.checkequal('hello', ' hello ', 'strip', None) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
438 self.checkequal('hello ', ' hello ', 'lstrip', None) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
439 self.checkequal(' hello', ' hello ', 'rstrip', None) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
440 self.checkequal('hello', 'hello', 'strip', None) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
441 |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
442 # strip/lstrip/rstrip with str arg |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
443 self.checkequal('hello', 'xyzzyhelloxyzzy', 'strip', 'xyz') |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
444 self.checkequal('helloxyzzy', 'xyzzyhelloxyzzy', 'lstrip', 'xyz') |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
445 self.checkequal('xyzzyhello', 'xyzzyhelloxyzzy', 'rstrip', 'xyz') |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
446 self.checkequal('hello', 'hello', 'strip', 'xyz') |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
447 |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
448 # strip/lstrip/rstrip with unicode arg |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
449 if test_support.have_unicode: |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
450 self.checkequal(unicode('hello', 'ascii'), 'xyzzyhelloxyzzy', |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
451 'strip', unicode('xyz', 'ascii')) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
452 self.checkequal(unicode('helloxyzzy', 'ascii'), 'xyzzyhelloxyzzy', |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
453 'lstrip', unicode('xyz', 'ascii')) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
454 self.checkequal(unicode('xyzzyhello', 'ascii'), 'xyzzyhelloxyzzy', |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
455 'rstrip', unicode('xyz', 'ascii')) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
456 self.checkequal(unicode('hello', 'ascii'), 'hello', |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
457 'strip', unicode('xyz', 'ascii')) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
458 |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
459 self.checkraises(TypeError, 'hello', 'strip', 42, 42) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
460 self.checkraises(TypeError, 'hello', 'lstrip', 42, 42) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
461 self.checkraises(TypeError, 'hello', 'rstrip', 42, 42) |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28478
diff
changeset
|
462 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
463 def test_ljust(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
464 self.checkequal('abc ', 'abc', 'ljust', 10) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
465 self.checkequal('abc ', 'abc', 'ljust', 6) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
466 self.checkequal('abc', 'abc', 'ljust', 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
467 self.checkequal('abc', 'abc', 'ljust', 2) |
|
31021
21a10c3600b5
Add optional fillchar argument to ljust(), rjust(), and center() string methods.
Raymond Hettinger <python@rcn.com>
parents:
30216
diff
changeset
|
468 self.checkequal('abc*******', 'abc', 'ljust', 10, '*') |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
469 self.checkraises(TypeError, 'abc', 'ljust') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
470 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
471 def test_rjust(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
472 self.checkequal(' abc', 'abc', 'rjust', 10) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
473 self.checkequal(' abc', 'abc', 'rjust', 6) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
474 self.checkequal('abc', 'abc', 'rjust', 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
475 self.checkequal('abc', 'abc', 'rjust', 2) |
|
31021
21a10c3600b5
Add optional fillchar argument to ljust(), rjust(), and center() string methods.
Raymond Hettinger <python@rcn.com>
parents:
30216
diff
changeset
|
476 self.checkequal('*******abc', 'abc', 'rjust', 10, '*') |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
477 self.checkraises(TypeError, 'abc', 'rjust') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
478 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
479 def test_center(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
480 self.checkequal(' abc ', 'abc', 'center', 10) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
481 self.checkequal(' abc ', 'abc', 'center', 6) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
482 self.checkequal('abc', 'abc', 'center', 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
483 self.checkequal('abc', 'abc', 'center', 2) |
|
31021
21a10c3600b5
Add optional fillchar argument to ljust(), rjust(), and center() string methods.
Raymond Hettinger <python@rcn.com>
parents:
30216
diff
changeset
|
484 self.checkequal('***abc****', 'abc', 'center', 10, '*') |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
485 self.checkraises(TypeError, 'abc', 'center') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
486 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
487 def test_swapcase(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
488 self.checkequal('hEllO CoMPuTErS', 'HeLLo cOmpUteRs', 'swapcase') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
489 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
490 self.checkraises(TypeError, 'hello', 'swapcase', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
491 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
492 def test_replace(self): |
|
38279
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
493 EQ = self.checkequal |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
494 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
495 # Operations on the empty string |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
496 EQ("", "", "replace", "", "") |
|
38539
b9b036f02207
Re-enable a new empty-string test added during the NFS sprint,
Tim Peters <tim.peters@gmail.com>
parents:
38516
diff
changeset
|
497 EQ("A", "", "replace", "", "A") |
|
38279
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
498 EQ("", "", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
499 EQ("", "", "replace", "A", "A") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
500 EQ("", "", "replace", "", "", 100) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
501 EQ("", "", "replace", "", "", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
502 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
503 # interleave (from=="", 'to' gets inserted everywhere) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
504 EQ("A", "A", "replace", "", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
505 EQ("*A*", "A", "replace", "", "*") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
506 EQ("*1A*1", "A", "replace", "", "*1") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
507 EQ("*-#A*-#", "A", "replace", "", "*-#") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
508 EQ("*-A*-A*-", "AA", "replace", "", "*-") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
509 EQ("*-A*-A*-", "AA", "replace", "", "*-", -1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
510 EQ("*-A*-A*-", "AA", "replace", "", "*-", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
511 EQ("*-A*-A*-", "AA", "replace", "", "*-", 4) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
512 EQ("*-A*-A*-", "AA", "replace", "", "*-", 3) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
513 EQ("*-A*-A", "AA", "replace", "", "*-", 2) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
514 EQ("*-AA", "AA", "replace", "", "*-", 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
515 EQ("AA", "AA", "replace", "", "*-", 0) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
516 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
517 # single character deletion (from=="A", to=="") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
518 EQ("", "A", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
519 EQ("", "AAA", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
520 EQ("", "AAA", "replace", "A", "", -1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
521 EQ("", "AAA", "replace", "A", "", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
522 EQ("", "AAA", "replace", "A", "", 4) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
523 EQ("", "AAA", "replace", "A", "", 3) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
524 EQ("A", "AAA", "replace", "A", "", 2) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
525 EQ("AA", "AAA", "replace", "A", "", 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
526 EQ("AAA", "AAA", "replace", "A", "", 0) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
527 EQ("", "AAAAAAAAAA", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
528 EQ("BCD", "ABACADA", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
529 EQ("BCD", "ABACADA", "replace", "A", "", -1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
530 EQ("BCD", "ABACADA", "replace", "A", "", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
531 EQ("BCD", "ABACADA", "replace", "A", "", 5) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
532 EQ("BCD", "ABACADA", "replace", "A", "", 4) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
533 EQ("BCDA", "ABACADA", "replace", "A", "", 3) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
534 EQ("BCADA", "ABACADA", "replace", "A", "", 2) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
535 EQ("BACADA", "ABACADA", "replace", "A", "", 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
536 EQ("ABACADA", "ABACADA", "replace", "A", "", 0) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
537 EQ("BCD", "ABCAD", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
538 EQ("BCD", "ABCADAA", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
539 EQ("BCD", "BCD", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
540 EQ("*************", "*************", "replace", "A", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
541 EQ("^A^", "^"+"A"*1000+"^", "replace", "A", "", 999) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
542 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
543 # substring deletion (from=="the", to=="") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
544 EQ("", "the", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
545 EQ("ater", "theater", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
546 EQ("", "thethe", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
547 EQ("", "thethethethe", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
548 EQ("aaaa", "theatheatheathea", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
549 EQ("that", "that", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
550 EQ("thaet", "thaet", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
551 EQ("here and re", "here and there", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
552 EQ("here and re and re", "here and there and there", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
553 "replace", "the", "", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
554 EQ("here and re and re", "here and there and there", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
555 "replace", "the", "", -1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
556 EQ("here and re and re", "here and there and there", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
557 "replace", "the", "", 3) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
558 EQ("here and re and re", "here and there and there", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
559 "replace", "the", "", 2) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
560 EQ("here and re and there", "here and there and there", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
561 "replace", "the", "", 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
562 EQ("here and there and there", "here and there and there", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
563 "replace", "the", "", 0) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
564 EQ("here and re and re", "here and there and there", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
565 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
566 EQ("abc", "abc", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
567 EQ("abcdefg", "abcdefg", "replace", "the", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
568 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
569 # substring deletion (from=="bob", to=="") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
570 EQ("bob", "bbobob", "replace", "bob", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
571 EQ("bobXbob", "bbobobXbbobob", "replace", "bob", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
572 EQ("aaaaaaa", "aaaaaaabob", "replace", "bob", "") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
573 EQ("aaaaaaa", "aaaaaaa", "replace", "bob", "") |
|
38280
32ba3a0c6040
We can't leave the checked-in tests broken.
Tim Peters <tim.peters@gmail.com>
parents:
38279
diff
changeset
|
574 |
|
38279
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
575 # single character replace in place (len(from)==len(to)==1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
576 EQ("Who goes there?", "Who goes there?", "replace", "o", "o") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
577 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
578 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
579 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", -1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
580 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", 3) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
581 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", 2) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
582 EQ("WhO goes there?", "Who goes there?", "replace", "o", "O", 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
583 EQ("Who goes there?", "Who goes there?", "replace", "o", "O", 0) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
584 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
585 EQ("Who goes there?", "Who goes there?", "replace", "a", "q") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
586 EQ("who goes there?", "Who goes there?", "replace", "W", "w") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
587 EQ("wwho goes there?ww", "WWho goes there?WW", "replace", "W", "w") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
588 EQ("Who goes there!", "Who goes there?", "replace", "?", "!") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
589 EQ("Who goes there!!", "Who goes there??", "replace", "?", "!") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
590 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
591 EQ("Who goes there?", "Who goes there?", "replace", ".", "!") |
|
38280
32ba3a0c6040
We can't leave the checked-in tests broken.
Tim Peters <tim.peters@gmail.com>
parents:
38279
diff
changeset
|
592 |
|
38279
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
593 # substring replace in place (len(from)==len(to) > 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
594 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
595 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
596 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", -1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
597 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", 4) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
598 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", 3) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
599 EQ("Th** ** a tissue", "This is a tissue", "replace", "is", "**", 2) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
600 EQ("Th** is a tissue", "This is a tissue", "replace", "is", "**", 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
601 EQ("This is a tissue", "This is a tissue", "replace", "is", "**", 0) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
602 EQ("cobob", "bobob", "replace", "bob", "cob") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
603 EQ("cobobXcobocob", "bobobXbobobob", "replace", "bob", "cob") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
604 EQ("bobob", "bobob", "replace", "bot", "bot") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
605 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
606 # replace single character (len(from)==1, len(to)>1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
607 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
608 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", -1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
609 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
610 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", 2) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
611 EQ("ReyKKjavik", "Reykjavik", "replace", "k", "KK", 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
612 EQ("Reykjavik", "Reykjavik", "replace", "k", "KK", 0) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
613 EQ("A----B----C----", "A.B.C.", "replace", ".", "----") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
614 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
615 EQ("Reykjavik", "Reykjavik", "replace", "q", "KK") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
616 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
617 # replace substring (len(from)>1, len(to)!=len(from)) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
618 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
619 "replace", "spam", "ham") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
620 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
621 "replace", "spam", "ham", sys.maxint) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
622 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
623 "replace", "spam", "ham", -1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
624 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
625 "replace", "spam", "ham", 4) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
626 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
627 "replace", "spam", "ham", 3) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
628 EQ("ham, ham, eggs and spam", "spam, spam, eggs and spam", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
629 "replace", "spam", "ham", 2) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
630 EQ("ham, spam, eggs and spam", "spam, spam, eggs and spam", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
631 "replace", "spam", "ham", 1) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
632 EQ("spam, spam, eggs and spam", "spam, spam, eggs and spam", |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
633 "replace", "spam", "ham", 0) |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
634 |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
635 EQ("bobob", "bobobob", "replace", "bobob", "bob") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
636 EQ("bobobXbobob", "bobobobXbobobob", "replace", "bobob", "bob") |
|
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
637 EQ("BOBOBOB", "BOBOBOB", "replace", "bob", "bobby") |
|
38280
32ba3a0c6040
We can't leave the checked-in tests broken.
Tim Peters <tim.peters@gmail.com>
parents:
38279
diff
changeset
|
638 |
|
32ba3a0c6040
We can't leave the checked-in tests broken.
Tim Peters <tim.peters@gmail.com>
parents:
38279
diff
changeset
|
639 # |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
640 self.checkequal('one@two!three!', 'one!two!three!', 'replace', '!', '@', 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
641 self.checkequal('onetwothree', 'one!two!three!', 'replace', '!', '') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
642 self.checkequal('one@two@three!', 'one!two!three!', 'replace', '!', '@', 2) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
643 self.checkequal('one@two@three@', 'one!two!three!', 'replace', '!', '@', 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
644 self.checkequal('one@two@three@', 'one!two!three!', 'replace', '!', '@', 4) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
645 self.checkequal('one!two!three!', 'one!two!three!', 'replace', '!', '@', 0) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
646 self.checkequal('one@two@three@', 'one!two!three!', 'replace', '!', '@') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
647 self.checkequal('one!two!three!', 'one!two!three!', 'replace', 'x', '@') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
648 self.checkequal('one!two!three!', 'one!two!three!', 'replace', 'x', '@', 2) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
649 self.checkequal('-a-b-c-', 'abc', 'replace', '', '-') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
650 self.checkequal('-a-b-c', 'abc', 'replace', '', '-', 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
651 self.checkequal('abc', 'abc', 'replace', '', '-', 0) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
652 self.checkequal('', '', 'replace', '', '') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
653 self.checkequal('abc', 'abc', 'replace', 'ab', '--', 0) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
654 self.checkequal('abc', 'abc', 'replace', 'xy', '--') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
655 # Next three for SF bug 422088: [OSF1 alpha] string.replace(); died with |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
656 # MemoryError due to empty result (platform malloc issue when requesting |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
657 # 0 bytes). |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
658 self.checkequal('', '123', 'replace', '123', '') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
659 self.checkequal('', '123123', 'replace', '123', '') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
660 self.checkequal('x', '123x123', 'replace', '123', '') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
661 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
662 self.checkraises(TypeError, 'hello', 'replace') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
663 self.checkraises(TypeError, 'hello', 'replace', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
664 self.checkraises(TypeError, 'hello', 'replace', 42, 'h') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
665 self.checkraises(TypeError, 'hello', 'replace', 'h', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
666 |
|
38299
ae6bbf2f2a41
needforspeed: check for overflow in replace (from Andrew Dalke)
Fredrik Lundh <fredrik@pythonware.com>
parents:
38296
diff
changeset
|
667 def test_replace_overflow(self): |
|
ae6bbf2f2a41
needforspeed: check for overflow in replace (from Andrew Dalke)
Fredrik Lundh <fredrik@pythonware.com>
parents:
38296
diff
changeset
|
668 # Check for overflow checking on 32 bit machines |
|
ae6bbf2f2a41
needforspeed: check for overflow in replace (from Andrew Dalke)
Fredrik Lundh <fredrik@pythonware.com>
parents:
38296
diff
changeset
|
669 if sys.maxint != 2147483647: |
|
ae6bbf2f2a41
needforspeed: check for overflow in replace (from Andrew Dalke)
Fredrik Lundh <fredrik@pythonware.com>
parents:
38296
diff
changeset
|
670 return |
|
ae6bbf2f2a41
needforspeed: check for overflow in replace (from Andrew Dalke)
Fredrik Lundh <fredrik@pythonware.com>
parents:
38296
diff
changeset
|
671 A2_16 = "A" * (2**16) |
|
ae6bbf2f2a41
needforspeed: check for overflow in replace (from Andrew Dalke)
Fredrik Lundh <fredrik@pythonware.com>
parents:
38296
diff
changeset
|
672 self.checkraises(OverflowError, A2_16, "replace", "", A2_16) |
|
ae6bbf2f2a41
needforspeed: check for overflow in replace (from Andrew Dalke)
Fredrik Lundh <fredrik@pythonware.com>
parents:
38296
diff
changeset
|
673 self.checkraises(OverflowError, A2_16, "replace", "A", A2_16) |
|
ae6bbf2f2a41
needforspeed: check for overflow in replace (from Andrew Dalke)
Fredrik Lundh <fredrik@pythonware.com>
parents:
38296
diff
changeset
|
674 self.checkraises(OverflowError, A2_16, "replace", "AA", A2_16+A2_16) |
|
38279
6860c36f7db7
Added a slew of test for string replace, based various corner cases from
Andrew Dalke <dalke@dalkescientific.com>
parents:
36501
diff
changeset
|
675 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
676 def test_zfill(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
677 self.checkequal('123', '123', 'zfill', 2) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
678 self.checkequal('123', '123', 'zfill', 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
679 self.checkequal('0123', '123', 'zfill', 4) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
680 self.checkequal('+123', '+123', 'zfill', 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
681 self.checkequal('+123', '+123', 'zfill', 4) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
682 self.checkequal('+0123', '+123', 'zfill', 5) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
683 self.checkequal('-123', '-123', 'zfill', 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
684 self.checkequal('-123', '-123', 'zfill', 4) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
685 self.checkequal('-0123', '-123', 'zfill', 5) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
686 self.checkequal('000', '', 'zfill', 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
687 self.checkequal('34', '34', 'zfill', 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
688 self.checkequal('0034', '34', 'zfill', 4) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
689 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
690 self.checkraises(TypeError, '123', 'zfill') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
691 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
692 class MixinStrUnicodeUserStringTest: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
693 # additional tests that only work for |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
694 # stringlike objects, i.e. str, unicode, UserString |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
695 # (but not the string module) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
696 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
697 def test_islower(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
698 self.checkequal(False, '', 'islower') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
699 self.checkequal(True, 'a', 'islower') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
700 self.checkequal(False, 'A', 'islower') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
701 self.checkequal(False, '\n', 'islower') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
702 self.checkequal(True, 'abc', 'islower') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
703 self.checkequal(False, 'aBc', 'islower') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
704 self.checkequal(True, 'abc\n', 'islower') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
705 self.checkraises(TypeError, 'abc', 'islower', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
706 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
707 def test_isupper(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
708 self.checkequal(False, '', 'isupper') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
709 self.checkequal(False, 'a', 'isupper') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
710 self.checkequal(True, 'A', 'isupper') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
711 self.checkequal(False, '\n', 'isupper') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
712 self.checkequal(True, 'ABC', 'isupper') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
713 self.checkequal(False, 'AbC', 'isupper') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
714 self.checkequal(True, 'ABC\n', 'isupper') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
715 self.checkraises(TypeError, 'abc', 'isupper', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
716 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
717 def test_istitle(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
718 self.checkequal(False, '', 'istitle') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
719 self.checkequal(False, 'a', 'istitle') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
720 self.checkequal(True, 'A', 'istitle') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
721 self.checkequal(False, '\n', 'istitle') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
722 self.checkequal(True, 'A Titlecased Line', 'istitle') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
723 self.checkequal(True, 'A\nTitlecased Line', 'istitle') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
724 self.checkequal(True, 'A Titlecased, Line', 'istitle') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
725 self.checkequal(False, 'Not a capitalized String', 'istitle') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
726 self.checkequal(False, 'Not\ta Titlecase String', 'istitle') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
727 self.checkequal(False, 'Not--a Titlecase String', 'istitle') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
728 self.checkequal(False, 'NOT', 'istitle') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
729 self.checkraises(TypeError, 'abc', 'istitle', 42) |
|
13517
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
730 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
731 def test_isspace(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
732 self.checkequal(False, '', 'isspace') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
733 self.checkequal(False, 'a', 'isspace') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
734 self.checkequal(True, ' ', 'isspace') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
735 self.checkequal(True, '\t', 'isspace') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
736 self.checkequal(True, '\r', 'isspace') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
737 self.checkequal(True, '\n', 'isspace') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
738 self.checkequal(True, ' \t\r\n', 'isspace') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
739 self.checkequal(False, ' \t\r\na', 'isspace') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
740 self.checkraises(TypeError, 'abc', 'isspace', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
741 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
742 def test_isalpha(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
743 self.checkequal(False, '', 'isalpha') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
744 self.checkequal(True, 'a', 'isalpha') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
745 self.checkequal(True, 'A', 'isalpha') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
746 self.checkequal(False, '\n', 'isalpha') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
747 self.checkequal(True, 'abc', 'isalpha') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
748 self.checkequal(False, 'aBc123', 'isalpha') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
749 self.checkequal(False, 'abc\n', 'isalpha') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
750 self.checkraises(TypeError, 'abc', 'isalpha', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
751 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
752 def test_isalnum(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
753 self.checkequal(False, '', 'isalnum') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
754 self.checkequal(True, 'a', 'isalnum') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
755 self.checkequal(True, 'A', 'isalnum') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
756 self.checkequal(False, '\n', 'isalnum') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
757 self.checkequal(True, '123abc456', 'isalnum') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
758 self.checkequal(True, 'a1b3c', 'isalnum') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
759 self.checkequal(False, 'aBc000 ', 'isalnum') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
760 self.checkequal(False, 'abc\n', 'isalnum') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
761 self.checkraises(TypeError, 'abc', 'isalnum', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
762 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
763 def test_isdigit(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
764 self.checkequal(False, '', 'isdigit') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
765 self.checkequal(False, 'a', 'isdigit') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
766 self.checkequal(True, '0', 'isdigit') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
767 self.checkequal(True, '0123456789', 'isdigit') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
768 self.checkequal(False, '0123456789a', 'isdigit') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
769 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
770 self.checkraises(TypeError, 'abc', 'isdigit', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
771 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
772 def test_title(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
773 self.checkequal(' Hello ', ' hello ', 'title') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
774 self.checkequal('Hello ', 'hello ', 'title') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
775 self.checkequal('Hello ', 'Hello ', 'title') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
776 self.checkequal('Format This As Title String', "fOrMaT thIs aS titLe String", 'title') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
777 self.checkequal('Format,This-As*Title;String', "fOrMaT,thIs-aS*titLe;String", 'title', ) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
778 self.checkequal('Getint', "getInt", 'title') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
779 self.checkraises(TypeError, 'hello', 'title', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
780 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
781 def test_splitlines(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
782 self.checkequal(['abc', 'def', '', 'ghi'], "abc\ndef\n\rghi", 'splitlines') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
783 self.checkequal(['abc', 'def', '', 'ghi'], "abc\ndef\n\r\nghi", 'splitlines') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
784 self.checkequal(['abc', 'def', 'ghi'], "abc\ndef\r\nghi", 'splitlines') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
785 self.checkequal(['abc', 'def', 'ghi'], "abc\ndef\r\nghi\n", 'splitlines') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
786 self.checkequal(['abc', 'def', 'ghi', ''], "abc\ndef\r\nghi\n\r", 'splitlines') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
787 self.checkequal(['', 'abc', 'def', 'ghi', ''], "\nabc\ndef\r\nghi\n\r", 'splitlines') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
788 self.checkequal(['\n', 'abc\n', 'def\r\n', 'ghi\n', '\r'], "\nabc\ndef\r\nghi\n\r", 'splitlines', 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
789 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
790 self.checkraises(TypeError, 'abc', 'splitlines', 42, 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
791 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
792 def test_startswith(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
793 self.checkequal(True, 'hello', 'startswith', 'he') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
794 self.checkequal(True, 'hello', 'startswith', 'hello') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
795 self.checkequal(False, 'hello', 'startswith', 'hello world') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
796 self.checkequal(True, 'hello', 'startswith', '') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
797 self.checkequal(False, 'hello', 'startswith', 'ello') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
798 self.checkequal(True, 'hello', 'startswith', 'ello', 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
799 self.checkequal(True, 'hello', 'startswith', 'o', 4) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
800 self.checkequal(False, 'hello', 'startswith', 'o', 5) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
801 self.checkequal(True, 'hello', 'startswith', '', 5) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
802 self.checkequal(False, 'hello', 'startswith', 'lo', 6) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
803 self.checkequal(True, 'helloworld', 'startswith', 'lowo', 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
804 self.checkequal(True, 'helloworld', 'startswith', 'lowo', 3, 7) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
805 self.checkequal(False, 'helloworld', 'startswith', 'lowo', 3, 6) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
806 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
807 # test negative indices |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
808 self.checkequal(True, 'hello', 'startswith', 'he', 0, -1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
809 self.checkequal(True, 'hello', 'startswith', 'he', -53, -1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
810 self.checkequal(False, 'hello', 'startswith', 'hello', 0, -1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
811 self.checkequal(False, 'hello', 'startswith', 'hello world', -1, -10) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
812 self.checkequal(False, 'hello', 'startswith', 'ello', -5) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
813 self.checkequal(True, 'hello', 'startswith', 'ello', -4) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
814 self.checkequal(False, 'hello', 'startswith', 'o', -2) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
815 self.checkequal(True, 'hello', 'startswith', 'o', -1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
816 self.checkequal(True, 'hello', 'startswith', '', -3, -3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
817 self.checkequal(False, 'hello', 'startswith', 'lo', -9) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
818 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
819 self.checkraises(TypeError, 'hello', 'startswith') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
820 self.checkraises(TypeError, 'hello', 'startswith', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
821 |
|
38697
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
822 # test tuple arguments |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
823 self.checkequal(True, 'hello', 'startswith', ('he', 'ha')) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
824 self.checkequal(False, 'hello', 'startswith', ('lo', 'llo')) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
825 self.checkequal(True, 'hello', 'startswith', ('hellox', 'hello')) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
826 self.checkequal(False, 'hello', 'startswith', ()) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
827 self.checkequal(True, 'helloworld', 'startswith', ('hellowo', |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
828 'rld', 'lowo'), 3) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
829 self.checkequal(False, 'helloworld', 'startswith', ('hellowo', 'ello', |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
830 'rld'), 3) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
831 self.checkequal(True, 'hello', 'startswith', ('lo', 'he'), 0, -1) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
832 self.checkequal(False, 'hello', 'startswith', ('he', 'hel'), 0, 1) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
833 self.checkequal(True, 'hello', 'startswith', ('he', 'hel'), 0, 2) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
834 |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
835 self.checkraises(TypeError, 'hello', 'startswith', (42,)) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
836 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
837 def test_endswith(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
838 self.checkequal(True, 'hello', 'endswith', 'lo') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
839 self.checkequal(False, 'hello', 'endswith', 'he') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
840 self.checkequal(True, 'hello', 'endswith', '') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
841 self.checkequal(False, 'hello', 'endswith', 'hello world') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
842 self.checkequal(False, 'helloworld', 'endswith', 'worl') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
843 self.checkequal(True, 'helloworld', 'endswith', 'worl', 3, 9) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
844 self.checkequal(True, 'helloworld', 'endswith', 'world', 3, 12) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
845 self.checkequal(True, 'helloworld', 'endswith', 'lowo', 1, 7) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
846 self.checkequal(True, 'helloworld', 'endswith', 'lowo', 2, 7) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
847 self.checkequal(True, 'helloworld', 'endswith', 'lowo', 3, 7) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
848 self.checkequal(False, 'helloworld', 'endswith', 'lowo', 4, 7) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
849 self.checkequal(False, 'helloworld', 'endswith', 'lowo', 3, 8) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
850 self.checkequal(False, 'ab', 'endswith', 'ab', 0, 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
851 self.checkequal(False, 'ab', 'endswith', 'ab', 0, 0) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
852 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
853 # test negative indices |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
854 self.checkequal(True, 'hello', 'endswith', 'lo', -2) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
855 self.checkequal(False, 'hello', 'endswith', 'he', -2) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
856 self.checkequal(True, 'hello', 'endswith', '', -3, -3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
857 self.checkequal(False, 'hello', 'endswith', 'hello world', -10, -2) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
858 self.checkequal(False, 'helloworld', 'endswith', 'worl', -6) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
859 self.checkequal(True, 'helloworld', 'endswith', 'worl', -5, -1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
860 self.checkequal(True, 'helloworld', 'endswith', 'worl', -5, 9) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
861 self.checkequal(True, 'helloworld', 'endswith', 'world', -7, 12) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
862 self.checkequal(True, 'helloworld', 'endswith', 'lowo', -99, -3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
863 self.checkequal(True, 'helloworld', 'endswith', 'lowo', -8, -3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
864 self.checkequal(True, 'helloworld', 'endswith', 'lowo', -7, -3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
865 self.checkequal(False, 'helloworld', 'endswith', 'lowo', 3, -4) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
866 self.checkequal(False, 'helloworld', 'endswith', 'lowo', -8, -2) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
867 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
868 self.checkraises(TypeError, 'hello', 'endswith') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
869 self.checkraises(TypeError, 'hello', 'endswith', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
870 |
|
38697
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
871 # test tuple arguments |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
872 self.checkequal(False, 'hello', 'endswith', ('he', 'ha')) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
873 self.checkequal(True, 'hello', 'endswith', ('lo', 'llo')) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
874 self.checkequal(True, 'hello', 'endswith', ('hellox', 'hello')) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
875 self.checkequal(False, 'hello', 'endswith', ()) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
876 self.checkequal(True, 'helloworld', 'endswith', ('hellowo', |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
877 'rld', 'lowo'), 3) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
878 self.checkequal(False, 'helloworld', 'endswith', ('hellowo', 'ello', |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
879 'rld'), 3, -1) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
880 self.checkequal(True, 'hello', 'endswith', ('hell', 'ell'), 0, -1) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
881 self.checkequal(False, 'hello', 'endswith', ('he', 'hel'), 0, 1) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
882 self.checkequal(True, 'hello', 'endswith', ('he', 'hell'), 0, 4) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
883 |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
884 self.checkraises(TypeError, 'hello', 'endswith', (42,)) |
|
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
885 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
886 def test___contains__(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
887 self.checkequal(True, '', '__contains__', '') # vereq('' in '', True) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
888 self.checkequal(True, 'abc', '__contains__', '') # vereq('' in 'abc', True) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
889 self.checkequal(False, 'abc', '__contains__', '\0') # vereq('\0' in 'abc', False) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
890 self.checkequal(True, '\0abc', '__contains__', '\0') # vereq('\0' in '\0abc', True) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
891 self.checkequal(True, 'abc\0', '__contains__', '\0') # vereq('\0' in 'abc\0', True) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
892 self.checkequal(True, '\0abc', '__contains__', 'a') # vereq('a' in '\0abc', True) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
893 self.checkequal(True, 'asdf', '__contains__', 'asdf') # vereq('asdf' in 'asdf', True) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
894 self.checkequal(False, 'asd', '__contains__', 'asdf') # vereq('asdf' in 'asd', False) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
895 self.checkequal(False, '', '__contains__', 'asdf') # vereq('asdf' in '', False) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
896 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
897 def test_subscript(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
898 self.checkequal(u'a', 'abc', '__getitem__', 0) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
899 self.checkequal(u'c', 'abc', '__getitem__', -1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
900 self.checkequal(u'a', 'abc', '__getitem__', 0L) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
901 self.checkequal(u'abc', 'abc', '__getitem__', slice(0, 3)) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
902 self.checkequal(u'abc', 'abc', '__getitem__', slice(0, 1000)) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
903 self.checkequal(u'a', 'abc', '__getitem__', slice(0, 1)) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
904 self.checkequal(u'', 'abc', '__getitem__', slice(0, 0)) |
|
38697
1cafbcd7f55c
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
Georg Brandl <georg@python.org>
parents:
38539
diff
changeset
|
905 # FIXME What about negative indices? This is handled differently by [] and __getitem__(slice) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
906 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
907 self.checkraises(TypeError, 'abc', '__getitem__', 'def') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
908 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
909 def test_slice(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
910 self.checkequal('abc', 'abc', '__getslice__', 0, 1000) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
911 self.checkequal('abc', 'abc', '__getslice__', 0, 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
912 self.checkequal('ab', 'abc', '__getslice__', 0, 2) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
913 self.checkequal('bc', 'abc', '__getslice__', 1, 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
914 self.checkequal('b', 'abc', '__getslice__', 1, 2) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
915 self.checkequal('', 'abc', '__getslice__', 2, 2) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
916 self.checkequal('', 'abc', '__getslice__', 1000, 1000) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
917 self.checkequal('', 'abc', '__getslice__', 2000, 1000) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
918 self.checkequal('', 'abc', '__getslice__', 2, 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
919 # FIXME What about negative indizes? This is handled differently by [] and __getslice__ |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
920 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
921 self.checkraises(TypeError, 'abc', '__getslice__', 'def') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
922 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
923 def test_mul(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
924 self.checkequal('', 'abc', '__mul__', -1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
925 self.checkequal('', 'abc', '__mul__', 0) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
926 self.checkequal('abc', 'abc', '__mul__', 1) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
927 self.checkequal('abcabcabc', 'abc', '__mul__', 3) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
928 self.checkraises(TypeError, 'abc', '__mul__') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
929 self.checkraises(TypeError, 'abc', '__mul__', '') |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35758
diff
changeset
|
930 # XXX: on a 64-bit system, this doesn't raise an overflow error, |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35758
diff
changeset
|
931 # but either raises a MemoryError, or succeeds (if you have 54TiB) |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35758
diff
changeset
|
932 #self.checkraises(OverflowError, 10000*'abc', '__mul__', 2000000000) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
933 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
934 def test_join(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
935 # join now works with any sequence type |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
936 # moved here, because the argument order is |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
937 # different in string.join (see the test in |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
938 # test.test_string.StringTest.test_join) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
939 self.checkequal('a b c d', ' ', 'join', ['a', 'b', 'c', 'd']) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
940 self.checkequal('abcd', '', 'join', ('a', 'b', 'c', 'd')) |
|
38709
67450db26f81
Apply perky's fix for #1503157: "/".join([u"", u""]) raising OverflowError.
Georg Brandl <georg@python.org>
parents:
38697
diff
changeset
|
941 self.checkequal('bd', '', 'join', ('', 'b', '', 'd')) |
|
67450db26f81
Apply perky's fix for #1503157: "/".join([u"", u""]) raising OverflowError.
Georg Brandl <georg@python.org>
parents:
38697
diff
changeset
|
942 self.checkequal('ac', '', 'join', ('a', '', 'c', '')) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
943 self.checkequal('w x y z', ' ', 'join', Sequence()) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
944 self.checkequal('abc', 'a', 'join', ('abc',)) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
945 self.checkequal('z', 'a', 'join', UserList(['z'])) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
946 if test_support.have_unicode: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
947 self.checkequal(unicode('a.b.c'), unicode('.'), 'join', ['a', 'b', 'c']) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
948 self.checkequal(unicode('a.b.c'), '.', 'join', [unicode('a'), 'b', 'c']) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
949 self.checkequal(unicode('a.b.c'), '.', 'join', ['a', unicode('b'), 'c']) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
950 self.checkequal(unicode('a.b.c'), '.', 'join', ['a', 'b', unicode('c')]) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
951 self.checkraises(TypeError, '.', 'join', ['a', unicode('b'), 3]) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
952 for i in [5, 25, 125]: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
953 self.checkequal(((('a' * i) + '-') * i)[:-1], '-', 'join', |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
954 ['a' * i] * i) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
955 self.checkequal(((('a' * i) + '-') * i)[:-1], '-', 'join', |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
956 ('a' * i,) * i) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
957 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
958 self.checkraises(TypeError, ' ', 'join', BadSeq1()) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
959 self.checkequal('a b c', ' ', 'join', BadSeq2()) |
|
13517
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
960 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
961 self.checkraises(TypeError, ' ', 'join') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
962 self.checkraises(TypeError, ' ', 'join', 7) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
963 self.checkraises(TypeError, ' ', 'join', Sequence([7, 'hello', 123L])) |
| 35758 | 964 try: |
| 965 def f(): | |
| 966 yield 4 + "" | |
| 967 self.fixtype(' ').join(f()) | |
| 968 except TypeError, e: | |
| 969 if '+' not in str(e): | |
| 970 self.fail('join() ate exception message') | |
| 971 else: | |
| 972 self.fail('exception not raised') | |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
973 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
974 def test_formatting(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
975 self.checkequal('+hello+', '+%s+', '__mod__', 'hello') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
976 self.checkequal('+10+', '+%d+', '__mod__', 10) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
977 self.checkequal('a', "%c", '__mod__', "a") |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
978 self.checkequal('a', "%c", '__mod__', "a") |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
979 self.checkequal('"', "%c", '__mod__', 34) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
980 self.checkequal('$', "%c", '__mod__', 36) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
981 self.checkequal('10', "%d", '__mod__', 10) |
|
28478
8802de0da533
Fix PyString_Format() so that '%c' % u'a' returns u'a'
Walter Dörwald <walter@livinglogic.de>
parents:
28407
diff
changeset
|
982 self.checkequal('\x7f', "%c", '__mod__', 0x7f) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
983 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
984 for ordinal in (-100, 0x200000): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
985 # unicode raises ValueError, str raises OverflowError |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
986 self.checkraises((ValueError, OverflowError), '%c', '__mod__', ordinal) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
987 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
988 self.checkequal(' 42', '%3ld', '__mod__', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
989 self.checkequal('0042.00', '%07.2f', '__mod__', 42) |
|
30216
7ab1a41f16da
SF bug #795506: Wrong handling of string format code for float values.
Raymond Hettinger <python@rcn.com>
parents:
28774
diff
changeset
|
990 self.checkequal('0042.00', '%07.2F', '__mod__', 42) |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
991 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
992 self.checkraises(TypeError, 'abc', '__mod__') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
993 self.checkraises(TypeError, '%(foo)s', '__mod__', 42) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
994 self.checkraises(TypeError, '%s%s', '__mod__', (42,)) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
995 self.checkraises(TypeError, '%c', '__mod__', (None,)) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
996 self.checkraises(ValueError, '%(foo', '__mod__', {}) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
997 self.checkraises(TypeError, '%(foo)s %(bar)s', '__mod__', ('foo', 42)) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
998 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
999 # argument names with properly nested brackets are supported |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1000 self.checkequal('bar', '%((foo))s', '__mod__', {'(foo)': 'bar'}) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1001 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1002 # 100 is a magic number in PyUnicode_Format, this forces a resize |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1003 self.checkequal(103*'a'+'x', '%sx', '__mod__', 103*'a') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1004 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1005 self.checkraises(TypeError, '%*s', '__mod__', ('foo', 'bar')) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1006 self.checkraises(TypeError, '%10.*f', '__mod__', ('foo', 42.)) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1007 self.checkraises(ValueError, '%10', '__mod__', (42,)) |
|
13517
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
1008 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1009 def test_floatformatting(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1010 # float formatting |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1011 for prec in xrange(100): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1012 format = '%%.%if' % prec |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1013 value = 0.01 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1014 for x in xrange(60): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1015 value = value * 3.141592655 / 3.0 * 10.0 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1016 # The formatfloat() code in stringobject.c and |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1017 # unicodeobject.c uses a 120 byte buffer and switches from |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1018 # 'f' formatting to 'g' at precision 50, so we expect |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1019 # OverflowErrors for the ranges x < 50 and prec >= 67. |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1020 if x < 50 and prec >= 67: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1021 self.checkraises(OverflowError, format, "__mod__", value) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1022 else: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1023 self.checkcall(format, "__mod__", value) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1024 |
|
38296
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1025 def test_inplace_rewrites(self): |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1026 # Check that strings don't copy and modify cached single-character strings |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1027 self.checkequal('a', 'A', 'lower') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1028 self.checkequal(True, 'A', 'isupper') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1029 self.checkequal('A', 'a', 'upper') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1030 self.checkequal(True, 'a', 'islower') |
|
38327
e9eb526b7111
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
38299
diff
changeset
|
1031 |
|
38296
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1032 self.checkequal('a', 'A', 'replace', 'A', 'a') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1033 self.checkequal(True, 'A', 'isupper') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1034 |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1035 self.checkequal('A', 'a', 'capitalize') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1036 self.checkequal(True, 'a', 'islower') |
|
38327
e9eb526b7111
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
38299
diff
changeset
|
1037 |
|
38296
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1038 self.checkequal('A', 'a', 'swapcase') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1039 self.checkequal(True, 'a', 'islower') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1040 |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1041 self.checkequal('A', 'a', 'title') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1042 self.checkequal(True, 'a', 'islower') |
|
ba713d31d00c
Added tests for implementation error we came up with in the need for speed sprint.
Andrew Dalke <dalke@dalkescientific.com>
parents:
38282
diff
changeset
|
1043 |
|
38335
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1044 def test_partition(self): |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1045 |
|
38391
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1046 self.checkequal(('this is the par', 'ti', 'tion method'), |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1047 'this is the partition method', 'partition', 'ti') |
|
38335
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1048 |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1049 # from raymond's original specification |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1050 S = 'http://www.python.org' |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1051 self.checkequal(('http', '://', 'www.python.org'), S, 'partition', '://') |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1052 self.checkequal(('http://www.python.org', '', ''), S, 'partition', '?') |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1053 self.checkequal(('', 'http://', 'www.python.org'), S, 'partition', 'http://') |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1054 self.checkequal(('http://www.python.', 'org', ''), S, 'partition', 'org') |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1055 |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1056 self.checkraises(ValueError, S, 'partition', '') |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1057 self.checkraises(TypeError, S, 'partition', None) |
|
f9332ad4287a
needforspeed: partition implementation, part two.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38327
diff
changeset
|
1058 |
|
38391
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1059 def test_rpartition(self): |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1060 |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1061 self.checkequal(('this is the rparti', 'ti', 'on method'), |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1062 'this is the rpartition method', 'rpartition', 'ti') |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1063 |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1064 # from raymond's original specification |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1065 S = 'http://www.python.org' |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1066 self.checkequal(('http', '://', 'www.python.org'), S, 'rpartition', '://') |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1067 self.checkequal(('http://www.python.org', '', ''), S, 'rpartition', '?') |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1068 self.checkequal(('', 'http://', 'www.python.org'), S, 'rpartition', 'http://') |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1069 self.checkequal(('http://www.python.', 'org', ''), S, 'rpartition', 'org') |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1070 |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1071 self.checkraises(ValueError, S, 'rpartition', '') |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1072 self.checkraises(TypeError, S, 'rpartition', None) |
|
78771d673b4b
needspeed: rpartition documentation, tests, and a bug fixes.
Fredrik Lundh <fredrik@pythonware.com>
parents:
38373
diff
changeset
|
1073 |
|
33298
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1074 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1075 class MixinStrStringUserStringTest: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1076 # Additional tests for 8bit strings, i.e. str, UserString and |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1077 # the string module |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1078 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1079 def test_maketrans(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1080 self.assertEqual( |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1081 ''.join(map(chr, xrange(256))).replace('abc', 'xyz'), |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1082 string.maketrans('abc', 'xyz') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1083 ) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1084 self.assertRaises(ValueError, string.maketrans, 'abc', 'xyzw') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1085 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1086 def test_translate(self): |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1087 table = string.maketrans('abc', 'xyz') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1088 self.checkequal('xyzxyz', 'xyzabcdef', 'translate', table, 'def') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1089 |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1090 table = string.maketrans('a', 'A') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1091 self.checkequal('Abc', 'abc', 'translate', table) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1092 self.checkequal('xyz', 'xyz', 'translate', table) |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1093 self.checkequal('yz', 'xyz', 'translate', table, 'x') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1094 self.checkraises(ValueError, 'xyz', 'translate', 'too short', 'strip') |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1095 self.checkraises(ValueError, 'xyz', 'translate', 'too short') |
|
13517
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
1096 |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
1097 |
|
28009
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1098 class MixinStrUserStringTest: |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1099 # Additional tests that only work with |
|
fe10ece8ba68
Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents:
26625
diff
changeset
|
1100 # 8bit compatible object, i.e. str and UserString |
|
13517
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
1101 |
|
35287
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1102 if test_support.have_unicode: |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1103 def test_encoding_decoding(self): |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1104 codecs = [('rot13', 'uryyb jbeyq'), |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1105 ('base64', 'aGVsbG8gd29ybGQ=\n'), |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1106 ('hex', '68656c6c6f20776f726c64'), |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1107 ('uu', 'begin 666 <data>\n+:&5L;&\\@=V]R;&0 \n \nend\n')] |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1108 for encoding, data in codecs: |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1109 self.checkequal(data, 'hello world', 'encode', encoding) |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1110 self.checkequal('hello world', data, 'decode', encoding) |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1111 # zlib is optional, so we make the test optional too... |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1112 try: |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1113 import zlib |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1114 except ImportError: |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1115 pass |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1116 else: |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1117 data = 'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x1a\x0b\x04]' |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1118 self.checkequal(data, 'hello world', 'encode', 'zlib') |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1119 self.checkequal('hello world', data, 'decode', 'zlib') |
|
28407
632a6cae0be6
Add two tests for simple error cases.
Walter Dörwald <walter@livinglogic.de>
parents:
28033
diff
changeset
|
1120 |
|
35287
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1121 self.checkraises(TypeError, 'xyz', 'decode', 42) |
|
2feedf850789
Disable encoding/decoding test, if unicode is disabled.
Walter Dörwald <walter@livinglogic.de>
parents:
34621
diff
changeset
|
1122 self.checkraises(TypeError, 'xyz', 'encode', 42) |
|
33298
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1123 |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1124 |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1125 class MixinStrUnicodeTest: |
|
33305
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1126 # Additional tests that only work with str and unicode. |
|
33298
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1127 |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1128 def test_bug1001011(self): |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1129 # Make sure join returns a NEW object for single item sequences |
|
33305
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1130 # involving a subclass. |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1131 # Make sure that it is of the appropriate type. |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1132 # Check the optimisation still occurs for standard objects. |
|
33298
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1133 t = self.type2test |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1134 class subclass(t): |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1135 pass |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1136 s1 = subclass("abcd") |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1137 s2 = t().join([s1]) |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1138 self.assert_(s1 is not s2) |
|
a37ae7dba814
Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents:
32951
diff
changeset
|
1139 self.assert_(type(s2) is t) |
|
33305
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1140 |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1141 s1 = t("abcd") |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1142 s2 = t().join([s1]) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1143 self.assert_(s1 is s2) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1144 |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1145 # Should also test mixed-type join. |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1146 if t is unicode: |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1147 s1 = subclass("abcd") |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1148 s2 = "".join([s1]) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1149 self.assert_(s1 is not s2) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1150 self.assert_(type(s2) is t) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1151 |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1152 s1 = t("abcd") |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1153 s2 = "".join([s1]) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1154 self.assert_(s1 is s2) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1155 |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1156 elif t is str: |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1157 s1 = subclass("abcd") |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1158 s2 = u"".join([s1]) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1159 self.assert_(s1 is not s2) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1160 self.assert_(type(s2) is unicode) # promotes! |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1161 |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1162 s1 = t("abcd") |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1163 s2 = u"".join([s1]) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1164 self.assert_(s1 is not s2) |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1165 self.assert_(type(s2) is unicode) # promotes! |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1166 |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1167 else: |
|
78b578c46770
test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents:
33298
diff
changeset
|
1168 self.fail("unexpected type for MixinStrUnicodeTest %r" % t) |
