annotate Lib/test/string_tests.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 82b58807f481
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
41716
00c02c4488ce Merged revisions 55325-55327 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41642
diff changeset
5 import unittest, string, sys, struct
47201
9c930a32cebb #2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents: 45504
diff changeset
6 from test import support
45302
b1cb6b44b798 Move UserList to collections.
Raymond Hettinger <python@rcn.com>
parents: 44160
diff changeset
7 from collections import UserList
81587
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
8 import _testcapi
13527
07c31182f237 add more tests of string.join variants to run_method_tests
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13517
diff changeset
9
13517
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
10 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
11 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
12 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
13 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
14
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
15 class BadSeq1(Sequence):
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
16 def __init__(self): self.seq = [7, 'hello', 123]
43446
a7c48ab809ec Patch # 1145 by Thomas Lee:
Guido van Rossum <guido@python.org>
parents: 43100
diff changeset
17 def __str__(self): return '{0} {1} {2}'.format(*self.seq)
13517
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
18
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
19 class BadSeq2(Sequence):
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
20 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
21 def __len__(self): return 8
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
22
81356
55383912c225 #16910: test_bytes, test_unicode, and test_userstring now work with unittest test discovery. Patch by Zachary Ware.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 78794
diff changeset
23 class BaseTest:
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
24 # These tests are for buffers of values (bytes) and not
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
25 # specific to character interpretation, used for bytes objects
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
26 # and various string implementations
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
27
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
28 # 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
29 # 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
30 type2test = None
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
31
73038
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
32 # Whether the "contained items" of the container are integers in
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
33 # range(0, 256) (i.e. bytes, bytearray) or strings of length 1
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
34 # (str)
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
35 contains_bytes = False
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
36
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
37 # 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
38 # 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
39 # 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
40 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
41 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
42 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
43 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
44 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
45 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
46 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
47 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
48 return dict([
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
49 (self.fixtype(key), self.fixtype(value))
40809
f340cb045bf9 - PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
50 for (key, value) in obj.items()
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
51 ])
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
52 else:
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
53 return obj
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
54
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
55 # check that obj.method(*args) returns result
72462
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
56 def checkequal(self, result, obj, methodname, *args, **kwargs):
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
57 result = self.fixtype(result)
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
58 obj = self.fixtype(obj)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
59 args = self.fixtype(args)
75291
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
60 kwargs = {k: self.fixtype(v) for k,v in kwargs.items()}
72462
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
61 realresult = getattr(obj, methodname)(*args, **kwargs)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
62 self.assertEqual(
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
63 result,
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
64 realresult
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
65 )
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
66 # 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
67 # this doesn't happen with subclasses
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
68 if obj is realresult:
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
69 try:
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
70 class subtype(self.__class__.type2test):
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
71 pass
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
72 except TypeError:
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
73 pass # Skip this if we can't subclass
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
74 else:
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
75 obj = subtype(obj)
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
76 realresult = getattr(obj, methodname)(*args)
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
77 self.assertIsNot(obj, realresult)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
78
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
79 # check that obj.method(*args) raises exc
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
80 def checkraises(self, exc, obj, methodname, *args):
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
81 obj = self.fixtype(obj)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
82 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
83 self.assertRaises(
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
84 exc,
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
85 getattr(obj, methodname),
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
86 *args
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
87 )
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
88
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
89 # call obj.method(*args) without any checks
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
90 def checkcall(self, obj, methodname, *args):
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
91 obj = self.fixtype(obj)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
92 args = self.fixtype(args)
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
93 getattr(obj, methodname)(*args)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
94
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
95 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
96 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
97 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
98 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
99 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
100 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
101 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
102 self.checkequal(0, 'aaa', 'count', 'b')
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
103 self.checkequal(2, 'aaa', 'count', 'a', 1)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
104 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
105 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
106 self.checkequal(3, 'aaa', 'count', 'a', -10)
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
107 self.checkequal(1, 'aaa', 'count', 'a', 0, 1)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
108 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
109 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
110 self.checkequal(0, 'aaa', 'count', 'a', 0, -10)
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
111 self.checkequal(3, 'aaa', 'count', '', 1)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
112 self.checkequal(1, 'aaa', 'count', '', 3)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
113 self.checkequal(0, 'aaa', 'count', '', 10)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
114 self.checkequal(2, 'aaa', 'count', '', -1)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
115 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
116
49310
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
117 self.checkequal(1, '', 'count', '')
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
118 self.checkequal(0, '', 'count', '', 1, 1)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
119 self.checkequal(0, '', 'count', '', sys.maxsize, 0)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
120
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
121 self.checkequal(0, '', 'count', 'xx')
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
122 self.checkequal(0, '', 'count', 'xx', 1, 1)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
123 self.checkequal(0, '', 'count', 'xx', sys.maxsize, 0)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
124
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
125 self.checkraises(TypeError, 'hello', 'count')
73038
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
126
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
127 if self.contains_bytes:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
128 self.checkequal(0, 'hello', 'count', 42)
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
129 else:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
130 self.checkraises(TypeError, 'hello', 'count', 42)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
131
34621
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
132 # For a variety of combinations,
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
133 # verify that str.count() matches an equivalent function
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
134 # 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
135 charset = ['', 'a', 'b']
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
136 digits = 7
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
137 base = len(charset)
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
138 teststrings = set()
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41620
diff changeset
139 for i in range(base ** digits):
34621
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
140 entry = []
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41620
diff changeset
141 for j in range(digits):
34621
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
142 i, m = divmod(i, base)
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
143 entry.append(charset[m])
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
144 teststrings.add(''.join(entry))
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
145 teststrings = [self.fixtype(ts) for ts in teststrings]
34621
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
146 for i in teststrings:
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
147 n = len(i)
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
148 for j in teststrings:
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
149 r1 = i.count(j)
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
150 if j:
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
151 r2, rem = divmod(n - len(i.replace(j, self.fixtype(''))),
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
152 len(j))
34621
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
153 else:
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
154 r2, rem = len(i)+1, 0
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
155 if rem or r1 != r2:
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
156 self.assertEqual(rem, 0, '%s != 0 for %s' % (rem, i))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
157 self.assertEqual(r1, r2, '%s != %s for %s' % (r1, r2, i))
34621
1edea4c2b011 * Beef-up tests for str.count().
Raymond Hettinger <python@rcn.com>
parents: 34620
diff changeset
158
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
159 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
160 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
161 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
162 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
163
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
164 self.checkequal(0, 'abc', 'find', '', 0)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
165 self.checkequal(3, 'abc', 'find', '', 3)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
166 self.checkequal(-1, 'abc', 'find', '', 4)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
167
43897
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
168 # to check the ability to pass None as defaults
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
169 self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a')
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
170 self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
171 self.checkequal(-1, 'rrarrrrrrrrra', 'find', 'a', 4, 6)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
172 self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4, None)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
173 self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a', None, 6)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
174
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
175 self.checkraises(TypeError, 'hello', 'find')
73038
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
176
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
177 if self.contains_bytes:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
178 self.checkequal(-1, 'hello', 'find', 42)
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
179 else:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
180 self.checkraises(TypeError, 'hello', 'find', 42)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
181
49310
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
182 self.checkequal(0, '', 'find', '')
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
183 self.checkequal(-1, '', 'find', '', 1, 1)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
184 self.checkequal(-1, '', 'find', '', sys.maxsize, 0)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
185
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
186 self.checkequal(-1, '', 'find', 'xx')
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
187 self.checkequal(-1, '', 'find', 'xx', 1, 1)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
188 self.checkequal(-1, '', 'find', 'xx', sys.maxsize, 0)
6403f1edecc1 Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47201
diff changeset
189
58097
a6ace30cb912 Merged revisions 77247 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58095
diff changeset
190 # issue 7458
a6ace30cb912 Merged revisions 77247 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58095
diff changeset
191 self.checkequal(-1, 'ab', 'find', 'xxx', sys.maxsize + 1, 0)
a6ace30cb912 Merged revisions 77247 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58095
diff changeset
192
34620
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
193 # For a variety of combinations,
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
194 # 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
195 # 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
196 charset = ['', 'a', 'b', 'c']
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
197 digits = 5
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
198 base = len(charset)
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
199 teststrings = set()
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41620
diff changeset
200 for i in range(base ** digits):
34620
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
201 entry = []
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41620
diff changeset
202 for j in range(digits):
34620
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
203 i, m = divmod(i, base)
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
204 entry.append(charset[m])
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
205 teststrings.add(''.join(entry))
42911
cb28e14ee808 Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42902
diff changeset
206 teststrings = [self.fixtype(ts) for ts in teststrings]
34620
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
207 for i in teststrings:
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
208 for j in teststrings:
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
209 loc = i.find(j)
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
210 r1 = (loc != -1)
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
211 r2 = j in i
58099
cc97a96e4a09 Merged revisions 77249 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58097
diff changeset
212 self.assertEqual(r1, r2)
34620
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
213 if loc != -1:
556f6f1056a8 * Beef-up testing of str.__contains__() and str.find().
Raymond Hettinger <python@rcn.com>
parents: 33833
diff changeset
214 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
215
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
216 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
217 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
218 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
219 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
220 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
221
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
222 self.checkequal(3, 'abc', 'rfind', '', 0)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
223 self.checkequal(3, 'abc', 'rfind', '', 3)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
224 self.checkequal(-1, 'abc', 'rfind', '', 4)
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
225
43897
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
226 # to check the ability to pass None as defaults
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
227 self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a')
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
228 self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
229 self.checkequal(-1, 'rrarrrrrrrrra', 'rfind', 'a', 4, 6)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
230 self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4, None)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
231 self.checkequal( 2, 'rrarrrrrrrrra', 'rfind', 'a', None, 6)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
232
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
233 self.checkraises(TypeError, 'hello', 'rfind')
73038
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
234
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
235 if self.contains_bytes:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
236 self.checkequal(-1, 'hello', 'rfind', 42)
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
237 else:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
238 self.checkraises(TypeError, 'hello', 'rfind', 42)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
239
58095
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
240 # For a variety of combinations,
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
241 # verify that str.rfind() matches __contains__
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
242 # and that the found substring is really at that location
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
243 charset = ['', 'a', 'b', 'c']
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
244 digits = 5
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
245 base = len(charset)
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
246 teststrings = set()
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
247 for i in range(base ** digits):
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
248 entry = []
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
249 for j in range(digits):
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
250 i, m = divmod(i, base)
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
251 entry.append(charset[m])
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
252 teststrings.add(''.join(entry))
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
253 teststrings = [self.fixtype(ts) for ts in teststrings]
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
254 for i in teststrings:
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
255 for j in teststrings:
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
256 loc = i.rfind(j)
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
257 r1 = (loc != -1)
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
258 r2 = j in i
58099
cc97a96e4a09 Merged revisions 77249 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58097
diff changeset
259 self.assertEqual(r1, r2)
58095
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
260 if loc != -1:
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
261 self.assertEqual(i[loc:loc+len(j)], j)
a1035cb4a925 Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57582
diff changeset
262
58097
a6ace30cb912 Merged revisions 77247 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58095
diff changeset
263 # issue 7458
a6ace30cb912 Merged revisions 77247 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58095
diff changeset
264 self.checkequal(-1, 'ab', 'rfind', 'xxx', sys.maxsize + 1, 0)
a6ace30cb912 Merged revisions 77247 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58095
diff changeset
265
78386
0e95b61af859 Close #15534: Fix a typo in the fast search function of the string library (_s => s)
Victor Stinner <victor.stinner@gmail.com>
parents: 76817
diff changeset
266 # issue #15534
0e95b61af859 Close #15534: Fix a typo in the fast search function of the string library (_s => s)
Victor Stinner <victor.stinner@gmail.com>
parents: 76817
diff changeset
267 self.checkequal(0, '<......\u043c...', "rfind", "<")
0e95b61af859 Close #15534: Fix a typo in the fast search function of the string library (_s => s)
Victor Stinner <victor.stinner@gmail.com>
parents: 76817
diff changeset
268
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
269 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
270 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
271 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
272 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
273 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
274
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
275 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
276 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
277 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
278 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
279
43897
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
280 # to check the ability to pass None as defaults
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
281 self.checkequal( 2, 'rrarrrrrrrrra', 'index', 'a')
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
282 self.checkequal(12, 'rrarrrrrrrrra', 'index', 'a', 4)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
283 self.checkraises(ValueError, 'rrarrrrrrrrra', 'index', 'a', 4, 6)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
284 self.checkequal(12, 'rrarrrrrrrrra', 'index', 'a', 4, None)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
285 self.checkequal( 2, 'rrarrrrrrrrra', 'index', 'a', None, 6)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
286
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
287 self.checkraises(TypeError, 'hello', 'index')
73038
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
288
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
289 if self.contains_bytes:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
290 self.checkraises(ValueError, 'hello', 'index', 42)
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
291 else:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
292 self.checkraises(TypeError, 'hello', 'index', 42)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
293
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
294 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
295 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
296 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
297 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
298 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
299
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
300 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
301 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
302 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
303 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
304 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
305
43897
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
306 # to check the ability to pass None as defaults
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
307 self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a')
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
308 self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a', 4)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
309 self.checkraises(ValueError, 'rrarrrrrrrrra', 'rindex', 'a', 4, 6)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
310 self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a', 4, None)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
311 self.checkequal( 2, 'rrarrrrrrrrra', 'rindex', 'a', None, 6)
41f7c13ef161 Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
312
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
313 self.checkraises(TypeError, 'hello', 'rindex')
73038
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
314
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
315 if self.contains_bytes:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
316 self.checkraises(ValueError, 'hello', 'rindex', 42)
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
317 else:
c1effa2cdd20 Issue #12170: The count(), find(), rfind(), index() and rindex() methods
Antoine Pitrou <solipsis@pitrou.net>
parents: 72462
diff changeset
318 self.checkraises(TypeError, 'hello', 'rindex', 42)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
319
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
320 def test_lower(self):
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
321 self.checkequal('hello', 'HeLLo', 'lower')
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
322 self.checkequal('hello', 'hello', 'lower')
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
323 self.checkraises(TypeError, 'hello', 'lower', 42)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
324
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
325 def test_upper(self):
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
326 self.checkequal('HELLO', 'HeLLo', 'upper')
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
327 self.checkequal('HELLO', 'HELLO', 'upper')
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
328 self.checkraises(TypeError, 'hello', 'upper', 42)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
329
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
330 def test_expandtabs(self):
87153
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
331 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi',
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
332 'expandtabs')
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
333 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi',
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
334 'expandtabs', 8)
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
335 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi',
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
336 'expandtabs', 4)
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
337 self.checkequal('abc\r\nab def\ng hi', 'abc\r\nab\tdef\ng\thi',
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
338 'expandtabs')
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
339 self.checkequal('abc\r\nab def\ng hi', 'abc\r\nab\tdef\ng\thi',
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
340 'expandtabs', 8)
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
341 self.checkequal('abc\r\nab def\ng hi', 'abc\r\nab\tdef\ng\thi',
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
342 'expandtabs', 4)
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
343 self.checkequal('abc\r\nab\r\ndef\ng\r\nhi', 'abc\r\nab\r\ndef\ng\r\nhi',
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
344 'expandtabs', 4)
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
345 # check keyword args
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
346 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi',
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
347 'expandtabs', tabsize=8)
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
348 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi',
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
349 'expandtabs', tabsize=4)
82b58807f481 #17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
Ezio Melotti <ezio.melotti@gmail.com>
parents: 83475
diff changeset
350
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
351 self.checkequal(' a\n b', ' \ta\n\tb', 'expandtabs', 1)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
352
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
353 self.checkraises(TypeError, 'hello', 'expandtabs', 42, 42)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
354 # This test is only valid when sizeof(int) == sizeof(void*) == 4.
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
355 if sys.maxsize < (1 << 32) and struct.calcsize('P') == 4:
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
356 self.checkraises(OverflowError,
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
357 '\ta\n\tb', 'expandtabs', sys.maxsize)
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
358
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
359 def test_split(self):
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
360 # by a char
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
361 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|')
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
362 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
363 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
364 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
365 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
366 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|', 4)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
367 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|',
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
368 sys.maxsize-2)
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
369 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
370 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
371 self.checkequal(['endcase ', ''], 'endcase |', 'split', '|')
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
372 self.checkequal(['', ' startcase'], '| startcase', 'split', '|')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
373 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
374 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
375
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
376 self.checkequal(['a']*20, ('a|'*20)[:-1], 'split', '|')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
377 self.checkequal(['a']*15 +['a|a|a|a|a'],
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
378 ('a|'*20)[:-1], 'split', '|', 15)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
379
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
380 # 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
381 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
382 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
383 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
384 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
385 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//', 4)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
386 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//',
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
387 sys.maxsize-10)
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
388 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
389 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
390 self.checkequal(['endcase ', ''], 'endcase test', 'split', 'test')
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
391 self.checkequal(['', ' begincase'], 'test begincase', 'split', 'test')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
392 self.checkequal(['', ' bothcase ', ''], 'test bothcase test',
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
393 'split', 'test')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
394 self.checkequal(['a', 'bc'], 'abbbc', 'split', 'bb')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
395 self.checkequal(['', ''], 'aaa', 'split', 'aaa')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
396 self.checkequal(['aaa'], 'aaa', 'split', 'aaa', 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
397 self.checkequal(['ab', 'ab'], 'abbaab', 'split', 'ba')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
398 self.checkequal(['aaaa'], 'aaaa', 'split', 'aab')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
399 self.checkequal([''], '', 'split', 'aaa')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
400 self.checkequal(['aa'], 'aa', 'split', 'aaa')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
401 self.checkequal(['A', 'bobb'], 'Abbobbbobb', 'split', 'bbobb')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
402 self.checkequal(['A', 'B', ''], 'AbbobbBbbobb', 'split', 'bbobb')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
403
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
404 self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'split', 'BLAH')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
405 self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'split', 'BLAH', 19)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
406 self.checkequal(['a']*18 + ['aBLAHa'], ('aBLAH'*20)[:-4],
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
407 '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
408
75291
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
409 # with keyword args
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
410 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', sep='|')
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
411 self.checkequal(['a', 'b|c|d'],
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
412 'a|b|c|d', 'split', '|', maxsplit=1)
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
413 self.checkequal(['a', 'b|c|d'],
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
414 'a|b|c|d', 'split', sep='|', maxsplit=1)
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
415 self.checkequal(['a', 'b|c|d'],
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
416 'a|b|c|d', 'split', maxsplit=1, sep='|')
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
417 self.checkequal(['a', 'b c d'],
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
418 'a b c d', 'split', maxsplit=1)
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
419
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
420 # 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
421 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
422
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
423 # null case
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
424 self.checkraises(ValueError, 'hello', 'split', '')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
425 self.checkraises(ValueError, 'hello', 'split', '', 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
426
31199
504943c89193 Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31021
diff changeset
427 def test_rsplit(self):
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
428 # by a char
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
429 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
430 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
431 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
432 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
433 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', 4)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
434 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|',
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
435 sys.maxsize-100)
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
436 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
437 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
438 self.checkequal(['', ' begincase'], '| begincase', 'rsplit', '|')
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
439 self.checkequal(['endcase ', ''], 'endcase |', 'rsplit', '|')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
440 self.checkequal(['', 'bothcase', ''], '|bothcase|', 'rsplit', '|')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
441
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
442 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
443
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
444 self.checkequal(['a']*20, ('a|'*20)[:-1], 'rsplit', '|')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
445 self.checkequal(['a|a|a|a|a']+['a']*15,
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
446 ('a|'*20)[:-1], 'rsplit', '|', 15)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
447
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
448 # by string
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
449 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
450 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
451 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
452 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
453 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//', 4)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
454 self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//',
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
455 sys.maxsize-5)
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
456 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
457 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
458 self.checkequal(['', ' begincase'], 'test begincase', 'rsplit', 'test')
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
459 self.checkequal(['endcase ', ''], 'endcase test', 'rsplit', 'test')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
460 self.checkequal(['', ' bothcase ', ''], 'test bothcase test',
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
461 'rsplit', 'test')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
462 self.checkequal(['ab', 'c'], 'abbbc', 'rsplit', 'bb')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
463 self.checkequal(['', ''], 'aaa', 'rsplit', 'aaa')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
464 self.checkequal(['aaa'], 'aaa', 'rsplit', 'aaa', 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
465 self.checkequal(['ab', 'ab'], 'abbaab', 'rsplit', 'ba')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
466 self.checkequal(['aaaa'], 'aaaa', 'rsplit', 'aab')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
467 self.checkequal([''], '', 'rsplit', 'aaa')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
468 self.checkequal(['aa'], 'aa', 'rsplit', 'aaa')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
469 self.checkequal(['bbob', 'A'], 'bbobbbobbA', 'rsplit', 'bbobb')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
470 self.checkequal(['', 'B', 'A'], 'bbobbBbbobbA', 'rsplit', 'bbobb')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
471
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
472 self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'rsplit', 'BLAH')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
473 self.checkequal(['a']*20, ('aBLAH'*20)[:-4], 'rsplit', 'BLAH', 19)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
474 self.checkequal(['aBLAHa'] + ['a']*18, ('aBLAH'*20)[:-4],
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
475 'rsplit', 'BLAH', 18)
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
476
75291
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
477 # with keyword args
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
478 self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', sep='|')
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
479 self.checkequal(['a|b|c', 'd'],
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
480 'a|b|c|d', 'rsplit', '|', maxsplit=1)
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
481 self.checkequal(['a|b|c', 'd'],
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
482 'a|b|c|d', 'rsplit', sep='|', maxsplit=1)
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
483 self.checkequal(['a|b|c', 'd'],
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
484 'a|b|c|d', 'rsplit', maxsplit=1, sep='|')
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
485 self.checkequal(['a b c', 'd'],
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
486 'a b c d', 'rsplit', maxsplit=1)
db968ac2b82c #14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74338
diff changeset
487
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
488 # argument type
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
489 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
490
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
491 # null case
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
492 self.checkraises(ValueError, 'hello', 'rsplit', '')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
493 self.checkraises(ValueError, 'hello', 'rsplit', '', 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
494
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
495 def test_replace(self):
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
496 EQ = self.checkequal
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
497
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
498 # Operations on the empty string
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
499 EQ("", "", "replace", "", "")
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
500 EQ("A", "", "replace", "", "A")
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
501 EQ("", "", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
502 EQ("", "", "replace", "A", "A")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
503 EQ("", "", "replace", "", "", 100)
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
504 EQ("", "", "replace", "", "", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
505
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
506 # interleave (from=="", 'to' gets inserted everywhere)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
507 EQ("A", "A", "replace", "", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
508 EQ("*A*", "A", "replace", "", "*")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
509 EQ("*1A*1", "A", "replace", "", "*1")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
510 EQ("*-#A*-#", "A", "replace", "", "*-#")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
511 EQ("*-A*-A*-", "AA", "replace", "", "*-")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
512 EQ("*-A*-A*-", "AA", "replace", "", "*-", -1)
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
513 EQ("*-A*-A*-", "AA", "replace", "", "*-", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
514 EQ("*-A*-A*-", "AA", "replace", "", "*-", 4)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
515 EQ("*-A*-A*-", "AA", "replace", "", "*-", 3)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
516 EQ("*-A*-A", "AA", "replace", "", "*-", 2)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
517 EQ("*-AA", "AA", "replace", "", "*-", 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
518 EQ("AA", "AA", "replace", "", "*-", 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
519
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
520 # single character deletion (from=="A", to=="")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
521 EQ("", "A", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
522 EQ("", "AAA", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
523 EQ("", "AAA", "replace", "A", "", -1)
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
524 EQ("", "AAA", "replace", "A", "", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
525 EQ("", "AAA", "replace", "A", "", 4)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
526 EQ("", "AAA", "replace", "A", "", 3)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
527 EQ("A", "AAA", "replace", "A", "", 2)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
528 EQ("AA", "AAA", "replace", "A", "", 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
529 EQ("AAA", "AAA", "replace", "A", "", 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
530 EQ("", "AAAAAAAAAA", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
531 EQ("BCD", "ABACADA", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
532 EQ("BCD", "ABACADA", "replace", "A", "", -1)
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
533 EQ("BCD", "ABACADA", "replace", "A", "", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
534 EQ("BCD", "ABACADA", "replace", "A", "", 5)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
535 EQ("BCD", "ABACADA", "replace", "A", "", 4)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
536 EQ("BCDA", "ABACADA", "replace", "A", "", 3)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
537 EQ("BCADA", "ABACADA", "replace", "A", "", 2)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
538 EQ("BACADA", "ABACADA", "replace", "A", "", 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
539 EQ("ABACADA", "ABACADA", "replace", "A", "", 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
540 EQ("BCD", "ABCAD", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
541 EQ("BCD", "ABCADAA", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
542 EQ("BCD", "BCD", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
543 EQ("*************", "*************", "replace", "A", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
544 EQ("^A^", "^"+"A"*1000+"^", "replace", "A", "", 999)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
545
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
546 # substring deletion (from=="the", to=="")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
547 EQ("", "the", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
548 EQ("ater", "theater", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
549 EQ("", "thethe", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
550 EQ("", "thethethethe", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
551 EQ("aaaa", "theatheatheathea", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
552 EQ("that", "that", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
553 EQ("thaet", "thaet", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
554 EQ("here and re", "here and there", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
555 EQ("here and re and re", "here and there and there",
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
556 "replace", "the", "", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
557 EQ("here and re and re", "here and there and there",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
558 "replace", "the", "", -1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
559 EQ("here and re and re", "here and there and there",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
560 "replace", "the", "", 3)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
561 EQ("here and re and re", "here and there and there",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
562 "replace", "the", "", 2)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
563 EQ("here and re and there", "here and there and there",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
564 "replace", "the", "", 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
565 EQ("here and there and there", "here and there and there",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
566 "replace", "the", "", 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
567 EQ("here and re and re", "here and there and there", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
568
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
569 EQ("abc", "abc", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
570 EQ("abcdefg", "abcdefg", "replace", "the", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
571
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
572 # substring deletion (from=="bob", to=="")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
573 EQ("bob", "bbobob", "replace", "bob", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
574 EQ("bobXbob", "bbobobXbbobob", "replace", "bob", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
575 EQ("aaaaaaa", "aaaaaaabob", "replace", "bob", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
576 EQ("aaaaaaa", "aaaaaaa", "replace", "bob", "")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
577
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
578 # single character replace in place (len(from)==len(to)==1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
579 EQ("Who goes there?", "Who goes there?", "replace", "o", "o")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
580 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O")
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
581 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
582 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", -1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
583 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", 3)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
584 EQ("WhO gOes there?", "Who goes there?", "replace", "o", "O", 2)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
585 EQ("WhO goes there?", "Who goes there?", "replace", "o", "O", 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
586 EQ("Who goes there?", "Who goes there?", "replace", "o", "O", 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
587
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
588 EQ("Who goes there?", "Who goes there?", "replace", "a", "q")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
589 EQ("who goes there?", "Who goes there?", "replace", "W", "w")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
590 EQ("wwho goes there?ww", "WWho goes there?WW", "replace", "W", "w")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
591 EQ("Who goes there!", "Who goes there?", "replace", "?", "!")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
592 EQ("Who goes there!!", "Who goes there??", "replace", "?", "!")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
593
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
594 EQ("Who goes there?", "Who goes there?", "replace", ".", "!")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
595
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
596 # substring replace in place (len(from)==len(to) > 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
597 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**")
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
598 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
599 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", -1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
600 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", 4)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
601 EQ("Th** ** a t**sue", "This is a tissue", "replace", "is", "**", 3)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
602 EQ("Th** ** a tissue", "This is a tissue", "replace", "is", "**", 2)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
603 EQ("Th** is a tissue", "This is a tissue", "replace", "is", "**", 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
604 EQ("This is a tissue", "This is a tissue", "replace", "is", "**", 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
605 EQ("cobob", "bobob", "replace", "bob", "cob")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
606 EQ("cobobXcobocob", "bobobXbobobob", "replace", "bob", "cob")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
607 EQ("bobob", "bobob", "replace", "bot", "bot")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
608
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
609 # replace single character (len(from)==1, len(to)>1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
610 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
611 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", -1)
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
612 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
613 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", 2)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
614 EQ("ReyKKjavik", "Reykjavik", "replace", "k", "KK", 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
615 EQ("Reykjavik", "Reykjavik", "replace", "k", "KK", 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
616 EQ("A----B----C----", "A.B.C.", "replace", ".", "----")
78386
0e95b61af859 Close #15534: Fix a typo in the fast search function of the string library (_s => s)
Victor Stinner <victor.stinner@gmail.com>
parents: 76817
diff changeset
617 # issue #15534
0e95b61af859 Close #15534: Fix a typo in the fast search function of the string library (_s => s)
Victor Stinner <victor.stinner@gmail.com>
parents: 76817
diff changeset
618 EQ('...\u043c......&lt;', '...\u043c......<', "replace", "<", "&lt;")
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
619
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
620 EQ("Reykjavik", "Reykjavik", "replace", "q", "KK")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
621
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
622 # replace substring (len(from)>1, len(to)!=len(from))
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
623 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
624 "replace", "spam", "ham")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
625 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
626 "replace", "spam", "ham", sys.maxsize)
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
627 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
628 "replace", "spam", "ham", -1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
629 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
630 "replace", "spam", "ham", 4)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
631 EQ("ham, ham, eggs and ham", "spam, spam, eggs and spam",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
632 "replace", "spam", "ham", 3)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
633 EQ("ham, ham, eggs and spam", "spam, spam, eggs and spam",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
634 "replace", "spam", "ham", 2)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
635 EQ("ham, spam, eggs and spam", "spam, spam, eggs and spam",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
636 "replace", "spam", "ham", 1)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
637 EQ("spam, spam, eggs and spam", "spam, spam, eggs and spam",
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
638 "replace", "spam", "ham", 0)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
639
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
640 EQ("bobob", "bobobob", "replace", "bobob", "bob")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
641 EQ("bobobXbobob", "bobobobXbobobob", "replace", "bobob", "bob")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
642 EQ("BOBOBOB", "BOBOBOB", "replace", "bob", "bobby")
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
643
42902
62874b34d95d Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42088
diff changeset
644 # XXX Commented out. Is there any reason to support buffer objects
62874b34d95d Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42088
diff changeset
645 # as arguments for str.replace()? GvR
43947
cbc8b3bd3157 Rename buffer -> bytearray.
Guido van Rossum <guido@python.org>
parents: 43897
diff changeset
646 ## ba = bytearray('a')
cbc8b3bd3157 Rename buffer -> bytearray.
Guido van Rossum <guido@python.org>
parents: 43897
diff changeset
647 ## bb = bytearray('b')
42902
62874b34d95d Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42088
diff changeset
648 ## EQ("bbc", "abc", "replace", ba, bb)
62874b34d95d Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42088
diff changeset
649 ## EQ("aac", "abc", "replace", bb, ba)
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
650
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
651 #
28009
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('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
653 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
654 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
655 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
656 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
657 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
658 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
659 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
660 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
661 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
662 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
663 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
664 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
665 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
666 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
667 # 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
668 # 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
669 # 0 bytes).
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
670 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
671 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
672 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
673
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
674 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
675 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
676 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
677 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
678
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
679 def test_replace_overflow(self):
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
680 # Check for overflow checking on 32 bit machines
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
681 if sys.maxsize != 2147483647 or struct.calcsize("P") > 4:
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
682 return
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
683 A2_16 = "A" * (2**16)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
684 self.checkraises(OverflowError, A2_16, "replace", "", A2_16)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
685 self.checkraises(OverflowError, A2_16, "replace", "A", A2_16)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
686 self.checkraises(OverflowError, A2_16, "replace", "AA", A2_16+A2_16)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
687
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
688
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
689
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
690 class CommonTest(BaseTest):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
691 # This testcase contains test that can be used in all
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
692 # stringlike classes. Currently this is str, unicode
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
693 # UserString and the string module.
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
694
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
695 def test_hash(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
696 # SF bug 1054139: += optimization was not invalidating cached hash value
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
697 a = self.type2test('DNSSEC')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
698 b = self.type2test('')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
699 for c in a:
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
700 b += c
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
701 hash(b)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
702 self.assertEqual(hash(a), hash(b))
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
703
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
704 def test_capitalize(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
705 self.checkequal(' hello ', ' hello ', 'capitalize')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
706 self.checkequal('Hello ', 'Hello ','capitalize')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
707 self.checkequal('Hello ', 'hello ','capitalize')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
708 self.checkequal('Aaaa', 'aaaa', 'capitalize')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
709 self.checkequal('Aaaa', 'AaAa', 'capitalize')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
710
71866
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
711 # check that titlecased chars are lowered correctly
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
712 # \u1ffc is the titlecased char
74338
f7e05d205a52 use full unicode mappings for upper/lower/title case (#12736)
Benjamin Peterson <benjamin@python.org>
parents: 73038
diff changeset
713 self.checkequal('\u03a9\u0399\u1ff3\u1ff3\u1ff3',
71866
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
714 '\u1ff3\u1ff3\u1ffc\u1ffc', 'capitalize')
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
715 # check with cased non-letter chars
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
716 self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd',
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
717 '\u24c5\u24ce\u24c9\u24bd\u24c4\u24c3', 'capitalize')
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
718 self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd',
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
719 '\u24df\u24e8\u24e3\u24d7\u24de\u24dd', 'capitalize')
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
720 self.checkequal('\u2160\u2171\u2172',
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
721 '\u2160\u2161\u2162', 'capitalize')
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
722 self.checkequal('\u2160\u2171\u2172',
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
723 '\u2170\u2171\u2172', 'capitalize')
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
724 # check with Ll chars with no upper - nothing changes here
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
725 self.checkequal('\u019b\u1d00\u1d86\u0221\u1fb7',
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
726 '\u019b\u1d00\u1d86\u0221\u1fb7', 'capitalize')
c34772013c53 #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69479
diff changeset
727
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
728 self.checkraises(TypeError, 'hello', 'capitalize', 42)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
729
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
730 def test_additional_split(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
731 self.checkequal(['this', 'is', 'the', 'split', 'function'],
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
732 'this is the split function', 'split')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
733
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
734 # by whitespace
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
735 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d ', 'split')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
736 self.checkequal(['a', 'b c d'], 'a b c d', 'split', None, 1)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
737 self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', None, 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
738 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None, 3)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
739 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None, 4)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
740 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None,
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
741 sys.maxsize-1)
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
742 self.checkequal(['a b c d'], 'a b c d', 'split', None, 0)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
743 self.checkequal(['a b c d'], ' a b c d', 'split', None, 0)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
744 self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', None, 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
745
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
746 self.checkequal([], ' ', 'split')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
747 self.checkequal(['a'], ' a ', 'split')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
748 self.checkequal(['a', 'b'], ' a b ', 'split')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
749 self.checkequal(['a', 'b '], ' a b ', 'split', None, 1)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
750 self.checkequal(['a', 'b c '], ' a b c ', 'split', None, 1)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
751 self.checkequal(['a', 'b', 'c '], ' a b c ', 'split', None, 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
752 self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'split')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
753 aaa = ' a '*20
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
754 self.checkequal(['a']*20, aaa, 'split')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
755 self.checkequal(['a'] + [aaa[4:]], aaa, 'split', None, 1)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
756 self.checkequal(['a']*19 + ['a '], aaa, 'split', None, 19)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
757
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
758 # mixed use of str and unicode
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
759 self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', ' ', 2)
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
760
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
761 def test_additional_rsplit(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
762 self.checkequal(['this', 'is', 'the', 'rsplit', 'function'],
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
763 'this is the rsplit function', 'rsplit')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
764
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
765 # by whitespace
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
766 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d ', 'rsplit')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
767 self.checkequal(['a b c', 'd'], 'a b c d', 'rsplit', None, 1)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
768 self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', None, 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
769 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None, 3)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
770 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None, 4)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
771 self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None,
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
772 sys.maxsize-20)
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
773 self.checkequal(['a b c d'], 'a b c d', 'rsplit', None, 0)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
774 self.checkequal(['a b c d'], 'a b c d ', 'rsplit', None, 0)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
775 self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', None, 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
776
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
777 self.checkequal([], ' ', 'rsplit')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
778 self.checkequal(['a'], ' a ', 'rsplit')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
779 self.checkequal(['a', 'b'], ' a b ', 'rsplit')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
780 self.checkequal([' a', 'b'], ' a b ', 'rsplit', None, 1)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
781 self.checkequal([' a b','c'], ' a b c ', 'rsplit',
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
782 None, 1)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
783 self.checkequal([' a', 'b', 'c'], ' a b c ', 'rsplit',
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
784 None, 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
785 self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'rsplit', None, 88)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
786 aaa = ' a '*20
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
787 self.checkequal(['a']*20, aaa, 'rsplit')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
788 self.checkequal([aaa[:-4]] + ['a'], aaa, 'rsplit', None, 1)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
789 self.checkequal([' a a'] + ['a']*18, aaa, 'rsplit', None, 18)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
790
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
791 # mixed use of str and unicode
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
792 self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', ' ', 2)
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
793
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
794 def test_strip(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
795 self.checkequal('hello', ' hello ', 'strip')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
796 self.checkequal('hello ', ' hello ', 'lstrip')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
797 self.checkequal(' hello', ' hello ', 'rstrip')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
798 self.checkequal('hello', 'hello', 'strip')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
799
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
800 # strip/lstrip/rstrip with None arg
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
801 self.checkequal('hello', ' hello ', 'strip', None)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
802 self.checkequal('hello ', ' hello ', 'lstrip', None)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
803 self.checkequal(' hello', ' hello ', 'rstrip', None)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
804 self.checkequal('hello', 'hello', 'strip', None)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
805
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
806 # strip/lstrip/rstrip with str arg
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
807 self.checkequal('hello', 'xyzzyhelloxyzzy', 'strip', 'xyz')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
808 self.checkequal('helloxyzzy', 'xyzzyhelloxyzzy', 'lstrip', 'xyz')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
809 self.checkequal('xyzzyhello', 'xyzzyhelloxyzzy', 'rstrip', 'xyz')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
810 self.checkequal('hello', 'hello', 'strip', 'xyz')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
811
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
812 self.checkraises(TypeError, 'hello', 'strip', 42, 42)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
813 self.checkraises(TypeError, 'hello', 'lstrip', 42, 42)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
814 self.checkraises(TypeError, 'hello', 'rstrip', 42, 42)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
815
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
816 def test_ljust(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
817 self.checkequal('abc ', 'abc', 'ljust', 10)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
818 self.checkequal('abc ', 'abc', 'ljust', 6)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
819 self.checkequal('abc', 'abc', 'ljust', 3)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
820 self.checkequal('abc', 'abc', 'ljust', 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
821 self.checkequal('abc*******', 'abc', 'ljust', 10, '*')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
822 self.checkraises(TypeError, 'abc', 'ljust')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
823
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
824 def test_rjust(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
825 self.checkequal(' abc', 'abc', 'rjust', 10)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
826 self.checkequal(' abc', 'abc', 'rjust', 6)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
827 self.checkequal('abc', 'abc', 'rjust', 3)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
828 self.checkequal('abc', 'abc', 'rjust', 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
829 self.checkequal('*******abc', 'abc', 'rjust', 10, '*')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
830 self.checkraises(TypeError, 'abc', 'rjust')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
831
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
832 def test_center(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
833 self.checkequal(' abc ', 'abc', 'center', 10)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
834 self.checkequal(' abc ', 'abc', 'center', 6)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
835 self.checkequal('abc', 'abc', 'center', 3)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
836 self.checkequal('abc', 'abc', 'center', 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
837 self.checkequal('***abc****', 'abc', 'center', 10, '*')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
838 self.checkraises(TypeError, 'abc', 'center')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
839
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
840 def test_swapcase(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
841 self.checkequal('hEllO CoMPuTErS', 'HeLLo cOmpUteRs', 'swapcase')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
842
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
843 self.checkraises(TypeError, 'hello', 'swapcase', 42)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
844
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
845 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
846 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
847 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
848 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
849 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
850 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
851 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
852 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
853 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
854 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
855 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
856 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
857 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
858
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
859 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
860
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
861 class MixinStrUnicodeUserStringTest:
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
862 # 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
863 # 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
864 # (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
865
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
866 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
867 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
868 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
869 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
870 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
871 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
872 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
873 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
874 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
875
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
876 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
877 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
878 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
879 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
880 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
881 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
882 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
883 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
884 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
885
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_istitle(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(False, '', 'istitle')
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(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
889 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
890 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
891 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
892 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
893 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
894 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
895 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
896 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
897 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
898 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
899
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
900 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
901 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
902 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
903 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
904 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
905 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
906 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
907 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
908 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
909 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
910
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
911 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
912 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
913 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
914 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
915 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
916 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
917 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
918 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
919 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
920
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
921 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
922 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
923 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
924 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
925 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
926 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
927 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
928 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
929 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
930 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
931
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
932 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
933 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
934 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
935 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
936 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
937 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
938
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
939 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
940
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
941 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
942 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
943 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
944 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
945 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
946 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
947 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
948 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
949
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
950 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
951 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
952 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
953 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
954 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
955 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
956 self.checkequal(['', 'abc', 'def', 'ghi', ''], "\nabc\ndef\r\nghi\n\r", 'splitlines')
72462
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
957 self.checkequal(['', 'abc', 'def', 'ghi', ''],
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
958 "\nabc\ndef\r\nghi\n\r", 'splitlines', False)
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
959 self.checkequal(['\n', 'abc\n', 'def\r\n', 'ghi\n', '\r'],
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
960 "\nabc\ndef\r\nghi\n\r", 'splitlines', True)
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
961 self.checkequal(['', 'abc', 'def', 'ghi', ''], "\nabc\ndef\r\nghi\n\r",
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
962 'splitlines', keepends=False)
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
963 self.checkequal(['\n', 'abc\n', 'def\r\n', 'ghi\n', '\r'],
0b2660384d4e Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines.
Mark Dickinson <mdickinson@enthought.com>
parents: 71866
diff changeset
964 "\nabc\ndef\r\nghi\n\r", 'splitlines', keepends=True)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
965
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
966 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
967
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
968 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
969 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
970 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
971 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
972 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
973 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
974 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
975 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
976 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
977 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
978 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
979 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
980 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
981 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
982
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
983 # 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
984 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
985 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
986 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
987 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
988 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
989 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
990 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
991 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
992 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
993 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
994
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, 'hello', 'startswith')
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(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
997
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
998 # test tuple arguments
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
999 self.checkequal(True, 'hello', 'startswith', ('he', 'ha'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1000 self.checkequal(False, 'hello', 'startswith', ('lo', 'llo'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1001 self.checkequal(True, 'hello', 'startswith', ('hellox', 'hello'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1002 self.checkequal(False, 'hello', 'startswith', ())
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1003 self.checkequal(True, 'helloworld', 'startswith', ('hellowo',
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1004 'rld', 'lowo'), 3)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1005 self.checkequal(False, 'helloworld', 'startswith', ('hellowo', 'ello',
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1006 'rld'), 3)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1007 self.checkequal(True, 'hello', 'startswith', ('lo', 'he'), 0, -1)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1008 self.checkequal(False, 'hello', 'startswith', ('he', 'hel'), 0, 1)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1009 self.checkequal(True, 'hello', 'startswith', ('he', 'hel'), 0, 2)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1010
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1011 self.checkraises(TypeError, 'hello', 'startswith', (42,))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1012
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1013 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
1014 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
1015 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
1016 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
1017 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
1018 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
1019 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
1020 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
1021 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
1022 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
1023 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
1024 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
1025 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
1026 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
1027 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
1028
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1029 # 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
1030 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
1031 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
1032 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
1033 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
1034 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
1035 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
1036 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
1037 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
1038 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
1039 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
1040 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
1041 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
1042 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
1043
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1044 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
1045 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
1046
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1047 # test tuple arguments
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1048 self.checkequal(False, 'hello', 'endswith', ('he', 'ha'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1049 self.checkequal(True, 'hello', 'endswith', ('lo', 'llo'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1050 self.checkequal(True, 'hello', 'endswith', ('hellox', 'hello'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1051 self.checkequal(False, 'hello', 'endswith', ())
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1052 self.checkequal(True, 'helloworld', 'endswith', ('hellowo',
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1053 'rld', 'lowo'), 3)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1054 self.checkequal(False, 'helloworld', 'endswith', ('hellowo', 'ello',
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1055 'rld'), 3, -1)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1056 self.checkequal(True, 'hello', 'endswith', ('hell', 'ell'), 0, -1)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1057 self.checkequal(False, 'hello', 'endswith', ('he', 'hel'), 0, 1)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1058 self.checkequal(True, 'hello', 'endswith', ('he', 'hell'), 0, 4)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1059
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1060 self.checkraises(TypeError, 'hello', 'endswith', (42,))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1061
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1062 def test___contains__(self):
58477
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1063 self.checkequal(True, '', '__contains__', '')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1064 self.checkequal(True, 'abc', '__contains__', '')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1065 self.checkequal(False, 'abc', '__contains__', '\0')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1066 self.checkequal(True, '\0abc', '__contains__', '\0')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1067 self.checkequal(True, 'abc\0', '__contains__', '\0')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1068 self.checkequal(True, '\0abc', '__contains__', 'a')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1069 self.checkequal(True, 'asdf', '__contains__', 'asdf')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1070 self.checkequal(False, 'asd', '__contains__', 'asdf')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1071 self.checkequal(False, '', '__contains__', 'asdf')
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1072
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1073 def test_subscript(self):
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1074 self.checkequal('a', 'abc', '__getitem__', 0)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1075 self.checkequal('c', 'abc', '__getitem__', -1)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1076 self.checkequal('a', 'abc', '__getitem__', 0)
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1077 self.checkequal('abc', 'abc', '__getitem__', slice(0, 3))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1078 self.checkequal('abc', 'abc', '__getitem__', slice(0, 1000))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1079 self.checkequal('a', 'abc', '__getitem__', slice(0, 1))
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1080 self.checkequal('', 'abc', '__getitem__', slice(0, 0))
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1081
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1082 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
1083
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1084 def test_slice(self):
43100
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1085 self.checkequal('abc', 'abc', '__getitem__', slice(0, 1000))
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1086 self.checkequal('abc', 'abc', '__getitem__', slice(0, 3))
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1087 self.checkequal('ab', 'abc', '__getitem__', slice(0, 2))
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1088 self.checkequal('bc', 'abc', '__getitem__', slice(1, 3))
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1089 self.checkequal('b', 'abc', '__getitem__', slice(1, 2))
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1090 self.checkequal('', 'abc', '__getitem__', slice(2, 2))
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1091 self.checkequal('', 'abc', '__getitem__', slice(1000, 1000))
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1092 self.checkequal('', 'abc', '__getitem__', slice(2000, 1000))
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1093 self.checkequal('', 'abc', '__getitem__', slice(2, 1))
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1094
43100
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1095 self.checkraises(TypeError, 'abc', '__getitem__', 'def')
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1096
42954
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1097 def test_extended_getslice(self):
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1098 # Test extended slicing by comparing with list slicing.
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1099 s = string.ascii_letters + string.digits
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1100 indices = (0, None, 1, 3, 41, -1, -2, -37)
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1101 for start in indices:
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1102 for stop in indices:
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1103 # Skip step 0 (invalid)
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1104 for step in indices[1:]:
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1105 L = list(s)[start:stop:step]
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1106 self.checkequal("".join(L), s, '__getitem__',
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1107 slice(start, stop, step))
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1108
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1109 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
1110 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
1111 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
1112 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
1113 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
1114 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
1115 self.checkraises(TypeError, 'abc', '__mul__', '')
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35758
diff changeset
1116 # 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
1117 # 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
1118 #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
1119
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1120 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
1121 # 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
1122 # 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
1123 # 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
1124 # 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
1125 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
1126 self.checkequal('abcd', '', 'join', ('a', 'b', 'c', 'd'))
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1127 self.checkequal('bd', '', 'join', ('', 'b', '', 'd'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1128 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
1129 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
1130 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
1131 self.checkequal('z', 'a', 'join', UserList(['z']))
41620
6b7d1782a574 test_unicode.py passes again 9except for problems
Walter Dörwald <walter@livinglogic.de>
parents: 41575
diff changeset
1132 self.checkequal('a.b.c', '.', 'join', ['a', 'b', 'c'])
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1133 self.assertRaises(TypeError, '.'.join, ['a', 'b', 3])
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1134 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
1135 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
1136 ['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
1137 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
1138 ('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
1139
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1140 #self.checkequal(str(BadSeq1()), ' ', 'join', BadSeq1())
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1141 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
1142
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1143 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
1144 self.checkraises(TypeError, ' ', 'join', 7)
43446
a7c48ab809ec Patch # 1145 by Thomas Lee:
Guido van Rossum <guido@python.org>
parents: 43100
diff changeset
1145 self.checkraises(TypeError, ' ', 'join', [1, 2, bytes()])
35758
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1146 try:
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1147 def f():
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1148 yield 4 + ""
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1149 self.fixtype(' ').join(f())
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
1150 except TypeError as e:
35758
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1151 if '+' not in str(e):
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1152 self.fail('join() ate exception message')
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1153 else:
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1154 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
1155
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1156 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
1157 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
1158 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
1159 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
1160 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
1161 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
1162 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
1163 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
1164 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
1165
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1166 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
1167 # 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
1168 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
1169
45504
1b6fb5699634 Merged revisions 61034-61036,61038-61048 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45302
diff changeset
1170 longvalue = sys.maxsize + 10
1b6fb5699634 Merged revisions 61034-61036,61038-61048 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45302
diff changeset
1171 slongvalue = str(longvalue)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1172 self.checkequal(' 42', '%3ld', '__mod__', 42)
45504
1b6fb5699634 Merged revisions 61034-61036,61038-61048 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45302
diff changeset
1173 self.checkequal('42', '%d', '__mod__', 42.0)
1b6fb5699634 Merged revisions 61034-61036,61038-61048 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45302
diff changeset
1174 self.checkequal(slongvalue, '%d', '__mod__', longvalue)
1b6fb5699634 Merged revisions 61034-61036,61038-61048 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45302
diff changeset
1175 self.checkcall('%d', '__mod__', float(longvalue))
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1176 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
1177 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
1178
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1179 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
1180 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
1181 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
1182 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
1183 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
1184 self.checkraises(TypeError, '%(foo)s %(bar)s', '__mod__', ('foo', 42))
45504
1b6fb5699634 Merged revisions 61034-61036,61038-61048 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45302
diff changeset
1185 self.checkraises(TypeError, '%d', '__mod__', "42") # not numeric
57582
1c92fbb3baf2 Issue #7435: Remove duplicate int/long tests, and other
Mark Dickinson <dickinsm@gmail.com>
parents: 53640
diff changeset
1186 self.checkraises(TypeError, '%d', '__mod__', (42+0j)) # no int conversion provided
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1187
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1188 # 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
1189 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
1190
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1191 # 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
1192 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
1193
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1194 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
1195 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
1196 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
1197
76817
064c2d0483f8 Issue #14700: Fix two broken and undefined-behaviour-inducing overflow checks in old-style string formatting. Thanks Serhiy Storchaka for report and original patch.
Mark Dickinson <mdickinson@enthought.com>
parents: 75291
diff changeset
1198 # Outrageously large width or precision should raise ValueError.
064c2d0483f8 Issue #14700: Fix two broken and undefined-behaviour-inducing overflow checks in old-style string formatting. Thanks Serhiy Storchaka for report and original patch.
Mark Dickinson <mdickinson@enthought.com>
parents: 75291
diff changeset
1199 self.checkraises(ValueError, '%%%df' % (2**64), '__mod__', (3.2))
064c2d0483f8 Issue #14700: Fix two broken and undefined-behaviour-inducing overflow checks in old-style string formatting. Thanks Serhiy Storchaka for report and original patch.
Mark Dickinson <mdickinson@enthought.com>
parents: 75291
diff changeset
1200 self.checkraises(ValueError, '%%.%df' % (2**64), '__mod__', (3.2))
064c2d0483f8 Issue #14700: Fix two broken and undefined-behaviour-inducing overflow checks in old-style string formatting. Thanks Serhiy Storchaka for report and original patch.
Mark Dickinson <mdickinson@enthought.com>
parents: 75291
diff changeset
1201
81587
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1202 self.checkraises(OverflowError, '%*s', '__mod__',
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1203 (_testcapi.PY_SSIZE_T_MAX + 1, ''))
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1204 self.checkraises(OverflowError, '%.*f', '__mod__',
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1205 (_testcapi.INT_MAX + 1, 1. / 7))
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1206 # Issue 15989
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1207 self.checkraises(OverflowError, '%*s', '__mod__',
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1208 (1 << (_testcapi.PY_SSIZE_T_MAX.bit_length() + 1), ''))
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1209 self.checkraises(OverflowError, '%.*f', '__mod__',
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1210 (_testcapi.UINT_MAX + 1, 1. / 7))
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1211
78793
4d431e719646 use the stricter PyMapping_Check (closes #15801)
Benjamin Peterson <benjamin@python.org>
parents: 71866
diff changeset
1212 class X(object): pass
4d431e719646 use the stricter PyMapping_Check (closes #15801)
Benjamin Peterson <benjamin@python.org>
parents: 71866
diff changeset
1213 self.checkraises(TypeError, 'abc', '__mod__', X())
4d431e719646 use the stricter PyMapping_Check (closes #15801)
Benjamin Peterson <benjamin@python.org>
parents: 71866
diff changeset
1214
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1215 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
1216 # float formatting
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41620
diff changeset
1217 for prec in range(100):
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1218 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
1219 value = 0.01
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41620
diff changeset
1220 for x in range(60):
64694
1e89b5ee02f8 Reenable test_ucs4 and remove some duplicated lines.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58476
diff changeset
1221 value = value * 3.14159265359 / 3.0 * 10.0
53640
e08e80e768c1 Issue #5859: Remove use of fixed-length buffers for float formatting
Mark Dickinson <dickinsm@gmail.com>
parents: 49310
diff changeset
1222 self.checkcall(format, "__mod__", value)
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1223
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1224 def test_inplace_rewrites(self):
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1225 # Check that strings don't copy and modify cached single-character strings
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1226 self.checkequal('a', 'A', 'lower')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1227 self.checkequal(True, 'A', 'isupper')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1228 self.checkequal('A', 'a', 'upper')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1229 self.checkequal(True, 'a', 'islower')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1230
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1231 self.checkequal('a', 'A', 'replace', 'A', 'a')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1232 self.checkequal(True, 'A', 'isupper')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1233
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1234 self.checkequal('A', 'a', 'capitalize')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1235 self.checkequal(True, 'a', 'islower')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1236
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1237 self.checkequal('A', 'a', 'swapcase')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1238 self.checkequal(True, 'a', 'islower')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1239
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1240 self.checkequal('A', 'a', 'title')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1241 self.checkequal(True, 'a', 'islower')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1242
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1243 def test_partition(self):
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1244
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1245 self.checkequal(('this is the par', 'ti', 'tion method'),
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1246 'this is the partition method', 'partition', 'ti')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1247
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1248 # from raymond's original specification
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1249 S = 'http://www.python.org'
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1250 self.checkequal(('http', '://', 'www.python.org'), S, 'partition', '://')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1251 self.checkequal(('http://www.python.org', '', ''), S, 'partition', '?')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1252 self.checkequal(('', 'http://', 'www.python.org'), S, 'partition', 'http://')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1253 self.checkequal(('http://www.python.', 'org', ''), S, 'partition', 'org')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1254
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1255 self.checkraises(ValueError, S, 'partition', '')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1256 self.checkraises(TypeError, S, 'partition', None)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1257
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1258 def test_rpartition(self):
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1259
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1260 self.checkequal(('this is the rparti', 'ti', 'on method'),
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1261 'this is the rpartition method', 'rpartition', 'ti')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1262
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1263 # from raymond's original specification
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1264 S = 'http://www.python.org'
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1265 self.checkequal(('http', '://', 'www.python.org'), S, 'rpartition', '://')
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39442
diff changeset
1266 self.checkequal(('', '', 'http://www.python.org'), S, 'rpartition', '?')
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1267 self.checkequal(('', 'http://', 'www.python.org'), S, 'rpartition', 'http://')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1268 self.checkequal(('http://www.python.', 'org', ''), S, 'rpartition', 'org')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1269
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1270 self.checkraises(ValueError, S, 'rpartition', '')
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1271 self.checkraises(TypeError, S, 'rpartition', None)
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1272
69472
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1273 def test_none_arguments(self):
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1274 # issue 11828
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1275 s = 'hello'
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1276 self.checkequal(2, s, 'find', 'l', None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1277 self.checkequal(3, s, 'find', 'l', -2, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1278 self.checkequal(2, s, 'find', 'l', None, -2)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1279 self.checkequal(0, s, 'find', 'h', None, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1280
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1281 self.checkequal(3, s, 'rfind', 'l', None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1282 self.checkequal(3, s, 'rfind', 'l', -2, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1283 self.checkequal(2, s, 'rfind', 'l', None, -2)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1284 self.checkequal(0, s, 'rfind', 'h', None, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1285
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1286 self.checkequal(2, s, 'index', 'l', None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1287 self.checkequal(3, s, 'index', 'l', -2, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1288 self.checkequal(2, s, 'index', 'l', None, -2)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1289 self.checkequal(0, s, 'index', 'h', None, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1290
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1291 self.checkequal(3, s, 'rindex', 'l', None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1292 self.checkequal(3, s, 'rindex', 'l', -2, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1293 self.checkequal(2, s, 'rindex', 'l', None, -2)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1294 self.checkequal(0, s, 'rindex', 'h', None, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1295
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1296 self.checkequal(2, s, 'count', 'l', None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1297 self.checkequal(1, s, 'count', 'l', -2, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1298 self.checkequal(1, s, 'count', 'l', None, -2)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1299 self.checkequal(0, s, 'count', 'x', None, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1300
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1301 self.checkequal(True, s, 'endswith', 'o', None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1302 self.checkequal(True, s, 'endswith', 'lo', -2, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1303 self.checkequal(True, s, 'endswith', 'l', None, -2)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1304 self.checkequal(False, s, 'endswith', 'x', None, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1305
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1306 self.checkequal(True, s, 'startswith', 'h', None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1307 self.checkequal(True, s, 'startswith', 'l', -2, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1308 self.checkequal(True, s, 'startswith', 'h', None, -2)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1309 self.checkequal(False, s, 'startswith', 'x', None, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1310
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1311 def test_find_etc_raise_correct_error_messages(self):
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1312 # issue 11828
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1313 s = 'hello'
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1314 x = 'x'
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1315 self.assertRaisesRegex(TypeError, r'^find\(', s.find,
69472
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1316 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1317 self.assertRaisesRegex(TypeError, r'^rfind\(', s.rfind,
69472
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1318 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1319 self.assertRaisesRegex(TypeError, r'^index\(', s.index,
69472
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1320 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1321 self.assertRaisesRegex(TypeError, r'^rindex\(', s.rindex,
69472
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1322 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1323 self.assertRaisesRegex(TypeError, r'^count\(', s.count,
69472
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1324 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1325 self.assertRaisesRegex(TypeError, r'^startswith\(', s.startswith,
69472
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1326 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1327 self.assertRaisesRegex(TypeError, r'^endswith\(', s.endswith,
69472
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1328 x, None, None, None)
77c657e47b5c startswith and endswith don't accept None as slice index. Patch by Torsten Becker. (closes #11828)
Jesus Cea <jcea@jcea.es>
parents: 66340
diff changeset
1329
78386
0e95b61af859 Close #15534: Fix a typo in the fast search function of the string library (_s => s)
Victor Stinner <victor.stinner@gmail.com>
parents: 76817
diff changeset
1330 # issue #15534
0e95b61af859 Close #15534: Fix a typo in the fast search function of the string library (_s => s)
Victor Stinner <victor.stinner@gmail.com>
parents: 76817
diff changeset
1331 self.checkequal(10, "...\u043c......<", "find", "<")
0e95b61af859 Close #15534: Fix a typo in the fast search function of the string library (_s => s)
Victor Stinner <victor.stinner@gmail.com>
parents: 76817
diff changeset
1332
33298
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1333
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1334 class MixinStrUnicodeTest:
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1335 # 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
1336
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1337 def test_bug1001011(self):
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1338 # 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
1339 # involving a subclass.
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1340 # Make sure that it is of the appropriate type.
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1341 # 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
1342 t = self.type2test
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1343 class subclass(t):
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1344 pass
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1345 s1 = subclass("abcd")
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1346 s2 = t().join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1347 self.assertIsNot(s1, s2)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1348 self.assertIs(type(s2), t)
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1349
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1350 s1 = t("abcd")
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1351 s2 = t().join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1352 self.assertIs(s1, s2)
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1353
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1354 # Should also test mixed-type join.
41575
beacf40b5960 Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents: 41554
diff changeset
1355 if t is str:
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1356 s1 = subclass("abcd")
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1357 s2 = "".join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1358 self.assertIsNot(s1, s2)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1359 self.assertIs(type(s2), t)
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1360
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1361 s1 = t("abcd")
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1362 s2 = "".join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1363 self.assertIs(s1, s2)
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1364
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1365 ## elif t is str8:
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1366 ## s1 = subclass("abcd")
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1367 ## s2 = "".join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1368 ## self.assertIsNot(s1, s2)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1369 ## self.assertIs(type(s2), str) # promotes!
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1370
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1371 ## s1 = t("abcd")
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1372 ## s2 = "".join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1373 ## self.assertIsNot(s1, s2)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1374 ## self.assertIs(type(s2), str) # promotes!
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1375
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1376 else:
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1377 self.fail("unexpected type for MixinStrUnicodeTest %r" % t)