annotate Lib/test/string_tests.py @ 84007:dbfbdf2b5c19 3.3

Fix #17967: For ftp urls CWD to target instead of hopping to each directory towards target. This fixes a bug where target is accessible, but parent directories are restricted.
author Senthil Kumaran <senthil@uthcode.com>
date Sat, 01 Jun 2013 08:27:06 -0700
parents 1e60a75e4e42
children f22e82d7be97
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):
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
331 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs')
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
332 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
333 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 4)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
334 self.checkequal('abc\r\nab def\ng hi', 'abc\r\nab\tdef\ng\thi', 'expandtabs', 4)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
335 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs')
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
336 self.checkequal('abc\rab def\ng hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
337 self.checkequal('abc\r\nab\r\ndef\ng\r\nhi', 'abc\r\nab\r\ndef\ng\r\nhi', 'expandtabs', 4)
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
338 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
339
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41993
diff changeset
340 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
341 # 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
342 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
343 self.checkraises(OverflowError,
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
344 '\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
345
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
346 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
347 # by a char
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
348 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
349 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
350 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
351 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
352 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
353 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
354 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
355 sys.maxsize-2)
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
356 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
357 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
358 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
359 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
360 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
361 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
362
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
363 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
364 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
365 ('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
366
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
367 # 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
368 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
369 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
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(['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
372 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
373 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
374 sys.maxsize-10)
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
375 self.checkequal(['a//b//c//d'], 'a//b//c//d', 'split', '//', 0)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
376 self.checkequal(['a', '', 'b////c////d'], 'a////b////c////d', '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
377 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
378 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
379 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
380 '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
381 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
382 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
383 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
384 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
385 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
386 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
387 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
388 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
389 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
390
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(['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
392 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
393 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
394 '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
395
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
396 # 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
397 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
398 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
399 '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
400 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
401 '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
402 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
403 '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
404 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
405 '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
406
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
407 # 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
408 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
409
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
410 # 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
411 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
412 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
413
31199
504943c89193 Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31021
diff changeset
414 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
415 # by a char
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
416 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
417 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
418 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
419 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
420 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
421 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
422 sys.maxsize-100)
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
423 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
424 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
425 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
426 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
427 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
428
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
429 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
430
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
431 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
432 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
433 ('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
434
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
435 # by string
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', '//')
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', '//', 1)
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
438 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
439 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
440 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
441 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
442 sys.maxsize-5)
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
443 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
444 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
445 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
446 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
447 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
448 '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
449 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
450 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
451 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
452 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
453 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
454 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
455 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
456 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
457 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
458
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(['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
460 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
461 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
462 'rsplit', 'BLAH', 18)
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
463
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
464 # 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
465 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
466 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
467 '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
468 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
469 '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
470 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
471 '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
472 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
473 '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
474
31350
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
475 # argument type
eaa1a4b74328 [SF #866875] Add a specialized routine for one character
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31252
diff changeset
476 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
477
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
478 # 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
479 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
480 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
481
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
482 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
483 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
484
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
485 # 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
486 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
487 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
488 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
489 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
490 EQ("", "", "replace", "", "", 100)
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
491 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
492
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
493 # 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
494 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
495 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
496 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
497 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
498 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
499 EQ("*-A*-A*-", "AA", "replace", "", "*-", -1)
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
500 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
501 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
502 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
503 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
504 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
505 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
506
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
507 # 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
508 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
509 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
510 EQ("", "AAA", "replace", "A", "", -1)
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
511 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
512 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
513 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
514 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
515 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
516 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
517 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
518 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
519 EQ("BCD", "ABACADA", "replace", "A", "", -1)
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
520 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
521 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
522 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
523 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
524 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
525 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
526 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
527 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
528 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
529 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
530 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
531 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
532
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
533 # 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
534 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
535 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
536 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
537 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
538 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
539 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
540 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
541 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
542 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
543 "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
544 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
545 "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
546 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
547 "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
548 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
549 "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
550 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
551 "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
552 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
553 "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
554 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
555
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
556 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
557 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
558
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
559 # 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
560 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
561 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
562 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
563 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
564
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
565 # 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
566 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
567 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
568 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
569 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
570 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
571 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
572 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
573 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
574
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("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
576 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
577 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
578 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
579 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
580
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
581 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
582
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
583 # 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
584 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
585 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
586 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
587 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
588 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
589 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
590 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
591 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
592 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
593 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
594 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
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 # 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
597 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
598 EQ("ReyKKjaviKK", "Reykjavik", "replace", "k", "KK", -1)
44160
9d152530910a Removed PyInt_GetMax and sys.maxint
Christian Heimes <christian@cheimes.de>
parents: 43963
diff changeset
599 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
600 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
601 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
602 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
603 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
604 # 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
605 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
606
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("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
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 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
610 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
611 "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
612 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
613 "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
614 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
615 "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
616 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
617 "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
618 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
619 "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
620 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
621 "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
622 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
623 "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
624 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
625 "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
626
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("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
628 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
629 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
630
42902
62874b34d95d Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42088
diff changeset
631 # 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
632 # as arguments for str.replace()? GvR
43947
cbc8b3bd3157 Rename buffer -> bytearray.
Guido van Rossum <guido@python.org>
parents: 43897
diff changeset
633 ## ba = bytearray('a')
cbc8b3bd3157 Rename buffer -> bytearray.
Guido van Rossum <guido@python.org>
parents: 43897
diff changeset
634 ## bb = bytearray('b')
42902
62874b34d95d Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents: 42088
diff changeset
635 ## 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
636 ## EQ("aac", "abc", "replace", bb, ba)
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
637
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
638 #
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
639 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
640 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
641 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
642 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
643 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
644 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
645 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
646 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
647 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
648 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
649 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
650 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
651 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
652 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
653 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
654 # 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
655 # 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
656 # 0 bytes).
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('', '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
658 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
659 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
660
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
661 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
662 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
663 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
664 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
665
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
666 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
667 # 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
668 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
669 return
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
670 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
671 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
672 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
673 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
674
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
675
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
676
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
677 class CommonTest(BaseTest):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
678 # 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
679 # 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
680 # UserString and the string module.
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
681
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
682 def test_hash(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
683 # 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
684 a = self.type2test('DNSSEC')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
685 b = self.type2test('')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
686 for c in a:
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
687 b += c
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
688 hash(b)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
689 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
690
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
691 def test_capitalize(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
692 self.checkequal(' hello ', ' hello ', 'capitalize')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
693 self.checkequal('Hello ', 'Hello ','capitalize')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
694 self.checkequal('Hello ', 'hello ','capitalize')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
695 self.checkequal('Aaaa', 'aaaa', 'capitalize')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
696 self.checkequal('Aaaa', 'AaAa', 'capitalize')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
697
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
698 # 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
699 # \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
700 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
701 '\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
702 # 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
703 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
704 '\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
705 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
706 '\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
707 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
708 '\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
709 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
710 '\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
711 # 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
712 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
713 '\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
714
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
715 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
716
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
717 def test_additional_split(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
718 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
719 '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
720
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
721 # by whitespace
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
722 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
723 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
724 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
725 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
726 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
727 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
728 sys.maxsize-1)
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
729 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
730 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
731 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
732
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
733 self.checkequal([], ' ', 'split')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
734 self.checkequal(['a'], ' a ', 'split')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
735 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
736 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
737 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
738 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
739 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
740 aaa = ' a '*20
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
741 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
742 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
743 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
744
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
745 # 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
746 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
747
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
748 def test_additional_rsplit(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
749 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
750 '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
751
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
752 # by whitespace
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
753 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
754 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
755 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
756 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
757 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
758 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
759 sys.maxsize-20)
41038
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
760 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
761 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
762 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
763
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
764 self.checkequal([], ' ', 'rsplit')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
765 self.checkequal(['a'], ' a ', 'rsplit')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
766 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
767 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
768 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
769 None, 1)
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'], ' a b c ', 'rsplit',
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
771 None, 2)
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
772 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
773 aaa = ' a '*20
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
774 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
775 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
776 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
777
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
778 # 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
779 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
780
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
781 def test_strip(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
782 self.checkequal('hello', ' hello ', 'strip')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
783 self.checkequal('hello ', ' hello ', 'lstrip')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
784 self.checkequal(' hello', ' hello ', 'rstrip')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
785 self.checkequal('hello', 'hello', 'strip')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
786
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
787 # 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
788 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
789 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
790 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
791 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
792
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
793 # 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
794 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
795 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
796 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
797 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
798
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
799 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
800 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
801 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
802
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
803 def test_ljust(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
804 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
805 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
806 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
807 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
808 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
809 self.checkraises(TypeError, 'abc', 'ljust')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
810
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
811 def test_rjust(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
812 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
813 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
814 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
815 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
816 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
817 self.checkraises(TypeError, 'abc', 'rjust')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
818
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
819 def test_center(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
820 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
821 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
822 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
823 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
824 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
825 self.checkraises(TypeError, 'abc', 'center')
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
826
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
827 def test_swapcase(self):
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
828 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
829
efa0a761918c Addendum of patch #1669633: additional tests for bytes methods.
Georg Brandl <georg@python.org>
parents: 40809
diff changeset
830 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
831
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
832 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
833 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
834 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
835 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
836 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
837 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
838 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
839 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
840 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
841 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
842 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
843 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
844 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
845
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
846 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
847
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
848 class MixinStrUnicodeUserStringTest:
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
849 # 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
850 # 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
851 # (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
852
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
853 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
854 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
855 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
856 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
857 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
858 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
859 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
860 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
861 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
862
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
863 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
864 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
865 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
866 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
867 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
868 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
869 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
870 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
871 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
872
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
873 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
874 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
875 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
876 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
877 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
878 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
879 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
880 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
881 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
882 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
883 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
884 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
885 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
886
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
887 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
888 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
889 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
890 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
891 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
892 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
893 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
894 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
895 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
896 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
897
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
898 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
899 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
900 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
901 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
902 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
903 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
904 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
905 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
906 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
907
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
908 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
909 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
910 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
911 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
912 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
913 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
914 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
915 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
916 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
917 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
918
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
919 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
920 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
921 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
922 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
923 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
924 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
925
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
926 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
927
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
928 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
929 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
930 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
931 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
932 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
933 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
934 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
935 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
936
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
937 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
938 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
939 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
940 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
941 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
942 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
943 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
944 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
945 "\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
946 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
947 "\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
948 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
949 '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
950 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
951 "\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
952
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
953 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
954
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
955 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
956 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
957 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
958 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
959 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
960 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
961 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
962 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
963 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
964 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
965 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
966 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
967 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
968 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
969
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
970 # 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
971 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
972 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
973 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
974 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
975 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
976 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
977 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
978 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
979 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
980 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
981
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
982 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
983 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
984
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
985 # test tuple arguments
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
986 self.checkequal(True, 'hello', 'startswith', ('he', 'ha'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
987 self.checkequal(False, 'hello', 'startswith', ('lo', 'llo'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
988 self.checkequal(True, 'hello', 'startswith', ('hellox', 'hello'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
989 self.checkequal(False, 'hello', 'startswith', ())
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
990 self.checkequal(True, 'helloworld', 'startswith', ('hellowo',
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
991 'rld', 'lowo'), 3)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
992 self.checkequal(False, 'helloworld', 'startswith', ('hellowo', 'ello',
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
993 'rld'), 3)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
994 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
995 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
996 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
997
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
998 self.checkraises(TypeError, 'hello', 'startswith', (42,))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
999
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1000 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
1001 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
1002 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
1003 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
1004 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
1005 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
1006 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
1007 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
1008 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
1009 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
1010 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
1011 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
1012 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
1013 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
1014 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
1015
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1016 # 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
1017 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
1018 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
1019 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
1020 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
1021 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
1022 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
1023 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
1024 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
1025 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
1026 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
1027 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
1028 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
1029 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
1030
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1031 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
1032 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
1033
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1034 # test tuple arguments
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1035 self.checkequal(False, 'hello', 'endswith', ('he', 'ha'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1036 self.checkequal(True, 'hello', 'endswith', ('lo', 'llo'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1037 self.checkequal(True, 'hello', 'endswith', ('hellox', 'hello'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1038 self.checkequal(False, 'hello', 'endswith', ())
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1039 self.checkequal(True, 'helloworld', 'endswith', ('hellowo',
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1040 'rld', 'lowo'), 3)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1041 self.checkequal(False, 'helloworld', 'endswith', ('hellowo', 'ello',
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1042 'rld'), 3, -1)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1043 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
1044 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
1045 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
1046
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1047 self.checkraises(TypeError, 'hello', 'endswith', (42,))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1048
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1049 def test___contains__(self):
58477
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1050 self.checkequal(True, '', '__contains__', '')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1051 self.checkequal(True, 'abc', '__contains__', '')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1052 self.checkequal(False, 'abc', '__contains__', '\0')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1053 self.checkequal(True, '\0abc', '__contains__', '\0')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1054 self.checkequal(True, 'abc\0', '__contains__', '\0')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1055 self.checkequal(True, '\0abc', '__contains__', 'a')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1056 self.checkequal(True, 'asdf', '__contains__', 'asdf')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1057 self.checkequal(False, 'asd', '__contains__', 'asdf')
ffb94920eff3 Merged revisions 77731 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 53640
diff changeset
1058 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
1059
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1060 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
1061 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
1062 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
1063 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
1064 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
1065 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
1066 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
1067 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
1068
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1069 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
1070
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1071 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
1072 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
1073 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
1074 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
1075 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
1076 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
1077 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
1078 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
1079 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
1080 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
1081
43100
4e6b4ba60c3b Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents: 42954
diff changeset
1082 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
1083
42954
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1084 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
1085 # 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
1086 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
1087 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
1088 for start in indices:
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1089 for stop in indices:
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1090 # Skip step 0 (invalid)
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1091 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
1092 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
1093 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
1094 slice(start, stop, step))
27f0289b6835 Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents: 42911
diff changeset
1095
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1096 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
1097 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
1098 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
1099 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
1100 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
1101 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
1102 self.checkraises(TypeError, 'abc', '__mul__', '')
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35758
diff changeset
1103 # 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
1104 # 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
1105 #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
1106
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1107 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
1108 # 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
1109 # 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
1110 # 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
1111 # 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
1112 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
1113 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
1114 self.checkequal('bd', '', 'join', ('', 'b', '', 'd'))
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1115 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
1116 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
1117 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
1118 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
1119 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
1120 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
1121 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
1122 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
1123 ['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
1124 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
1125 ('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
1126
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1127 #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
1128 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
1129
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1130 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
1131 self.checkraises(TypeError, ' ', 'join', 7)
43446
a7c48ab809ec Patch # 1145 by Thomas Lee:
Guido van Rossum <guido@python.org>
parents: 43100
diff changeset
1132 self.checkraises(TypeError, ' ', 'join', [1, 2, bytes()])
35758
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1133 try:
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1134 def f():
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1135 yield 4 + ""
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1136 self.fixtype(' ').join(f())
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
1137 except TypeError as e:
35758
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1138 if '+' not in str(e):
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1139 self.fail('join() ate exception message')
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1140 else:
e0e320f36c93 Fix bug:
Michael W. Hudson <mwh@python.net>
parents: 35287
diff changeset
1141 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
1142
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1143 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
1144 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
1145 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
1146 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
1147 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
1148 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
1149 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
1150 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
1151 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
1152
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1153 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
1154 # 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
1155 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
1156
45504
1b6fb5699634 Merged revisions 61034-61036,61038-61048 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45302
diff changeset
1157 longvalue = sys.maxsize + 10
1b6fb5699634 Merged revisions 61034-61036,61038-61048 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45302
diff changeset
1158 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
1159 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
1160 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
1161 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
1162 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
1163 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
1164 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
1165
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1166 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
1167 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
1168 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
1169 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
1170 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
1171 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
1172 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
1173 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
1174
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1175 # 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
1176 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
1177
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1178 # 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
1179 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
1180
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', '__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
1182 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
1183 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
1184
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
1185 # 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
1186 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
1187 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
1188
81587
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1189 self.checkraises(OverflowError, '%*s', '__mod__',
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1190 (_testcapi.PY_SSIZE_T_MAX + 1, ''))
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1191 self.checkraises(OverflowError, '%.*f', '__mod__',
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1192 (_testcapi.INT_MAX + 1, 1. / 7))
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1193 # Issue 15989
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1194 self.checkraises(OverflowError, '%*s', '__mod__',
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1195 (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
1196 self.checkraises(OverflowError, '%.*f', '__mod__',
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1197 (_testcapi.UINT_MAX + 1, 1. / 7))
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 78793
diff changeset
1198
78793
4d431e719646 use the stricter PyMapping_Check (closes #15801)
Benjamin Peterson <benjamin@python.org>
parents: 71866
diff changeset
1199 class X(object): pass
4d431e719646 use the stricter PyMapping_Check (closes #15801)
Benjamin Peterson <benjamin@python.org>
parents: 71866
diff changeset
1200 self.checkraises(TypeError, 'abc', '__mod__', X())
4d431e719646 use the stricter PyMapping_Check (closes #15801)
Benjamin Peterson <benjamin@python.org>
parents: 71866
diff changeset
1201
28009
fe10ece8ba68 Port all string tests to PyUnit and share as much tests
Walter Dörwald <walter@livinglogic.de>
parents: 26625
diff changeset
1202 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
1203 # float formatting
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41620
diff changeset
1204 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
1205 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
1206 value = 0.01
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41620
diff changeset
1207 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
1208 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
1209 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
1210
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1211 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
1212 # 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
1213 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
1214 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
1215 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
1216 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
1217
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1218 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
1219 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
1220
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1221 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
1222 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
1223
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1224 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
1225 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
1226
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('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
1228 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
1229
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1230 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
1231
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(('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
1233 '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
1234
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1235 # 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
1236 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
1237 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
1238 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
1239 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
1240 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
1241
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1242 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
1243 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
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 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
1246
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1247 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
1248 '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
1249
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1250 # 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
1251 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
1252 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
1253 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
1254 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
1255 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
1256
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
1257 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
1258 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
1259
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
1260 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
1261 # 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
1262 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
1263 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
1264 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
1265 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
1266 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
1267
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
1268 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
1269 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
1270 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
1271 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
1272
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 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
1274 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
1275 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
1276 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
1277
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(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
1279 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
1280 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
1281 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
1282
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, '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
1284 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
1285 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
1286 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
1287
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(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
1289 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
1290 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
1291 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
1292
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(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
1294 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
1295 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
1296 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
1297
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 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
1299 # 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
1300 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
1301 x = 'x'
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1302 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
1303 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1304 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
1305 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1306 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
1307 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1308 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
1309 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1310 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
1311 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1312 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
1313 x, None, None, None)
69479
87f9519203f4 Use non-deprecated method name.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69473
diff changeset
1314 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
1315 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
1316
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
1317 # 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
1318 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
1319
33298
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1320
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1321 class MixinStrUnicodeTest:
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1322 # 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
1323
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1324 def test_bug1001011(self):
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1325 # 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
1326 # involving a subclass.
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1327 # Make sure that it is of the appropriate type.
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1328 # 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
1329 t = self.type2test
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1330 class subclass(t):
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1331 pass
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1332 s1 = subclass("abcd")
a37ae7dba814 Move test_bug1001011() to string_tests.MixinStrUnicodeTest so that
Walter Dörwald <walter@livinglogic.de>
parents: 32951
diff changeset
1333 s2 = t().join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1334 self.assertIsNot(s1, s2)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1335 self.assertIs(type(s2), t)
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1336
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1337 s1 = t("abcd")
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1338 s2 = t().join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1339 self.assertIs(s1, s2)
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1340
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1341 # 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
1342 if t is str:
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1343 s1 = subclass("abcd")
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1344 s2 = "".join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1345 self.assertIsNot(s1, s2)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1346 self.assertIs(type(s2), t)
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1347
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1348 s1 = t("abcd")
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1349 s2 = "".join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1350 self.assertIs(s1, s2)
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1351
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1352 ## 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
1353 ## s1 = subclass("abcd")
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1354 ## s2 = "".join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1355 ## self.assertIsNot(s1, s2)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1356 ## self.assertIs(type(s2), str) # promotes!
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1357
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1358 ## s1 = t("abcd")
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43604
diff changeset
1359 ## s2 = "".join([s1])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1360 ## self.assertIsNot(s1, s2)
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58477
diff changeset
1361 ## self.assertIs(type(s2), str) # promotes!
33305
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1362
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1363 else:
78b578c46770 test_bug1001011(): Verify that
Tim Peters <tim.peters@gmail.com>
parents: 33298
diff changeset
1364 self.fail("unexpected type for MixinStrUnicodeTest %r" % t)