2 from test
import support
, list_tests
4 class ListTest(list_tests
.CommonTest
):
8 self
.assertEqual(list([]), [])
11 self
.assertEqual(l0_3
, l0_3_bis
)
12 self
.assert_(l0_3
is not l0_3_bis
)
13 self
.assertEqual(list(()), [])
14 self
.assertEqual(list((0, 1, 2, 3)), [0, 1, 2, 3])
15 self
.assertEqual(list(''), [])
16 self
.assertEqual(list('spam'), ['s', 'p', 'a', 'm'])
18 if sys
.maxsize
== 0x7fffffff:
19 # This test can currently only work on 32-bit machines.
20 # XXX If/when PySequence_Length() returns a ssize_t, it should be
22 # Verify clearing of bug #556025.
23 # This assumes that the max data size (sys.maxint) == max
24 # address size this also assumes that the address size is at
25 # least 4 bytes with 8 byte addresses, the bug is not well
28 # Note: This test is expected to SEGV under Cygwin 1.3.12 or
29 # earlier due to a newlib bug. See the following mailing list
30 # thread for the details:
32 # http://sources.redhat.com/ml/newlib/2002/msg00369.html
33 self
.assertRaises(MemoryError, list, range(sys
.maxsize
// 2))
35 # This code used to segfault in Py2.4a3
37 x
.extend(-y
for y
in x
)
38 self
.assertEqual(x
, [])
45 def test_identity(self
):
46 self
.assert_([] is not [])
50 self
.assertEqual(len([]), 0)
51 self
.assertEqual(len([0]), 1)
52 self
.assertEqual(len([0, 1, 2]), 3)
54 def test_overflow(self
):
56 n
= int((sys
.maxsize
*2+2) // len(lst
))
57 def mul(a
, b
): return a
* b
58 def imul(a
, b
): a
*= b
59 self
.assertRaises((MemoryError, OverflowError), mul
, lst
, n
)
60 self
.assertRaises((MemoryError, OverflowError), imul
, lst
, n
)
62 def test_main(verbose
=None):
63 support
.run_unittest(ListTest
)
65 # verify reference counting
67 if verbose
and hasattr(sys
, "gettotalrefcount"):
70 for i
in range(len(counts
)):
71 support
.run_unittest(ListTest
)
73 counts
[i
] = sys
.gettotalrefcount()
77 if __name__
== "__main__":
78 test_main(verbose
=True)