Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_list.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | 6768b2350c57 |
| children |
| rev | line source |
|---|---|
|
43583
6157e0d27eef
Fix the overflow checking of list_repeat.
Armin Rigo <arigo@tunes.org>
parents:
33623
diff
changeset
|
1 import sys |
|
31159
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
2 from test import test_support, list_tests |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
3 |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
4 class ListTest(list_tests.CommonTest): |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
5 type2test = list |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
6 |
|
46649
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
7 def test_basic(self): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
8 self.assertEqual(list([]), []) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
9 l0_3 = [0, 1, 2, 3] |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
10 l0_3_bis = list(l0_3) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
11 self.assertEqual(l0_3, l0_3_bis) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
48834
diff
changeset
|
12 self.assertTrue(l0_3 is not l0_3_bis) |
|
46649
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
13 self.assertEqual(list(()), []) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
14 self.assertEqual(list((0, 1, 2, 3)), [0, 1, 2, 3]) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
15 self.assertEqual(list(''), []) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
16 self.assertEqual(list('spam'), ['s', 'p', 'a', 'm']) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
17 |
|
48834
75f64fd1f113
Fix bug 3625: test issues on 64bit windows. r=pitrou
Mark Hammond <mhammond@skippinet.com.au>
parents:
46649
diff
changeset
|
18 if sys.maxsize == 0x7fffffff: |
|
46649
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
19 # This test can currently only work on 32-bit machines. |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
20 # XXX If/when PySequence_Length() returns a ssize_t, it should be |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
21 # XXX re-enabled. |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
22 # Verify clearing of bug #556025. |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
23 # This assumes that the max data size (sys.maxint) == max |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
24 # address size this also assumes that the address size is at |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
25 # least 4 bytes with 8 byte addresses, the bug is not well |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
26 # tested |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
27 # |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
28 # Note: This test is expected to SEGV under Cygwin 1.3.12 or |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
29 # earlier due to a newlib bug. See the following mailing list |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
30 # thread for the details: |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
31 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
32 # http://sources.redhat.com/ml/newlib/2002/msg00369.html |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
33 self.assertRaises(MemoryError, list, xrange(sys.maxint // 2)) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
34 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
35 # This code used to segfault in Py2.4a3 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
36 x = [] |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
37 x.extend(-y for y in x) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
38 self.assertEqual(x, []) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
39 |
|
31159
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
40 def test_truth(self): |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
41 super(ListTest, self).test_truth() |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
48834
diff
changeset
|
42 self.assertTrue(not []) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
48834
diff
changeset
|
43 self.assertTrue([42]) |
|
31159
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
44 |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
45 def test_identity(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
48834
diff
changeset
|
46 self.assertTrue([] is not []) |
|
31159
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
47 |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
48 def test_len(self): |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
49 super(ListTest, self).test_len() |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
50 self.assertEqual(len([]), 0) |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
51 self.assertEqual(len([0]), 1) |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
52 self.assertEqual(len([0, 1, 2]), 3) |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
53 |
|
43583
6157e0d27eef
Fix the overflow checking of list_repeat.
Armin Rigo <arigo@tunes.org>
parents:
33623
diff
changeset
|
54 def test_overflow(self): |
|
6157e0d27eef
Fix the overflow checking of list_repeat.
Armin Rigo <arigo@tunes.org>
parents:
33623
diff
changeset
|
55 lst = [4, 5, 6, 7] |
|
6157e0d27eef
Fix the overflow checking of list_repeat.
Armin Rigo <arigo@tunes.org>
parents:
33623
diff
changeset
|
56 n = int((sys.maxint*2+2) // len(lst)) |
|
6157e0d27eef
Fix the overflow checking of list_repeat.
Armin Rigo <arigo@tunes.org>
parents:
33623
diff
changeset
|
57 def mul(a, b): return a * b |
|
6157e0d27eef
Fix the overflow checking of list_repeat.
Armin Rigo <arigo@tunes.org>
parents:
33623
diff
changeset
|
58 def imul(a, b): a *= b |
|
6157e0d27eef
Fix the overflow checking of list_repeat.
Armin Rigo <arigo@tunes.org>
parents:
33623
diff
changeset
|
59 self.assertRaises((MemoryError, OverflowError), mul, lst, n) |
|
6157e0d27eef
Fix the overflow checking of list_repeat.
Armin Rigo <arigo@tunes.org>
parents:
33623
diff
changeset
|
60 self.assertRaises((MemoryError, OverflowError), imul, lst, n) |
|
6157e0d27eef
Fix the overflow checking of list_repeat.
Armin Rigo <arigo@tunes.org>
parents:
33623
diff
changeset
|
61 |
|
33623
8e9dcfe14d81
Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents:
31159
diff
changeset
|
62 def test_main(verbose=None): |
|
31159
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
63 test_support.run_unittest(ListTest) |
|
e1f1fb74451b
Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
64 |
|
33623
8e9dcfe14d81
Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents:
31159
diff
changeset
|
65 # verify reference counting |
|
8e9dcfe14d81
Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents:
31159
diff
changeset
|
66 import sys |
|
8e9dcfe14d81
Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents:
31159
diff
changeset
|
67 if verbose and hasattr(sys, "gettotalrefcount"): |
|
8e9dcfe14d81
Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents:
31159
diff
changeset
|
68 import gc |
|
8e9dcfe14d81
Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents:
31159
diff
changeset
|
69 counts = [None] * 5 |
|
8e9dcfe14d81
Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents:
31159
diff
changeset
|
70 for i in xrange(len(counts)): |
|
8e9dcfe14d81
Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents:
31159
diff
changeset
|
71 test_support.run_unittest(ListTest) |
|
8e9dcfe14d81
Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents:
31159
diff
changeset
|
72 gc.collect() |
|
8e9dcfe14d81
Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents:
31159
diff
changeset
|
73 counts[i] = sys.gettotalrefcount() |
|
8e9dcfe14d81
Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents:
31159
diff
changeset
|
74 print counts |
|
8e9dcfe14d81
Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents:
31159
diff
changeset
|
75 |
|
8e9dcfe14d81
Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents:
31159
diff
changeset
|
76 |
|
8e9dcfe14d81
Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents:
31159
diff
changeset
|
77 if __name__ == "__main__": |
|
8e9dcfe14d81
Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents:
31159
diff
changeset
|
78 test_main(verbose=True) |
