Skip to content

Commit 278d8c4

Browse files
committed
Merge branch 'master' into feature/GR-24297
2 parents 2454278 + 88fbf07 commit 278d8c4

File tree

135 files changed

+1781
-449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+1781
-449
lines changed

graalpython/com.oracle.graal.python.cext/src/dictobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ int _PyDict_Next(PyObject *d, Py_ssize_t *ppos, PyObject **pkey, PyObject **pval
101101
*pvalue = PyTuple_GetItem(tresult, 1);
102102
}
103103
if (phash != NULL) {
104-
*phash = PyTuple_GetItem(tresult, 2);
104+
*phash = PyLong_AsSsize_t(PyTuple_GetItem(tresult, 2));
105105
}
106106
return 1;
107107

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
153153
case "-S":
154154
noSite = true;
155155
break;
156+
case "-X":
157+
i++;
158+
if (i < arguments.size()) {
159+
// CPython ignores unknown/unsupported -X options, so we can do that too
160+
} else {
161+
print("Argument expected for the -X option");
162+
printShortHelp();
163+
}
164+
break;
156165
case "-v":
157166
verboseFlag = true;
158167
break;
@@ -585,6 +594,7 @@ protected void printHelp(OptionCategory maxCategory) {
585594
" can be supplied multiple times to increase verbosity\n" +
586595
"-V : print the Python version number and exit (also --version)\n" +
587596
" when given twice, print more information about the build\n" +
597+
"-X opt : CPython implementation-specific options. Ignored on GraalPython\n" +
588598
// "-W arg : warning control; arg is
589599
// action:message:category:module:lineno\n" +
590600
// " also PYTHONWARNINGS=arg\n" +

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/interop/JavaInteropTest.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,6 @@
5252
import java.util.Arrays;
5353
import java.util.List;
5454

55-
import com.oracle.graal.python.runtime.interop.InteropArray;
56-
import com.oracle.graal.python.test.PythonTests;
57-
import com.oracle.truffle.api.interop.ArityException;
58-
import com.oracle.truffle.api.interop.InteropLibrary;
59-
import com.oracle.truffle.api.interop.TruffleObject;
60-
import com.oracle.truffle.api.interop.UnknownIdentifierException;
61-
import com.oracle.truffle.api.library.ExportLibrary;
62-
import com.oracle.truffle.api.library.ExportMessage;
63-
6455
import org.graalvm.polyglot.Context;
6556
import org.graalvm.polyglot.Context.Builder;
6657
import org.graalvm.polyglot.Engine;
@@ -76,6 +67,15 @@
7667
import org.junit.runners.Parameterized.Parameter;
7768
import org.junit.runners.Parameterized.Parameters;
7869

70+
import com.oracle.graal.python.runtime.interop.InteropArray;
71+
import com.oracle.graal.python.test.PythonTests;
72+
import com.oracle.truffle.api.interop.ArityException;
73+
import com.oracle.truffle.api.interop.InteropLibrary;
74+
import com.oracle.truffle.api.interop.TruffleObject;
75+
import com.oracle.truffle.api.interop.UnknownIdentifierException;
76+
import com.oracle.truffle.api.library.ExportLibrary;
77+
import com.oracle.truffle.api.library.ExportMessage;
78+
7979
@RunWith(Enclosed.class)
8080
public class JavaInteropTest {
8181
public static class GeneralInterop extends PythonTests {
@@ -301,13 +301,14 @@ public void accessSuitePy() throws IOException {
301301
"suite.py").build();
302302
Value suite = context.eval(suitePy);
303303

304+
Value listConverter = context.eval("python", "list");
304305
Value libraries = suite.getMember("libraries");
305306
assertNotNull("libraries found", libraries);
306-
final List<Object> suiteKeys = Arrays.asList(suite.invokeMember("keys").as(Object[].class));
307+
final List<Object> suiteKeys = Arrays.asList(listConverter.execute(suite.invokeMember("keys")).as(Object[].class));
307308
assertTrue("Libraries found among keys: " + suiteKeys, suiteKeys.contains("libraries"));
308309

309310
Value dacapo = null;
310-
for (Object k : libraries.invokeMember("keys").as(List.class)) {
311+
for (Object k : listConverter.execute(libraries.invokeMember("keys")).as(List.class)) {
311312
System.err.println("k " + k);
312313
if ("DACAPO".equals(k)) {
313314
dacapo = libraries.getMember((String) k);

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_dict.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -255,6 +255,31 @@ def compile_module(self, name):
255255
cmpfunc=lambda x, y: type(x) == tuple and type(y) == tuple and len(x) == 3 and len(y) == 3 and (x[0] == 0 and y[0] == 0 or x == y)
256256
)
257257

258+
# _PyDict_SetItem_KnownHash
259+
test__PyDict_SetItem_KnownHash = CPyExtFunction(
260+
lambda args: {'a': "hello"},
261+
lambda: (({'a': "hello"}, ),),
262+
code='''PyObject* wrap__PyDict_SetItem_KnownHash(PyObject* dict) {
263+
PyObject* result = PyDict_New();
264+
265+
Py_ssize_t ppos = 0;
266+
PyObject* key;
267+
PyObject* value;
268+
Py_hash_t phash;
269+
270+
int res = 0;
271+
272+
_PyDict_Next(dict, &ppos, &key, &value, &phash);
273+
res = _PyDict_SetItem_KnownHash(result, key, value, phash);
274+
return result;
275+
}
276+
''',
277+
resultspec="O",
278+
argspec='O',
279+
arguments=["PyObject* dict"],
280+
callfunction="wrap__PyDict_SetItem_KnownHash",
281+
)
282+
258283
# PyDict_Size
259284
test_PyDict_Size = CPyExtFunction(
260285
lambda args: len(args[0]),
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# Subject to the condition set forth below, permission is hereby granted to any
7+
# person obtaining a copy of this software, associated documentation and/or
8+
# data (collectively the "Software"), free of charge and under any and all
9+
# copyright rights in the Software, and any and all patent rights owned or
10+
# freely licensable by each licensor hereunder covering either (i) the
11+
# unmodified Software as contributed to or provided by such licensor, or (ii)
12+
# the Larger Works (as defined below), to deal in both
13+
#
14+
# (a) the Software, and
15+
#
16+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
17+
# one is included with the Software each a "Larger Work" to which the Software
18+
# is contributed by such licensors),
19+
#
20+
# without restriction, including without limitation the rights to copy, create
21+
# derivative works of, display, perform, and distribute the Software and make,
22+
# use, sell, offer for sale, import, export, have made, and have sold the
23+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
24+
# either these or other terms.
25+
#
26+
# This license is subject to the following condition:
27+
#
28+
# The above copyright notice and either this complete permission notice or at a
29+
# minimum a reference to the UPL must be included in all copies or substantial
30+
# portions of the Software.
31+
#
32+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
# SOFTWARE.
39+
40+
import os
41+
import sys
42+
import unittest
43+
44+
sys.path.insert(0, os.getcwd())
45+
46+
47+
class TestLoader(unittest.TestLoader):
48+
def loadTestsFromModule(self, module, pattern=None):
49+
suite = super().loadTestsFromModule(module, pattern=pattern)
50+
test_main = getattr(module, 'test_main', None)
51+
if callable(test_main):
52+
class TestMain(unittest.TestCase):
53+
pass
54+
55+
TestMain.__module__ = test_main.__module__
56+
TestMain.__qualname__ = TestMain.__name__
57+
TestMain.test_main = staticmethod(test_main)
58+
suite.addTests(self.loadTestsFromTestCase(TestMain))
59+
return suite
60+
61+
62+
# We would normmally just pass the loader to the main, but there are tests for the framework itself (test_unittest)
63+
# that interact weirdly with non-default loaders
64+
unittest.defaultTestLoader = TestLoader()
65+
unittest.main(module=None, testLoader=unittest.defaultTestLoader)

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,19 @@ def test_pow():
299299
# (0xffffffffffffffff >> 63) is used to produce a non-narrowed int
300300
assert 2**(0xffffffffffffffff >> 63) == 2
301301

302+
# test that two-argument pow functions work
303+
class M:
304+
def __pow__(self, power):
305+
return (type(self), power)
306+
assert pow(M(), 2) == (M, 2)
307+
assert pow(M(), 2, None) == (M, 2)
308+
try:
309+
pow(M(), 2, 3)
310+
except TypeError:
311+
assert True
312+
else:
313+
assert False
314+
302315
if sys.version_info.minor >= 8:
303316
# for some reason this hangs CPython on the CI even if it's just parsed
304317
from pow_tests import test_pow

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ def test_init3():
165165
assert False, "expected ValueError"
166166
except ValueError as e:
167167
assert "dictionary update sequence element #4 has length 1; 2 is required" == str(e), "invalid error message"
168+
169+
try:
170+
dict("5")
171+
assert False, "expected ValueError"
172+
except ValueError as e:
173+
assert "dictionary update sequence element #0 has length 1; 2 is required" == str(e), "invalid error message"
174+
175+
try:
176+
dict([("a", 1), ("b", 2), ("c", 3), ("d", 4), "5"])
177+
assert False, "expected ValueError"
178+
except ValueError as e:
179+
assert "dictionary update sequence element #4 has length 1; 2 is required" == str(e), "invalid error message"
168180

169181

170182
def test_init4():
@@ -198,7 +210,13 @@ def __len__(self):
198210
assert set(d.keys()) == key_set, "unexpected keys: %s" % str(d.keys())
199211
assert set(d.values()) == {97, 98, 99, 100}, "unexpected values: %s" % str(d.values())
200212

201-
213+
def test_init6():
214+
try:
215+
dict(1)
216+
assert False, "expected TypeError"
217+
except TypeError as e:
218+
assert "'int' object is not iterable" == str(e), "invalid error message"
219+
202220
def test_init_kwargs():
203221
kwargs = {'ONE': 'one', 'TWO': 'two'}
204222
d = dict([(1, 11), (2, 22)], **kwargs)

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
TAGS_DIR = "null"
5151

5252

53+
RUNNER = os.path.join(os.path.dirname(__file__), "run_cpython_test.py")
54+
55+
5356
def working_selectors(tagfile):
5457
if os.path.exists(tagfile):
5558
with open(tagfile) as f:
@@ -84,7 +87,7 @@ def fun(self):
8487
cmd.append("--inspect")
8588
if "-debug-java" in sys.argv:
8689
cmd.append("-debug-java")
87-
cmd += ["-S", "-m", "unittest"]
90+
cmd += ["-S", RUNNER]
8891
for testpattern in working_test[1]:
8992
cmd.extend(["-k", testpattern])
9093
testmod = working_test[0].rpartition(".")[2]
@@ -163,7 +166,13 @@ def parse_unittest_output(output):
163166
# entirely
164167
testfile_stem = os.path.splitext(os.path.basename(testfile))[0]
165168
testmod = "test." + testfile_stem
166-
cmd = [timeout, "-s", "9", "120"] + executable + ["-S", "-m"]
169+
cmd = [timeout, "-s", "9", "120"] + executable
170+
if repeat == 0:
171+
# Allow catching Java exceptions in the first iteration only, so that subsequent iterations
172+
# (there will be one even if everything succeeds) filter out possible false-passes caused by
173+
# the tests catching all exceptions somewhere
174+
cmd += ['--experimental-options', '--python.CatchAllExceptions']
175+
cmd += ["-S", RUNNER, "-v"]
167176
tagfile = os.path.join(TAGS_DIR, testfile_stem + ".txt")
168177
if retag and repeat == 0:
169178
test_selectors = []
@@ -176,7 +185,6 @@ def parse_unittest_output(output):
176185
continue
177186

178187
print("[%d/%d, Try %d] Testing %s" %(idx + 1, len(testfiles), repeat + 1, testmod))
179-
cmd += ["unittest", "-v"]
180188
for selector in test_selectors:
181189
cmd += ["-k", selector]
182190
cmd.append(testfile)

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_ast.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*graalpython.lib-python.3.test.test_ast.AST_Tests.test_field_attr_writable
33
*graalpython.lib-python.3.test.test_ast.AST_Tests.test_issue31592
44
*graalpython.lib-python.3.test.test_ast.AST_Tests.test_realtype
5+
*graalpython.lib-python.3.test.test_ast.ConstantTests.test_load_const
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1+
*graalpython.lib-python.3.test.test_base64.BaseXYTestCase.test_ErrorHeritage
2+
*graalpython.lib-python.3.test.test_base64.BaseXYTestCase.test_a85_padding
3+
*graalpython.lib-python.3.test.test_base64.BaseXYTestCase.test_a85decode_errors
4+
*graalpython.lib-python.3.test.test_base64.BaseXYTestCase.test_b32decode_casefold
5+
*graalpython.lib-python.3.test.test_base64.BaseXYTestCase.test_b32decode_error
6+
*graalpython.lib-python.3.test.test_base64.BaseXYTestCase.test_b85_padding
7+
*graalpython.lib-python.3.test.test_base64.BaseXYTestCase.test_b85decode_errors
8+
*graalpython.lib-python.3.test.test_base64.BaseXYTestCase.test_decode_nonascii_str
19
*graalpython.lib-python.3.test.test_base64.LegacyBase64TestCase.test_decode
10+
*graalpython.lib-python.3.test.test_base64.LegacyBase64TestCase.test_decodestring_warns
11+
*graalpython.lib-python.3.test.test_base64.LegacyBase64TestCase.test_encode
12+
*graalpython.lib-python.3.test.test_base64.LegacyBase64TestCase.test_encodestring_warns

0 commit comments

Comments
 (0)