Skip to content

Commit 0eff0e3

Browse files
committed
Merge remote-tracking branch 'origin/master' into topic/GR-13107
2 parents 21eb898 + 0158bfd commit 0eff0e3

39 files changed

+1338
-401
lines changed

ci.jsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@
251251
// unittests
252252
testGate(type="unittest", platform="linux"),
253253
testGate(type="unittest", platform="darwin"),
254+
testGate(type="svm-unittest", platform="linux"),
255+
testGate(type="svm-unittest", platform="darwin"),
254256

255257
// junit
256258
testGate(type="junit", platform="linux"),

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,14 @@ public int read() throws IOException {
109109
}
110110
};
111111
}
112+
113+
public int getTerminalWidth() {
114+
// deafult value
115+
return 80;
116+
}
117+
118+
public int getTerminalHeight() {
119+
// default value
120+
return 25;
121+
}
112122
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -247,6 +247,9 @@ protected void launch(Builder contextBuilder) {
247247

248248
ConsoleHandler consoleHandler = createConsoleHandler(System.in, System.out);
249249
contextBuilder.arguments(getLanguageId(), programArgs.toArray(new String[0])).in(consoleHandler.createInputStream());
250+
contextBuilder.option("python.TerminalIsInteractive", Boolean.toString(stdinIsInteractive));
251+
contextBuilder.option("python.TerminalWidth", Integer.toString(consoleHandler.getTerminalWidth()));
252+
contextBuilder.option("python.TerminalHeight", Integer.toString(consoleHandler.getTerminalHeight()));
250253

251254
int rc = 1;
252255
try (Context context = contextBuilder.build()) {
@@ -360,7 +363,7 @@ protected void printHelp(OptionCategory maxCategory) {
360363
"-B : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x\n" +
361364
"-c cmd : program passed in as string (terminates option list)\n" +
362365
// "-d : debug output from parser; also PYTHONDEBUG=x\n" +
363-
// "-E : ignore PYTHON* environment variables (such as PYTHONPATH)\n" +
366+
"-E : ignore PYTHON* environment variables (such as PYTHONPATH)\n" +
364367
"-h : print this help message and exit (also --help)\n" +
365368
"-i : inspect interactively after running script; forces a prompt even\n" +
366369
" if stdin does not appear to be a terminal; also PYTHONINSPECT=x\n" +

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,15 @@ public String[] getHistory() {
268268
}
269269
return result;
270270
}
271+
272+
@Override
273+
public int getTerminalHeight() {
274+
return console.getTerminal().getHeight();
275+
}
276+
277+
@Override
278+
public int getTerminalWidth() {
279+
return console.getTerminal().getWidth();
280+
}
281+
271282
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/grammar/TestParserTranslator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -71,6 +71,7 @@
7171
import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
7272
import com.oracle.graal.python.nodes.expression.CastToBooleanNode;
7373
import com.oracle.graal.python.nodes.expression.CastToBooleanNode.NotNode;
74+
import com.oracle.graal.python.nodes.expression.ContainsNode;
7475
import com.oracle.graal.python.nodes.expression.ExpressionNode;
7576
import com.oracle.graal.python.nodes.expression.IsNode;
7677
import com.oracle.graal.python.nodes.expression.OrNode;
@@ -358,9 +359,9 @@ public void parseComparisons() {
358359
parseAs("x <= y", BinaryComparisonNode.class);
359360
parseAs("x <> y", BinaryComparisonNode.class);
360361
parseAs("x != y", BinaryComparisonNode.class);
361-
parseAs("x in y", BinaryComparisonNode.class);
362+
parseAs("x in y", ContainsNode.class);
362363
CastToBooleanNode notNode = parseAs("x not in y", CastToBooleanNode.NotNode.class);
363-
getChild(notNode, 0, BinaryComparisonNode.class);
364+
getChild(notNode, 0, ContainsNode.class);
364365
parseAs("x is y", IsNode.class);
365366
notNode = parseAs("x is not y", CastToBooleanNode.NotNode.class);
366367
getChild(notNode, 0, IsNode.class);

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,18 @@ def test_destructuring():
8585
# TODO not supported yet
8686
# a, b, c = "\U0001d49c\U0001d49e\U0001d4b5"
8787
# assert a == '𝒜' and b == '𝒞' and c == '𝒵'
88+
89+
90+
def test_assigning_hidden_keys():
91+
class A():
92+
def __init__(self):
93+
self.__dict__["xyz"] = 1
94+
95+
ary = [A(), A(), A(), A(), A(), A()]
96+
for a in ary:
97+
a.foo = 12
98+
99+
for a in ary:
100+
id(a) # id is stored in a HiddenKey
101+
102+
return

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,3 +529,8 @@ def test_strip_bytearray():
529529
assert bytearray(b'abc').strip(b'ac') == b'b'
530530
assert bytearray(b'abc').lstrip(b'ac') == b'bc'
531531
assert bytearray(b'abc').rstrip(b'ac') == b'ab'
532+
533+
def test_strip_bytes():
534+
assert b'abc'.strip(b'ac') == b'b'
535+
assert b'abc'.lstrip(b'ac') == b'bc'
536+
assert b'abc'.rstrip(b'ac') == b'ab'

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ def __len__(self):
176176
assert set(d.keys()) == key_set, "unexpected keys: %s" % str(d.keys())
177177
assert set(d.values()) == { 97, 98, 99, 100 }, "unexpected values: %s" % str(d.values())
178178

179+
def test_init_kwargs():
180+
kwargs = {'ONE':'one', 'TWO' : 'two'}
181+
d = dict([(1,11),(2,22)], **kwargs)
182+
assert len(d) == 4, "invalid length, expected 4 but was %d" % len(d)
183+
assert set(d.keys()) == {1,2,'ONE','TWO'}, "unexpected keys: %s" % str(d.keys())
184+
assert set(d.values()) == { 11, 22, 'one', 'two' }, "unexpected values: %s" % str(d.values())
179185

180186
def test_custom_key_object0():
181187
class CollisionKey:

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2019, Oracle and/or its affiliates.
22
# Copyright (C) 1996-2017 Python Software Foundation
33
#
44
# Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -178,3 +178,46 @@ def func(*args):
178178
gen = (x for x in range(10))
179179
assert func(*lst) == set(lst)
180180
assert func(*gen) == set(lst)
181+
182+
183+
def test_generator_cell_confusion():
184+
# tfel: this demonstrates various errors we can get when we get confused
185+
# about the generator scopes and their parents for eager iterator
186+
# evaluation. In fact, all of these should work
187+
def unbound_local_l2():
188+
l1 = []
189+
l2 = []
190+
return [
191+
link for link in (
192+
(url for url in l1),
193+
(url for url in l2)
194+
)
195+
]
196+
197+
assert len(unbound_local_l2()) == 2
198+
199+
def assertion_error_getting_closure_from_locals():
200+
l1 = []
201+
l2 = []
202+
l3 = []
203+
return [
204+
link for link in (
205+
(url for url in l1),
206+
(url for url in l2),
207+
(url for url in l3),
208+
)
209+
]
210+
211+
assert len(assertion_error_getting_closure_from_locals()) == 3
212+
213+
def illegal_state_expected_cell_got_list():
214+
l11, l1 = [], []
215+
l22, l2 = [], []
216+
return [
217+
link for link in (
218+
(url for url in l1),
219+
(url for url in l2),
220+
)
221+
]
222+
223+
assert len(illegal_state_expected_cell_got_list()) == 2

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

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2019, 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
@@ -60,29 +60,29 @@ def test_int_subclassing():
6060
MAXREPEAT = _NamedIntConstant(1, 'MAXREPEAT')
6161
assert MAXREPEAT == 1
6262
assert str(MAXREPEAT) == "MAXREPEAT"
63-
63+
6464

6565
def test_boolean2int():
6666
assert int(True) == 1
6767
assert int(False) == 0
68-
69-
68+
69+
7070
def test_int_from_custom():
7171
class CustomInt4():
7272
def __int__(self):
7373
return 1
74-
74+
7575
class CustomInt8():
7676
def __int__(self):
7777
return 0xCAFEBABECAFED00D
78-
78+
7979
class SubInt(int):
8080
def __int__(self):
8181
return 0xBADF00D
82-
82+
8383
class NoInt():
8484
pass
85-
85+
8686
assert int(CustomInt4()) == 1
8787
assert int(CustomInt8()) == 0xCAFEBABECAFED00D
8888
assert CustomInt8() != 0xCAFEBABECAFED00D
@@ -124,7 +124,7 @@ def builtinTest(number):
124124
builtinTest(9)
125125
builtinTest(6227020800)
126126
builtinTest(9999992432902008176640000999999)
127-
127+
128128
assert True.__int__() == 1
129129
assert False.__int__() == 0
130130

@@ -161,13 +161,13 @@ def builtinTest(number):
161161
builtinTest(9)
162162
builtinTest(6227020800)
163163
builtinTest(9999992432902008176640000999999)
164-
164+
165165
assert True.real == 1
166166
assert False.real == 0
167167
assert True.imag == 0
168168
assert False.imag == 0
169169

170-
def test_real_imag_subclass():
170+
def test_real_imag_subclass():
171171
def subclassTest(number):
172172
a = MyInt(number)
173173
b = a.real
@@ -202,7 +202,7 @@ def builtinTest(number):
202202
builtinTest(9)
203203
builtinTest(6227020800)
204204
builtinTest(9999992432902008176640000999999)
205-
205+
206206
assert True.numerator == 1
207207
assert False.numerator == 0
208208
assert True.denominator == 1
@@ -240,7 +240,7 @@ def builtinTest(number):
240240
builtinTest(9)
241241
builtinTest(6227020800)
242242
builtinTest(9999992432902008176640000999999)
243-
243+
244244
assert True.conjugate() == 1
245245
assert False.conjugate() == 0
246246

@@ -282,7 +282,7 @@ def builtinTest(number):
282282
builtinTest(9)
283283
builtinTest(6227020800)
284284
builtinTest(9999992432902008176640000999999)
285-
285+
286286
assert True.__trunc__() == 1
287287
assert False.__trunc__() == 0
288288

@@ -325,7 +325,7 @@ def test_create_int_from_string():
325325

326326

327327
class FromBytesTests(unittest.TestCase):
328-
328+
329329
def check(self, tests, byteorder, signed=False):
330330
for test, expected in tests.items():
331331
try:
@@ -447,10 +447,10 @@ def test_from_list(self):
447447
class LyingList(list):
448448
def __iter__(self):
449449
return iter([10, 20, 30, 40])
450-
450+
451451
self.assertEqual(
452452
int.from_bytes(LyingList([255, 1, 1]), 'big'), 169090600)
453-
453+
454454
def test_from_tuple(self):
455455
self.assertEqual(
456456
int.from_bytes((255, 0, 0), 'big', signed=True), -65536)
@@ -464,7 +464,7 @@ def __iter__(self):
464464
return iter((15, 25, 35, 45))
465465
self.assertEqual(
466466
int.from_bytes(LyingTuple((255, 1, 1)), 'big'), 253305645)
467-
467+
468468
def test_from_bytearray(self):
469469
self.assertEqual(int.from_bytes(
470470
bytearray(b'\xff\x00\x00'), 'big', signed=True), -65536)
@@ -487,11 +487,10 @@ def test_wrong_input(self):
487487
self.assertRaises(TypeError, int.from_bytes, 0, 'big')
488488
self.assertRaises(TypeError, int.from_bytes, 0, 'big', True)
489489

490-
#TODO uncoment these tests, when GR-12453 is fixed
491-
#self.assertRaises(TypeError, int.from_bytes, "", 'big')
492-
#self.assertRaises(TypeError, int.from_bytes, "\x00", 'big')
493-
#self.assertRaises(TypeError, MyInt.from_bytes, "", 'big')
494-
#self.assertRaises(TypeError, MyInt.from_bytes, "\x00", 'big')
490+
self.assertRaises(TypeError, int.from_bytes, "", 'big')
491+
self.assertRaises(TypeError, int.from_bytes, "\x00", 'big')
492+
self.assertRaises(TypeError, MyInt.from_bytes, "", 'big')
493+
self.assertRaises(TypeError, MyInt.from_bytes, "\x00", 'big')
495494
self.assertRaises(TypeError, MyInt.from_bytes, 0, 'big')
496495
self.assertRaises(TypeError, int.from_bytes, 0, 'big', True)
497496

@@ -550,7 +549,7 @@ class mybyteslike2():
550549
def __bytes__(self):
551550
return array.array('b', [2, 2, 3])
552551

553-
self.assertRaises(TypeError, int.from_bytes, mybyteslike2(), 'big')
552+
self.assertRaises(TypeError, int.from_bytes, mybyteslike2(), 'big')
554553

555554
def test_from_list_with_byteslike(self):
556555
class StrangeList(list):
@@ -564,7 +563,7 @@ def __iter__(self):
564563
class ToBytesTests(unittest.TestCase):
565564

566565
class MyInt(int):
567-
pass
566+
pass
568567

569568
def check(self, tests, byteorder, signed=False):
570569
for test, expected in tests.items():
@@ -634,7 +633,7 @@ def test_SignedLittleEndian(self):
634633
}
635634
self.check(tests2, 'little', signed=True)
636635
self.checkPIntSpec(tests2, 'little', signed=True)
637-
636+
638637
def test_UnsignedBigEndian(self):
639638
# Convert integers to unsigned big-endian byte arrays.
640639
tests3 = {
@@ -706,7 +705,5 @@ def __int__(self):
706705
return 3
707706
def __index__(self):
708707
return 4
709-
710-
self.assertEqual(MyTest(1).to_bytes(MyTest(10), 'big'), b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01')
711-
712708

709+
self.assertEqual(MyTest(1).to_bytes(MyTest(10), 'big'), b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01')

0 commit comments

Comments
 (0)