Skip to content

Commit 595a9bd

Browse files
committed
Enabling as many list tests from CPython as possible.
1 parent eb3f193 commit 595a9bd

File tree

3 files changed

+114
-38
lines changed

3 files changed

+114
-38
lines changed

graalpython/com.oracle.graal.python.test/src/tests/list_tests.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ def test_imul(self):
565565
oldid = id(s)
566566
s *= 10
567567
self.assertEqual(id(s), oldid)
568-
568+
'''
569569
def test_extendedslicing(self):
570570
# subscript
571571
a = self.type2test([0,1,2,3,4])
@@ -605,15 +605,16 @@ def test_extendedslicing(self):
605605
self.assertEqual(a, self.type2test([0, 1, 1, 3, 2, 5, 3, 7, 4, 9]))
606606
# test issue7788
607607
a = self.type2test(range(10))
608-
del a[9::1<<333]
608+
# TODO currently we don't support slices with PInt
609+
# del a[9::1<<333]
609610

610611
def test_constructor_exception_handling(self):
611612
# Bug #1242657
612613
class F(object):
613614
def __iter__(self):
614615
raise KeyboardInterrupt
615616
self.assertRaises(KeyboardInterrupt, list, F())
616-
'''
617+
617618
def test_exhausted_iterator(self):
618619
a = self.type2test([1, 2, 3])
619620
exhit = iter(a)

graalpython/com.oracle.graal.python.test/src/tests/test_list.py

Lines changed: 109 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,11 @@
11
# Copyright (c) 2018, Oracle and/or its affiliates.
2+
# Copyright (C) 1996-2017 Python Software Foundation
23
#
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
375

386
import seq_tests
7+
import sys
8+
#import pickle
399

4010
LONG_NUMBER = 6227020800;
4111

@@ -44,7 +14,111 @@
4414

4515
class ListTest(list_tests.CommonTest):
4616
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+
48122
# ======== Specific test for Graal Python ======
49123

50124
def test_getitem(self):

mx.graalpython/copyrights/overrides

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ graalpython/com.oracle.graal.python.test/src/tests/cpyext/clinic/posixmodule.c.h
189189
graalpython/com.oracle.graal.python.test/src/tests/cpyext/posixmodule.c,python.copyright
190190
graalpython/com.oracle.graal.python.test/src/tests/cpyext/posixmodule.h,python.copyright
191191
graalpython/com.oracle.graal.python.test/src/tests/list_tests.py,python.copyright
192+
graalpython/com.oracle.graal.python.test/src/tests/test_list.py,python.copyright
192193
graalpython/com.oracle.graal.python.test/src/tests/mandelbrot3.py,benchmarks.copyright
193194
graalpython/com.oracle.graal.python.test/src/tests/nbody3.py,benchmarks.copyright
194195
graalpython/com.oracle.graal.python.test/src/tests/relative_import.py,zippy.copyright

0 commit comments

Comments
 (0)