|
1 | 1 | # Copyright (c) 2018, Oracle and/or its affiliates.
|
| 2 | +# Copyright (C) 1996-2017 Python Software Foundation |
2 | 3 | #
|
3 |
| -# The Universal Permissive License (UPL), Version 1.0 |
4 |
| -# |
5 |
| -# Subject to the condition set forth below, permission is hereby granted to any |
6 |
| -# person obtaining a copy of this software, associated documentation and/or data |
7 |
| -# (collectively the "Software"), free of charge and under any and all copyright |
8 |
| -# rights in the Software, and any and all patent rights owned or freely |
9 |
| -# licensable by each licensor hereunder covering either (i) the unmodified |
10 |
| -# Software as contributed to or provided by such licensor, or (ii) the Larger |
11 |
| -# Works (as defined below), to deal in both |
12 |
| -# |
13 |
| -# (a) the Software, and |
14 |
| -# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if |
15 |
| -# one is included with the Software (each a "Larger Work" to which the |
16 |
| -# Software is contributed by such licensors), |
17 |
| -# |
18 |
| -# without restriction, including without limitation the rights to copy, create |
19 |
| -# derivative works of, display, perform, and distribute the Software and make, |
20 |
| -# use, sell, offer for sale, import, export, have made, and have sold the |
21 |
| -# Software and the Larger Work(s), and to sublicense the foregoing rights on |
22 |
| -# either these or other terms. |
23 |
| -# |
24 |
| -# This license is subject to the following condition: |
25 |
| -# |
26 |
| -# The above copyright notice and either this complete permission notice or at a |
27 |
| -# minimum a reference to the UPL must be included in all copies or substantial |
28 |
| -# portions of the Software. |
29 |
| -# |
30 |
| -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
31 |
| -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
32 |
| -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
33 |
| -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
34 |
| -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
35 |
| -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
36 |
| -# SOFTWARE. |
| 4 | +# Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 |
37 | 5 |
|
38 | 6 | import seq_tests
|
| 7 | +import sys |
| 8 | +#import pickle |
39 | 9 |
|
40 | 10 | LONG_NUMBER = 6227020800;
|
41 | 11 |
|
|
44 | 14 |
|
45 | 15 | class ListTest(list_tests.CommonTest):
|
46 | 16 | type2test = list
|
47 |
| - |
| 17 | + |
| 18 | + def test_basic(self): |
| 19 | + self.assertEqual(list([]), []) |
| 20 | + l0_3 = [0, 1, 2, 3] |
| 21 | + l0_3_bis = list(l0_3) |
| 22 | + self.assertEqual(l0_3, l0_3_bis) |
| 23 | + self.assertTrue(l0_3 is not l0_3_bis) |
| 24 | + self.assertEqual(list(()), []) |
| 25 | + self.assertEqual(list((0, 1, 2, 3)), [0, 1, 2, 3]) |
| 26 | + self.assertEqual(list(''), []) |
| 27 | + self.assertEqual(list('spam'), ['s', 'p', 'a', 'm']) |
| 28 | + |
| 29 | +# if sys.maxsize == 0x7fffffff: |
| 30 | + # This test can currently only work on 32-bit machines. |
| 31 | + # XXX If/when PySequence_Length() returns a ssize_t, it should be |
| 32 | + # XXX re-enabled. |
| 33 | + # Verify clearing of bug #556025. |
| 34 | + # This assumes that the max data size (sys.maxint) == max |
| 35 | + # address size this also assumes that the address size is at |
| 36 | + # least 4 bytes with 8 byte addresses, the bug is not well |
| 37 | + # tested |
| 38 | + # |
| 39 | + # Note: This test is expected to SEGV under Cygwin 1.3.12 or |
| 40 | + # earlier due to a newlib bug. See the following mailing list |
| 41 | + # thread for the details: |
| 42 | + |
| 43 | + # http://sources.redhat.com/ml/newlib/2002/msg00369.html |
| 44 | +# TODO currently we get OutOfMemmory Exception |
| 45 | +# self.assertRaises(MemoryError, list, range(sys.maxsize // 2)) |
| 46 | + |
| 47 | + # This code used to segfault in Py2.4a3 |
| 48 | + x = [] |
| 49 | + x.extend(-y for y in x) |
| 50 | + self.assertEqual(x, []) |
| 51 | + |
| 52 | + def test_truth(self): |
| 53 | + super().test_truth() |
| 54 | + self.assertTrue(not []) |
| 55 | + self.assertTrue([42]) |
| 56 | + |
| 57 | + def test_identity(self): |
| 58 | + self.assertTrue([] is not []) |
| 59 | + |
| 60 | + def test_len(self): |
| 61 | + super().test_len() |
| 62 | + self.assertEqual(len([]), 0) |
| 63 | + self.assertEqual(len([0]), 1) |
| 64 | + self.assertEqual(len([0, 1, 2]), 3) |
| 65 | + |
| 66 | + def test_overflow(self): |
| 67 | + lst = [4, 5, 6, 7] |
| 68 | + n = int((sys.maxsize*2+2) // len(lst)) |
| 69 | + def mul(a, b): return a * b |
| 70 | + def imul(a, b): a *= b |
| 71 | + self.assertRaises((MemoryError, OverflowError), mul, lst, n) |
| 72 | + self.assertRaises((MemoryError, OverflowError), imul, lst, n) |
| 73 | + |
| 74 | + def test_repr_large(self): |
| 75 | + # Check the repr of large list objects |
| 76 | + def check(n): |
| 77 | + l = [0] * n |
| 78 | + s = repr(l) |
| 79 | + self.assertEqual(s, |
| 80 | + '[' + ', '.join(['0'] * n) + ']') |
| 81 | + check(10) # check our checking code |
| 82 | + check(1000000) |
| 83 | + |
| 84 | + # TODO currently sulong crashes when pickle.dumps is used. |
| 85 | + ''' |
| 86 | + def test_iterator_pickle(self): |
| 87 | + # Userlist iterators don't support pickling yet since |
| 88 | + # they are based on generators. |
| 89 | + data = self.type2test([4, 5, 6, 7]) |
| 90 | + it = itorg = iter(data) |
| 91 | + d = pickle.dumps(it) |
| 92 | + it = pickle.loads(d) |
| 93 | + self.assertEqual(type(itorg), type(it)) |
| 94 | + self.assertEqual(self.type2test(it), self.type2test(data)) |
| 95 | +
|
| 96 | + it = pickle.loads(d) |
| 97 | + next(it) |
| 98 | + d = pickle.dumps(it) |
| 99 | + self.assertEqual(self.type2test(it), self.type2test(data)[1:]) |
| 100 | +
|
| 101 | + def test_reversed_pickle(self): |
| 102 | + data = self.type2test([4, 5, 6, 7]) |
| 103 | + it = itorg = reversed(data) |
| 104 | + d = pickle.dumps(it) |
| 105 | + it = pickle.loads(d) |
| 106 | + self.assertEqual(type(itorg), type(it)) |
| 107 | + self.assertEqual(self.type2test(it), self.type2test(reversed(data))) |
| 108 | +
|
| 109 | + it = pickle.loads(d) |
| 110 | + next(it) |
| 111 | + d = pickle.dumps(it) |
| 112 | + self.assertEqual(self.type2test(it), self.type2test(reversed(data))[1:]) |
| 113 | + ''' |
| 114 | + def test_no_comdat_folding(self): |
| 115 | + # Issue 8847: In the PGO build, the MSVC linker's COMDAT folding |
| 116 | + # optimization causes failures in code that relies on distinct |
| 117 | + # function addresses. |
| 118 | + class L(list): pass |
| 119 | + with self.assertRaises(TypeError): |
| 120 | + (3,) + L([1,2]) |
| 121 | + |
48 | 122 | # ======== Specific test for Graal Python ======
|
49 | 123 |
|
50 | 124 | def test_getitem(self):
|
|
0 commit comments