annotate Lib/test/test_bigmem.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents c4d24fc8ba8a
children 51102abdec50 6768b2350c57
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38197
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1 from test import test_support
48114
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
2 from test.test_support import bigmemtest, _1G, _2G, _4G, precisionbigmemtest
38197
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
3
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
4 import unittest
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
5 import operator
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
6 import string
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
7 import sys
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
8
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
9 # Bigmem testing houserules:
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
10 #
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
11 # - Try not to allocate too many large objects. It's okay to rely on
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
12 # refcounting semantics, but don't forget that 's = create_largestring()'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
13 # doesn't release the old 's' (if it exists) until well after its new
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
14 # value has been created. Use 'del s' before the create_largestring call.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
15 #
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
16 # - Do *not* compare large objects using assertEquals or similar. It's a
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
17 # lengty operation and the errormessage will be utterly useless due to
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
18 # its size. To make sure whether a result has the right contents, better
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
19 # to use the strip or count methods, or compare meaningful slices.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
20 #
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
21 # - Don't forget to test for large indices, offsets and results and such,
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
22 # in addition to large sizes.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
23 #
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
24 # - When repeating an object (say, a substring, or a small list) to create
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
25 # a large object, make the subobject of a length that is not a power of
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
26 # 2. That way, int-wrapping problems are more easily detected.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
27 #
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
28 # - While the bigmemtest decorator speaks of 'minsize', all tests will
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
29 # actually be called with a much smaller number too, in the normal
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
30 # test run (5Kb currently.) This is so the tests themselves get frequent
38850
6b4da4ee7146 Add missing period in comment.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38197
diff changeset
31 # testing. Consequently, always make all large allocations based on the
38197
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
32 # passed-in 'size', and don't rely on the size being very large. Also,
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
33 # memuse-per-size should remain sane (less than a few thousand); if your
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
34 # test uses more, adjust 'size' upward, instead.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
35
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
36 class StrTest(unittest.TestCase):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
37 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
38 def test_capitalize(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
39 SUBSTR = ' abc def ghi'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
40 s = '-' * size + SUBSTR
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
41 caps = s.capitalize()
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
42 self.assertEquals(caps[-len(SUBSTR):],
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
43 SUBSTR.capitalize())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
44 self.assertEquals(caps.lstrip('-'), SUBSTR)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
45
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
46 @bigmemtest(minsize=_2G + 10, memuse=1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
47 def test_center(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
48 SUBSTR = ' abc def ghi'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
49 s = SUBSTR.center(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
50 self.assertEquals(len(s), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
51 lpadsize = rpadsize = (len(s) - len(SUBSTR)) // 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
52 if len(s) % 2:
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
53 lpadsize += 1
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
54 self.assertEquals(s[lpadsize:-rpadsize], SUBSTR)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
55 self.assertEquals(s.strip(), SUBSTR.strip())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
56
48114
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
57 @precisionbigmemtest(size=_2G - 1, memuse=1)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
58 def test_center_unicode(self, size):
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
59 SUBSTR = u' abc def ghi'
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
60 try:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
61 s = SUBSTR.center(size)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
62 except OverflowError:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
63 pass # acceptable on 32-bit
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
64 else:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
65 self.assertEquals(len(s), size)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
66 lpadsize = rpadsize = (len(s) - len(SUBSTR)) // 2
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
67 if len(s) % 2:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
68 lpadsize += 1
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
69 self.assertEquals(s[lpadsize:-rpadsize], SUBSTR)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
70 self.assertEquals(s.strip(), SUBSTR.strip())
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
71 del s
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
72
38197
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
73 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
74 def test_count(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
75 SUBSTR = ' abc def ghi'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
76 s = '.' * size + SUBSTR
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
77 self.assertEquals(s.count('.'), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
78 s += '.'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
79 self.assertEquals(s.count('.'), size + 1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
80 self.assertEquals(s.count(' '), 3)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
81 self.assertEquals(s.count('i'), 1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
82 self.assertEquals(s.count('j'), 0)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
83
44075
f4e7c729b3a2 Backport of r59241: str.decode fails on very long strings on 64bit platforms.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 38850
diff changeset
84 @bigmemtest(minsize=_2G + 2, memuse=3)
38197
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
85 def test_decode(self, size):
44075
f4e7c729b3a2 Backport of r59241: str.decode fails on very long strings on 64bit platforms.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 38850
diff changeset
86 s = '.' * size
f4e7c729b3a2 Backport of r59241: str.decode fails on very long strings on 64bit platforms.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 38850
diff changeset
87 self.assertEquals(len(s.decode('utf-8')), size)
38197
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
88
48114
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
89 def basic_encode_test(self, size, enc, c=u'.', expectedsize=None):
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
90 if expectedsize is None:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
91 expectedsize = size
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
92
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
93 s = c * size
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
94 self.assertEquals(len(s.encode(enc)), expectedsize)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
95
44075
f4e7c729b3a2 Backport of r59241: str.decode fails on very long strings on 64bit platforms.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 38850
diff changeset
96 @bigmemtest(minsize=_2G + 2, memuse=3)
38197
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
97 def test_encode(self, size):
48114
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
98 return self.basic_encode_test(size, 'utf-8')
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
99
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
100 @precisionbigmemtest(size=_4G / 6 + 2, memuse=2)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
101 def test_encode_raw_unicode_escape(self, size):
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
102 try:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
103 return self.basic_encode_test(size, 'raw_unicode_escape')
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
104 except MemoryError:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
105 pass # acceptable on 32-bit
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
106
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
107 @precisionbigmemtest(size=_4G / 5 + 70, memuse=3)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
108 def test_encode_utf7(self, size):
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
109 try:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
110 return self.basic_encode_test(size, 'utf7')
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
111 except MemoryError:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
112 pass # acceptable on 32-bit
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
113
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
114 @precisionbigmemtest(size=_4G / 4 + 5, memuse=6)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
115 def test_encode_utf32(self, size):
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
116 try:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
117 return self.basic_encode_test(size, 'utf32', expectedsize=4*size+4)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
118 except MemoryError:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
119 pass # acceptable on 32-bit
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
120
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
121 @precisionbigmemtest(size=_2G-1, memuse=2)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
122 def test_decodeascii(self, size):
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
123 return self.basic_encode_test(size, 'ascii', c='A')
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
124
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
125 @precisionbigmemtest(size=_4G / 5, memuse=6+2)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
126 def test_unicode_repr_oflw(self, size):
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
127 try:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
128 s = u"\uAAAA"*size
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
129 r = repr(s)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
130 except MemoryError:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
131 pass # acceptable on 32-bit
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
132 else:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
133 self.failUnless(s == eval(r))
38197
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
134
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
135 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
136 def test_endswith(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
137 SUBSTR = ' abc def ghi'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
138 s = '-' * size + SUBSTR
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
139 self.failUnless(s.endswith(SUBSTR))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
140 self.failUnless(s.endswith(s))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
141 s2 = '...' + s
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
142 self.failUnless(s2.endswith(s))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
143 self.failIf(s.endswith('a' + SUBSTR))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
144 self.failIf(SUBSTR.endswith(s))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
145
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
146 @bigmemtest(minsize=_2G + 10, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
147 def test_expandtabs(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
148 s = '-' * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
149 tabsize = 8
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
150 self.assertEquals(s.expandtabs(), s)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
151 del s
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
152 slen, remainder = divmod(size, tabsize)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
153 s = ' \t' * slen
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
154 s = s.expandtabs(tabsize)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
155 self.assertEquals(len(s), size - remainder)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
156 self.assertEquals(len(s.strip(' ')), 0)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
157
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
158 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
159 def test_find(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
160 SUBSTR = ' abc def ghi'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
161 sublen = len(SUBSTR)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
162 s = ''.join([SUBSTR, '-' * size, SUBSTR])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
163 self.assertEquals(s.find(' '), 0)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
164 self.assertEquals(s.find(SUBSTR), 0)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
165 self.assertEquals(s.find(' ', sublen), sublen + size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
166 self.assertEquals(s.find(SUBSTR, len(SUBSTR)), sublen + size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
167 self.assertEquals(s.find('i'), SUBSTR.find('i'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
168 self.assertEquals(s.find('i', sublen),
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
169 sublen + size + SUBSTR.find('i'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
170 self.assertEquals(s.find('i', size),
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
171 sublen + size + SUBSTR.find('i'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
172 self.assertEquals(s.find('j'), -1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
173
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
174 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
175 def test_index(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
176 SUBSTR = ' abc def ghi'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
177 sublen = len(SUBSTR)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
178 s = ''.join([SUBSTR, '-' * size, SUBSTR])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
179 self.assertEquals(s.index(' '), 0)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
180 self.assertEquals(s.index(SUBSTR), 0)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
181 self.assertEquals(s.index(' ', sublen), sublen + size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
182 self.assertEquals(s.index(SUBSTR, sublen), sublen + size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
183 self.assertEquals(s.index('i'), SUBSTR.index('i'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
184 self.assertEquals(s.index('i', sublen),
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
185 sublen + size + SUBSTR.index('i'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
186 self.assertEquals(s.index('i', size),
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
187 sublen + size + SUBSTR.index('i'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
188 self.assertRaises(ValueError, s.index, 'j')
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
189
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
190 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
191 def test_isalnum(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
192 SUBSTR = '123456'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
193 s = 'a' * size + SUBSTR
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
194 self.failUnless(s.isalnum())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
195 s += '.'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
196 self.failIf(s.isalnum())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
197
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
198 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
199 def test_isalpha(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
200 SUBSTR = 'zzzzzzz'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
201 s = 'a' * size + SUBSTR
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
202 self.failUnless(s.isalpha())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
203 s += '.'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
204 self.failIf(s.isalpha())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
205
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
206 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
207 def test_isdigit(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
208 SUBSTR = '123456'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
209 s = '9' * size + SUBSTR
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
210 self.failUnless(s.isdigit())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
211 s += 'z'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
212 self.failIf(s.isdigit())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
213
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
214 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
215 def test_islower(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
216 chars = ''.join([ chr(c) for c in range(255) if not chr(c).isupper() ])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
217 repeats = size // len(chars) + 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
218 s = chars * repeats
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
219 self.failUnless(s.islower())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
220 s += 'A'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
221 self.failIf(s.islower())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
222
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
223 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
224 def test_isspace(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
225 whitespace = ' \f\n\r\t\v'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
226 repeats = size // len(whitespace) + 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
227 s = whitespace * repeats
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
228 self.failUnless(s.isspace())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
229 s += 'j'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
230 self.failIf(s.isspace())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
231
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
232 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
233 def test_istitle(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
234 SUBSTR = '123456'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
235 s = ''.join(['A', 'a' * size, SUBSTR])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
236 self.failUnless(s.istitle())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
237 s += 'A'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
238 self.failUnless(s.istitle())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
239 s += 'aA'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
240 self.failIf(s.istitle())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
241
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
242 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
243 def test_isupper(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
244 chars = ''.join([ chr(c) for c in range(255) if not chr(c).islower() ])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
245 repeats = size // len(chars) + 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
246 s = chars * repeats
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
247 self.failUnless(s.isupper())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
248 s += 'a'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
249 self.failIf(s.isupper())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
250
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
251 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
252 def test_join(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
253 s = 'A' * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
254 x = s.join(['aaaaa', 'bbbbb'])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
255 self.assertEquals(x.count('a'), 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
256 self.assertEquals(x.count('b'), 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
257 self.failUnless(x.startswith('aaaaaA'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
258 self.failUnless(x.endswith('Abbbbb'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
259
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
260 @bigmemtest(minsize=_2G + 10, memuse=1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
261 def test_ljust(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
262 SUBSTR = ' abc def ghi'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
263 s = SUBSTR.ljust(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
264 self.failUnless(s.startswith(SUBSTR + ' '))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
265 self.assertEquals(len(s), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
266 self.assertEquals(s.strip(), SUBSTR.strip())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
267
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
268 @bigmemtest(minsize=_2G + 10, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
269 def test_lower(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
270 s = 'A' * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
271 s = s.lower()
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
272 self.assertEquals(len(s), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
273 self.assertEquals(s.count('a'), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
274
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
275 @bigmemtest(minsize=_2G + 10, memuse=1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
276 def test_lstrip(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
277 SUBSTR = 'abc def ghi'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
278 s = SUBSTR.rjust(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
279 self.assertEquals(len(s), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
280 self.assertEquals(s.lstrip(), SUBSTR.lstrip())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
281 del s
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
282 s = SUBSTR.ljust(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
283 self.assertEquals(len(s), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
284 stripped = s.lstrip()
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
285 self.failUnless(stripped is s)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
286
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
287 @bigmemtest(minsize=_2G + 10, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
288 def test_replace(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
289 replacement = 'a'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
290 s = ' ' * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
291 s = s.replace(' ', replacement)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
292 self.assertEquals(len(s), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
293 self.assertEquals(s.count(replacement), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
294 s = s.replace(replacement, ' ', size - 4)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
295 self.assertEquals(len(s), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
296 self.assertEquals(s.count(replacement), 4)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
297 self.assertEquals(s[-10:], ' aaaa')
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
298
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
299 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
300 def test_rfind(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
301 SUBSTR = ' abc def ghi'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
302 sublen = len(SUBSTR)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
303 s = ''.join([SUBSTR, '-' * size, SUBSTR])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
304 self.assertEquals(s.rfind(' '), sublen + size + SUBSTR.rfind(' '))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
305 self.assertEquals(s.rfind(SUBSTR), sublen + size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
306 self.assertEquals(s.rfind(' ', 0, size), SUBSTR.rfind(' '))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
307 self.assertEquals(s.rfind(SUBSTR, 0, sublen + size), 0)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
308 self.assertEquals(s.rfind('i'), sublen + size + SUBSTR.rfind('i'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
309 self.assertEquals(s.rfind('i', 0, sublen), SUBSTR.rfind('i'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
310 self.assertEquals(s.rfind('i', 0, sublen + size),
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
311 SUBSTR.rfind('i'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
312 self.assertEquals(s.rfind('j'), -1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
313
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
314 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
315 def test_rindex(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
316 SUBSTR = ' abc def ghi'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
317 sublen = len(SUBSTR)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
318 s = ''.join([SUBSTR, '-' * size, SUBSTR])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
319 self.assertEquals(s.rindex(' '),
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
320 sublen + size + SUBSTR.rindex(' '))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
321 self.assertEquals(s.rindex(SUBSTR), sublen + size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
322 self.assertEquals(s.rindex(' ', 0, sublen + size - 1),
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
323 SUBSTR.rindex(' '))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
324 self.assertEquals(s.rindex(SUBSTR, 0, sublen + size), 0)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
325 self.assertEquals(s.rindex('i'),
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
326 sublen + size + SUBSTR.rindex('i'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
327 self.assertEquals(s.rindex('i', 0, sublen), SUBSTR.rindex('i'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
328 self.assertEquals(s.rindex('i', 0, sublen + size),
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
329 SUBSTR.rindex('i'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
330 self.assertRaises(ValueError, s.rindex, 'j')
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
331
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
332 @bigmemtest(minsize=_2G + 10, memuse=1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
333 def test_rjust(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
334 SUBSTR = ' abc def ghi'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
335 s = SUBSTR.ljust(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
336 self.failUnless(s.startswith(SUBSTR + ' '))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
337 self.assertEquals(len(s), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
338 self.assertEquals(s.strip(), SUBSTR.strip())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
339
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
340 @bigmemtest(minsize=_2G + 10, memuse=1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
341 def test_rstrip(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
342 SUBSTR = ' abc def ghi'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
343 s = SUBSTR.ljust(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
344 self.assertEquals(len(s), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
345 self.assertEquals(s.rstrip(), SUBSTR.rstrip())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
346 del s
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
347 s = SUBSTR.rjust(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
348 self.assertEquals(len(s), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
349 stripped = s.rstrip()
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
350 self.failUnless(stripped is s)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
351
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
352 # The test takes about size bytes to build a string, and then about
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
353 # sqrt(size) substrings of sqrt(size) in size and a list to
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
354 # hold sqrt(size) items. It's close but just over 2x size.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
355 @bigmemtest(minsize=_2G, memuse=2.1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
356 def test_split_small(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
357 # Crudely calculate an estimate so that the result of s.split won't
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
358 # take up an inordinate amount of memory
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
359 chunksize = int(size ** 0.5 + 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
360 SUBSTR = 'a' + ' ' * chunksize
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
361 s = SUBSTR * chunksize
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
362 l = s.split()
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
363 self.assertEquals(len(l), chunksize)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
364 self.assertEquals(set(l), set(['a']))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
365 del l
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
366 l = s.split('a')
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
367 self.assertEquals(len(l), chunksize + 1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
368 self.assertEquals(set(l), set(['', ' ' * chunksize]))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
369
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
370 # Allocates a string of twice size (and briefly two) and a list of
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
371 # size. Because of internal affairs, the s.split() call produces a
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
372 # list of size times the same one-character string, so we only
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
373 # suffer for the list size. (Otherwise, it'd cost another 48 times
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
374 # size in bytes!) Nevertheless, a list of size takes
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
375 # 8*size bytes.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
376 @bigmemtest(minsize=_2G + 5, memuse=10)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
377 def test_split_large(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
378 s = ' a' * size + ' '
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
379 l = s.split()
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
380 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
381 self.assertEquals(set(l), set(['a']))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
382 del l
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
383 l = s.split('a')
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
384 self.assertEquals(len(l), size + 1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
385 self.assertEquals(set(l), set([' ']))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
386
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
387 @bigmemtest(minsize=_2G, memuse=2.1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
388 def test_splitlines(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
389 # Crudely calculate an estimate so that the result of s.split won't
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
390 # take up an inordinate amount of memory
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
391 chunksize = int(size ** 0.5 + 2) // 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
392 SUBSTR = ' ' * chunksize + '\n' + ' ' * chunksize + '\r\n'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
393 s = SUBSTR * chunksize
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
394 l = s.splitlines()
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
395 self.assertEquals(len(l), chunksize * 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
396 self.assertEquals(set(l), set([' ' * chunksize]))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
397
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
398 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
399 def test_startswith(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
400 SUBSTR = ' abc def ghi'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
401 s = '-' * size + SUBSTR
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
402 self.failUnless(s.startswith(s))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
403 self.failUnless(s.startswith('-' * size))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
404 self.failIf(s.startswith(SUBSTR))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
405
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
406 @bigmemtest(minsize=_2G, memuse=1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
407 def test_strip(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
408 SUBSTR = ' abc def ghi '
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
409 s = SUBSTR.rjust(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
410 self.assertEquals(len(s), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
411 self.assertEquals(s.strip(), SUBSTR.strip())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
412 del s
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
413 s = SUBSTR.ljust(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
414 self.assertEquals(len(s), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
415 self.assertEquals(s.strip(), SUBSTR.strip())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
416
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
417 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
418 def test_swapcase(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
419 SUBSTR = "aBcDeFG12.'\xa9\x00"
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
420 sublen = len(SUBSTR)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
421 repeats = size // sublen + 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
422 s = SUBSTR * repeats
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
423 s = s.swapcase()
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
424 self.assertEquals(len(s), sublen * repeats)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
425 self.assertEquals(s[:sublen * 3], SUBSTR.swapcase() * 3)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
426 self.assertEquals(s[-sublen * 3:], SUBSTR.swapcase() * 3)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
427
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
428 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
429 def test_title(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
430 SUBSTR = 'SpaaHAaaAaham'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
431 s = SUBSTR * (size // len(SUBSTR) + 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
432 s = s.title()
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
433 self.failUnless(s.startswith((SUBSTR * 3).title()))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
434 self.failUnless(s.endswith(SUBSTR.lower() * 3))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
435
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
436 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
437 def test_translate(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
438 trans = string.maketrans('.aZ', '-!$')
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
439 SUBSTR = 'aZz.z.Aaz.'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
440 sublen = len(SUBSTR)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
441 repeats = size // sublen + 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
442 s = SUBSTR * repeats
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
443 s = s.translate(trans)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
444 self.assertEquals(len(s), repeats * sublen)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
445 self.assertEquals(s[:sublen], SUBSTR.translate(trans))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
446 self.assertEquals(s[-sublen:], SUBSTR.translate(trans))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
447 self.assertEquals(s.count('.'), 0)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
448 self.assertEquals(s.count('!'), repeats * 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
449 self.assertEquals(s.count('z'), repeats * 3)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
450
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
451 @bigmemtest(minsize=_2G + 5, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
452 def test_upper(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
453 s = 'a' * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
454 s = s.upper()
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
455 self.assertEquals(len(s), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
456 self.assertEquals(s.count('A'), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
457
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
458 @bigmemtest(minsize=_2G + 20, memuse=1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
459 def test_zfill(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
460 SUBSTR = '-568324723598234'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
461 s = SUBSTR.zfill(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
462 self.failUnless(s.endswith('0' + SUBSTR[1:]))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
463 self.failUnless(s.startswith('-0'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
464 self.assertEquals(len(s), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
465 self.assertEquals(s.count('0'), size - len(SUBSTR))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
466
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
467 @bigmemtest(minsize=_2G + 10, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
468 def test_format(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
469 s = '-' * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
470 sf = '%s' % (s,)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
471 self.failUnless(s == sf)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
472 del sf
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
473 sf = '..%s..' % (s,)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
474 self.assertEquals(len(sf), len(s) + 4)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
475 self.failUnless(sf.startswith('..-'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
476 self.failUnless(sf.endswith('-..'))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
477 del s, sf
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
478
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
479 size //= 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
480 edge = '-' * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
481 s = ''.join([edge, '%s', edge])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
482 del edge
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
483 s = s % '...'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
484 self.assertEquals(len(s), size * 2 + 3)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
485 self.assertEquals(s.count('.'), 3)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
486 self.assertEquals(s.count('-'), size * 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
487
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
488 @bigmemtest(minsize=_2G + 10, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
489 def test_repr_small(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
490 s = '-' * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
491 s = repr(s)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
492 self.assertEquals(len(s), size + 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
493 self.assertEquals(s[0], "'")
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
494 self.assertEquals(s[-1], "'")
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
495 self.assertEquals(s.count('-'), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
496 del s
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
497 # repr() will create a string four times as large as this 'binary
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
498 # string', but we don't want to allocate much more than twice
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
499 # size in total. (We do extra testing in test_repr_large())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
500 size = size // 5 * 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
501 s = '\x00' * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
502 s = repr(s)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
503 self.assertEquals(len(s), size * 4 + 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
504 self.assertEquals(s[0], "'")
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
505 self.assertEquals(s[-1], "'")
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
506 self.assertEquals(s.count('\\'), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
507 self.assertEquals(s.count('0'), size * 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
508
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
509 @bigmemtest(minsize=_2G + 10, memuse=5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
510 def test_repr_large(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
511 s = '\x00' * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
512 s = repr(s)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
513 self.assertEquals(len(s), size * 4 + 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
514 self.assertEquals(s[0], "'")
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
515 self.assertEquals(s[-1], "'")
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
516 self.assertEquals(s.count('\\'), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
517 self.assertEquals(s.count('0'), size * 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
518
48114
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
519 @bigmemtest(minsize=2**32 / 5, memuse=6+2)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
520 def test_unicode_repr(self, size):
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
521 s = u"\uAAAA" * size
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
522 self.failUnless(len(repr(s)) > size)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
523
38197
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
524 # This test is meaningful even with size < 2G, as long as the
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
525 # doubled string is > 2G (but it tests more if both are > 2G :)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
526 @bigmemtest(minsize=_1G + 2, memuse=3)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
527 def test_concat(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
528 s = '.' * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
529 self.assertEquals(len(s), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
530 s = s + s
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
531 self.assertEquals(len(s), size * 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
532 self.assertEquals(s.count('.'), size * 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
533
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
534 # This test is meaningful even with size < 2G, as long as the
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
535 # repeated string is > 2G (but it tests more if both are > 2G :)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
536 @bigmemtest(minsize=_1G + 2, memuse=3)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
537 def test_repeat(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
538 s = '.' * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
539 self.assertEquals(len(s), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
540 s = s * 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
541 self.assertEquals(len(s), size * 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
542 self.assertEquals(s.count('.'), size * 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
543
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
544 @bigmemtest(minsize=_2G + 20, memuse=1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
545 def test_slice_and_getitem(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
546 SUBSTR = '0123456789'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
547 sublen = len(SUBSTR)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
548 s = SUBSTR * (size // sublen)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
549 stepsize = len(s) // 100
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
550 stepsize = stepsize - (stepsize % sublen)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
551 for i in range(0, len(s) - stepsize, stepsize):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
552 self.assertEquals(s[i], SUBSTR[0])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
553 self.assertEquals(s[i:i + sublen], SUBSTR)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
554 self.assertEquals(s[i:i + sublen:2], SUBSTR[::2])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
555 if i > 0:
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
556 self.assertEquals(s[i + sublen - 1:i - 1:-3],
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
557 SUBSTR[sublen::-3])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
558 # Make sure we do some slicing and indexing near the end of the
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
559 # string, too.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
560 self.assertEquals(s[len(s) - 1], SUBSTR[-1])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
561 self.assertEquals(s[-1], SUBSTR[-1])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
562 self.assertEquals(s[len(s) - 10], SUBSTR[0])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
563 self.assertEquals(s[-sublen], SUBSTR[0])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
564 self.assertEquals(s[len(s):], '')
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
565 self.assertEquals(s[len(s) - 1:], SUBSTR[-1])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
566 self.assertEquals(s[-1:], SUBSTR[-1])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
567 self.assertEquals(s[len(s) - sublen:], SUBSTR)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
568 self.assertEquals(s[-sublen:], SUBSTR)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
569 self.assertEquals(len(s[:]), len(s))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
570 self.assertEquals(len(s[:len(s) - 5]), len(s) - 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
571 self.assertEquals(len(s[5:-5]), len(s) - 10)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
572
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
573 self.assertRaises(IndexError, operator.getitem, s, len(s))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
574 self.assertRaises(IndexError, operator.getitem, s, len(s) + 1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
575 self.assertRaises(IndexError, operator.getitem, s, len(s) + 1<<31)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
576
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
577 @bigmemtest(minsize=_2G, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
578 def test_contains(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
579 SUBSTR = '0123456789'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
580 edge = '-' * (size // 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
581 s = ''.join([edge, SUBSTR, edge])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
582 del edge
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
583 self.failUnless(SUBSTR in s)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
584 self.failIf(SUBSTR * 2 in s)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
585 self.failUnless('-' in s)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
586 self.failIf('a' in s)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
587 s += 'a'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
588 self.failUnless('a' in s)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
589
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
590 @bigmemtest(minsize=_2G + 10, memuse=2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
591 def test_compare(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
592 s1 = '-' * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
593 s2 = '-' * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
594 self.failUnless(s1 == s2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
595 del s2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
596 s2 = s1 + 'a'
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
597 self.failIf(s1 == s2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
598 del s2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
599 s2 = '.' * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
600 self.failIf(s1 == s2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
601
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
602 @bigmemtest(minsize=_2G + 10, memuse=1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
603 def test_hash(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
604 # Not sure if we can do any meaningful tests here... Even if we
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
605 # start relying on the exact algorithm used, the result will be
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
606 # different depending on the size of the C 'long int'. Even this
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
607 # test is dodgy (there's no *guarantee* that the two things should
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
608 # have a different hash, even if they, in the current
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
609 # implementation, almost always do.)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
610 s = '\x00' * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
611 h1 = hash(s)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
612 del s
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
613 s = '\x00' * (size + 1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
614 self.failIf(h1 == hash(s))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
615
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
616 class TupleTest(unittest.TestCase):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
617
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
618 # Tuples have a small, fixed-sized head and an array of pointers to
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
619 # data. Since we're testing 64-bit addressing, we can assume that the
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
620 # pointers are 8 bytes, and that thus that the tuples take up 8 bytes
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
621 # per size.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
622
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
623 # As a side-effect of testing long tuples, these tests happen to test
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
624 # having more than 2<<31 references to any given object. Hence the
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
625 # use of different types of objects as contents in different tests.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
626
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
627 @bigmemtest(minsize=_2G + 2, memuse=16)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
628 def test_compare(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
629 t1 = (u'',) * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
630 t2 = (u'',) * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
631 self.failUnless(t1 == t2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
632 del t2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
633 t2 = (u'',) * (size + 1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
634 self.failIf(t1 == t2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
635 del t2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
636 t2 = (1,) * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
637 self.failIf(t1 == t2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
638
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
639 # Test concatenating into a single tuple of more than 2G in length,
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
640 # and concatenating a tuple of more than 2G in length separately, so
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
641 # the smaller test still gets run even if there isn't memory for the
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
642 # larger test (but we still let the tester know the larger test is
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
643 # skipped, in verbose mode.)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
644 def basic_concat_test(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
645 t = ((),) * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
646 self.assertEquals(len(t), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
647 t = t + t
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
648 self.assertEquals(len(t), size * 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
649
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
650 @bigmemtest(minsize=_2G // 2 + 2, memuse=24)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
651 def test_concat_small(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
652 return self.basic_concat_test(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
653
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
654 @bigmemtest(minsize=_2G + 2, memuse=24)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
655 def test_concat_large(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
656 return self.basic_concat_test(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
657
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
658 @bigmemtest(minsize=_2G // 5 + 10, memuse=8 * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
659 def test_contains(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
660 t = (1, 2, 3, 4, 5) * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
661 self.assertEquals(len(t), size * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
662 self.failUnless(5 in t)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
663 self.failIf((1, 2, 3, 4, 5) in t)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
664 self.failIf(0 in t)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
665
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
666 @bigmemtest(minsize=_2G + 10, memuse=8)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
667 def test_hash(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
668 t1 = (0,) * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
669 h1 = hash(t1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
670 del t1
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
671 t2 = (0,) * (size + 1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
672 self.failIf(h1 == hash(t2))
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
673
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
674 @bigmemtest(minsize=_2G + 10, memuse=8)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
675 def test_index_and_slice(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
676 t = (None,) * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
677 self.assertEquals(len(t), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
678 self.assertEquals(t[-1], None)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
679 self.assertEquals(t[5], None)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
680 self.assertEquals(t[size - 1], None)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
681 self.assertRaises(IndexError, operator.getitem, t, size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
682 self.assertEquals(t[:5], (None,) * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
683 self.assertEquals(t[-5:], (None,) * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
684 self.assertEquals(t[20:25], (None,) * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
685 self.assertEquals(t[-25:-20], (None,) * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
686 self.assertEquals(t[size - 5:], (None,) * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
687 self.assertEquals(t[size - 5:size], (None,) * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
688 self.assertEquals(t[size - 6:size - 2], (None,) * 4)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
689 self.assertEquals(t[size:size], ())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
690 self.assertEquals(t[size:size+5], ())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
691
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
692 # Like test_concat, split in two.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
693 def basic_test_repeat(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
694 t = ('',) * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
695 self.assertEquals(len(t), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
696 t = t * 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
697 self.assertEquals(len(t), size * 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
698
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
699 @bigmemtest(minsize=_2G // 2 + 2, memuse=24)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
700 def test_repeat_small(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
701 return self.basic_test_repeat(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
702
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
703 @bigmemtest(minsize=_2G + 2, memuse=24)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
704 def test_repeat_large(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
705 return self.basic_test_repeat(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
706
48114
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
707 @bigmemtest(minsize=_1G - 1, memuse=12)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
708 def test_repeat_large_2(self, size):
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
709 return self.basic_test_repeat(size)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
710
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
711 @precisionbigmemtest(size=_1G - 1, memuse=9)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
712 def test_from_2G_generator(self, size):
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
713 try:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
714 t = tuple(xrange(size))
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
715 except MemoryError:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
716 pass # acceptable on 32-bit
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
717 else:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
718 count = 0
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
719 for item in t:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
720 self.assertEquals(item, count)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
721 count += 1
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
722 self.assertEquals(count, size)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
723
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
724 @precisionbigmemtest(size=_1G - 25, memuse=9)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
725 def test_from_almost_2G_generator(self, size):
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
726 try:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
727 t = tuple(xrange(size))
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
728 count = 0
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
729 for item in t:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
730 self.assertEquals(item, count)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
731 count += 1
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
732 self.assertEquals(count, size)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
733 except MemoryError:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
734 pass # acceptable, expected on 32-bit
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
735
38197
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
736 # Like test_concat, split in two.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
737 def basic_test_repr(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
738 t = (0,) * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
739 s = repr(t)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
740 # The repr of a tuple of 0's is exactly three times the tuple length.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
741 self.assertEquals(len(s), size * 3)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
742 self.assertEquals(s[:5], '(0, 0')
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
743 self.assertEquals(s[-5:], '0, 0)')
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
744 self.assertEquals(s.count('0'), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
745
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
746 @bigmemtest(minsize=_2G // 3 + 2, memuse=8 + 3)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
747 def test_repr_small(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
748 return self.basic_test_repr(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
749
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
750 @bigmemtest(minsize=_2G + 2, memuse=8 + 3)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
751 def test_repr_large(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
752 return self.basic_test_repr(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
753
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
754 class ListTest(unittest.TestCase):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
755
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
756 # Like tuples, lists have a small, fixed-sized head and an array of
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
757 # pointers to data, so 8 bytes per size. Also like tuples, we make the
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
758 # lists hold references to various objects to test their refcount
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
759 # limits.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
760
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
761 @bigmemtest(minsize=_2G + 2, memuse=16)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
762 def test_compare(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
763 l1 = [u''] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
764 l2 = [u''] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
765 self.failUnless(l1 == l2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
766 del l2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
767 l2 = [u''] * (size + 1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
768 self.failIf(l1 == l2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
769 del l2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
770 l2 = [2] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
771 self.failIf(l1 == l2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
772
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
773 # Test concatenating into a single list of more than 2G in length,
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
774 # and concatenating a list of more than 2G in length separately, so
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
775 # the smaller test still gets run even if there isn't memory for the
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
776 # larger test (but we still let the tester know the larger test is
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
777 # skipped, in verbose mode.)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
778 def basic_test_concat(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
779 l = [[]] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
780 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
781 l = l + l
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
782 self.assertEquals(len(l), size * 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
783
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
784 @bigmemtest(minsize=_2G // 2 + 2, memuse=24)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
785 def test_concat_small(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
786 return self.basic_test_concat(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
787
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
788 @bigmemtest(minsize=_2G + 2, memuse=24)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
789 def test_concat_large(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
790 return self.basic_test_concat(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
791
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
792 def basic_test_inplace_concat(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
793 l = [sys.stdout] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
794 l += l
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
795 self.assertEquals(len(l), size * 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
796 self.failUnless(l[0] is l[-1])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
797 self.failUnless(l[size - 1] is l[size + 1])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
798
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
799 @bigmemtest(minsize=_2G // 2 + 2, memuse=24)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
800 def test_inplace_concat_small(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
801 return self.basic_test_inplace_concat(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
802
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
803 @bigmemtest(minsize=_2G + 2, memuse=24)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
804 def test_inplace_concat_large(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
805 return self.basic_test_inplace_concat(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
806
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
807 @bigmemtest(minsize=_2G // 5 + 10, memuse=8 * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
808 def test_contains(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
809 l = [1, 2, 3, 4, 5] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
810 self.assertEquals(len(l), size * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
811 self.failUnless(5 in l)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
812 self.failIf([1, 2, 3, 4, 5] in l)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
813 self.failIf(0 in l)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
814
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
815 @bigmemtest(minsize=_2G + 10, memuse=8)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
816 def test_hash(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
817 l = [0] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
818 self.failUnlessRaises(TypeError, hash, l)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
819
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
820 @bigmemtest(minsize=_2G + 10, memuse=8)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
821 def test_index_and_slice(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
822 l = [None] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
823 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
824 self.assertEquals(l[-1], None)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
825 self.assertEquals(l[5], None)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
826 self.assertEquals(l[size - 1], None)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
827 self.assertRaises(IndexError, operator.getitem, l, size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
828 self.assertEquals(l[:5], [None] * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
829 self.assertEquals(l[-5:], [None] * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
830 self.assertEquals(l[20:25], [None] * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
831 self.assertEquals(l[-25:-20], [None] * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
832 self.assertEquals(l[size - 5:], [None] * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
833 self.assertEquals(l[size - 5:size], [None] * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
834 self.assertEquals(l[size - 6:size - 2], [None] * 4)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
835 self.assertEquals(l[size:size], [])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
836 self.assertEquals(l[size:size+5], [])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
837
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
838 l[size - 2] = 5
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
839 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
840 self.assertEquals(l[-3:], [None, 5, None])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
841 self.assertEquals(l.count(5), 1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
842 self.assertRaises(IndexError, operator.setitem, l, size, 6)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
843 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
844
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
845 l[size - 7:] = [1, 2, 3, 4, 5]
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
846 size -= 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
847 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
848 self.assertEquals(l[-7:], [None, None, 1, 2, 3, 4, 5])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
849
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
850 l[:7] = [1, 2, 3, 4, 5]
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
851 size -= 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
852 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
853 self.assertEquals(l[:7], [1, 2, 3, 4, 5, None, None])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
854
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
855 del l[size - 1]
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
856 size -= 1
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
857 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
858 self.assertEquals(l[-1], 4)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
859
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
860 del l[-2:]
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
861 size -= 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
862 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
863 self.assertEquals(l[-1], 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
864
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
865 del l[0]
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
866 size -= 1
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
867 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
868 self.assertEquals(l[0], 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
869
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
870 del l[:2]
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
871 size -= 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
872 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
873 self.assertEquals(l[0], 4)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
874
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
875 # Like test_concat, split in two.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
876 def basic_test_repeat(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
877 l = [] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
878 self.failIf(l)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
879 l = [''] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
880 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
881 l = l * 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
882 self.assertEquals(len(l), size * 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
883
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
884 @bigmemtest(minsize=_2G // 2 + 2, memuse=24)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
885 def test_repeat_small(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
886 return self.basic_test_repeat(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
887
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
888 @bigmemtest(minsize=_2G + 2, memuse=24)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
889 def test_repeat_large(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
890 return self.basic_test_repeat(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
891
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
892 def basic_test_inplace_repeat(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
893 l = ['']
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
894 l *= size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
895 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
896 self.failUnless(l[0] is l[-1])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
897 del l
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
898
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
899 l = [''] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
900 l *= 2
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
901 self.assertEquals(len(l), size * 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
902 self.failUnless(l[size - 1] is l[-1])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
903
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
904 @bigmemtest(minsize=_2G // 2 + 2, memuse=16)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
905 def test_inplace_repeat_small(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
906 return self.basic_test_inplace_repeat(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
907
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
908 @bigmemtest(minsize=_2G + 2, memuse=16)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
909 def test_inplace_repeat_large(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
910 return self.basic_test_inplace_repeat(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
911
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
912 def basic_test_repr(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
913 l = [0] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
914 s = repr(l)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
915 # The repr of a list of 0's is exactly three times the list length.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
916 self.assertEquals(len(s), size * 3)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
917 self.assertEquals(s[:5], '[0, 0')
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
918 self.assertEquals(s[-5:], '0, 0]')
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
919 self.assertEquals(s.count('0'), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
920
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
921 @bigmemtest(minsize=_2G // 3 + 2, memuse=8 + 3)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
922 def test_repr_small(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
923 return self.basic_test_repr(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
924
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
925 @bigmemtest(minsize=_2G + 2, memuse=8 + 3)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
926 def test_repr_large(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
927 return self.basic_test_repr(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
928
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
929 # list overallocates ~1/8th of the total size (on first expansion) so
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
930 # the single list.append call puts memuse at 9 bytes per size.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
931 @bigmemtest(minsize=_2G, memuse=9)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
932 def test_append(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
933 l = [object()] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
934 l.append(object())
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
935 self.assertEquals(len(l), size+1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
936 self.failUnless(l[-3] is l[-2])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
937 self.failIf(l[-2] is l[-1])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
938
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
939 @bigmemtest(minsize=_2G // 5 + 2, memuse=8 * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
940 def test_count(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
941 l = [1, 2, 3, 4, 5] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
942 self.assertEquals(l.count(1), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
943 self.assertEquals(l.count("1"), 0)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
944
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
945 def basic_test_extend(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
946 l = [file] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
947 l.extend(l)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
948 self.assertEquals(len(l), size * 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
949 self.failUnless(l[0] is l[-1])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
950 self.failUnless(l[size - 1] is l[size + 1])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
951
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
952 @bigmemtest(minsize=_2G // 2 + 2, memuse=16)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
953 def test_extend_small(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
954 return self.basic_test_extend(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
955
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
956 @bigmemtest(minsize=_2G + 2, memuse=16)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
957 def test_extend_large(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
958 return self.basic_test_extend(size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
959
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
960 @bigmemtest(minsize=_2G // 5 + 2, memuse=8 * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
961 def test_index(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
962 l = [1L, 2L, 3L, 4L, 5L] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
963 size *= 5
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
964 self.assertEquals(l.index(1), 0)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
965 self.assertEquals(l.index(5, size - 5), size - 1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
966 self.assertEquals(l.index(5, size - 5, size), size - 1)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
967 self.assertRaises(ValueError, l.index, 1, size - 4, size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
968 self.assertRaises(ValueError, l.index, 6L)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
969
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
970 # This tests suffers from overallocation, just like test_append.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
971 @bigmemtest(minsize=_2G + 10, memuse=9)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
972 def test_insert(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
973 l = [1.0] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
974 l.insert(size - 1, "A")
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
975 size += 1
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
976 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
977 self.assertEquals(l[-3:], [1.0, "A", 1.0])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
978
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
979 l.insert(size + 1, "B")
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
980 size += 1
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
981 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
982 self.assertEquals(l[-3:], ["A", 1.0, "B"])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
983
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
984 l.insert(1, "C")
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
985 size += 1
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
986 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
987 self.assertEquals(l[:3], [1.0, "C", 1.0])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
988 self.assertEquals(l[size - 3:], ["A", 1.0, "B"])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
989
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
990 @bigmemtest(minsize=_2G // 5 + 4, memuse=8 * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
991 def test_pop(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
992 l = [u"a", u"b", u"c", u"d", u"e"] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
993 size *= 5
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
994 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
995
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
996 item = l.pop()
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
997 size -= 1
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
998 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
999 self.assertEquals(item, u"e")
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1000 self.assertEquals(l[-2:], [u"c", u"d"])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1001
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1002 item = l.pop(0)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1003 size -= 1
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1004 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1005 self.assertEquals(item, u"a")
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1006 self.assertEquals(l[:2], [u"b", u"c"])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1007
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1008 item = l.pop(size - 2)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1009 size -= 1
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1010 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1011 self.assertEquals(item, u"c")
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1012 self.assertEquals(l[-2:], [u"b", u"d"])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1013
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1014 @bigmemtest(minsize=_2G + 10, memuse=8)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1015 def test_remove(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1016 l = [10] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1017 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1018
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1019 l.remove(10)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1020 size -= 1
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1021 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1022
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1023 # Because of the earlier l.remove(), this append doesn't trigger
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1024 # a resize.
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1025 l.append(5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1026 size += 1
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1027 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1028 self.assertEquals(l[-2:], [10, 5])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1029 l.remove(5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1030 size -= 1
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1031 self.assertEquals(len(l), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1032 self.assertEquals(l[-2:], [10, 10])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1033
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1034 @bigmemtest(minsize=_2G // 5 + 2, memuse=8 * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1035 def test_reverse(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1036 l = [1, 2, 3, 4, 5] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1037 l.reverse()
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1038 self.assertEquals(len(l), size * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1039 self.assertEquals(l[-5:], [5, 4, 3, 2, 1])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1040 self.assertEquals(l[:5], [5, 4, 3, 2, 1])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1041
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1042 @bigmemtest(minsize=_2G // 5 + 2, memuse=8 * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1043 def test_sort(self, size):
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1044 l = [1, 2, 3, 4, 5] * size
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1045 l.sort()
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1046 self.assertEquals(len(l), size * 5)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1047 self.assertEquals(l.count(1), size)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1048 self.assertEquals(l[:10], [1] * 10)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1049 self.assertEquals(l[-10:], [5] * 10)
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1050
48114
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
1051 class BufferTest(unittest.TestCase):
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
1052
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
1053 @precisionbigmemtest(size=_1G, memuse=4)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
1054 def test_repeat(self, size):
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
1055 try:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
1056 b = buffer("AAAA")*size
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
1057 except MemoryError:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
1058 pass # acceptable on 32-bit
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
1059 else:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
1060 count = 0
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
1061 for c in b:
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
1062 self.assertEquals(c, 'A')
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
1063 count += 1
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
1064 self.assertEquals(count, size*4)
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
1065
38197
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1066 def test_main():
48114
c4d24fc8ba8a Security patches from Apple: prevent int overflow when allocating memory
Neal Norwitz <nnorwitz@gmail.com>
parents: 44075
diff changeset
1067 test_support.run_unittest(StrTest, TupleTest, ListTest, BufferTest)
38197
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1068
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1069 if __name__ == '__main__':
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1070 if len(sys.argv) > 1:
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1071 test_support.set_memlimit(sys.argv[1])
204ec383b445 Text files missing the SVN eol-style property.
Tim Peters <tim.peters@gmail.com>
parents: 38014
diff changeset
1072 test_main()