Skip to content

Commit d35c1b0

Browse files
committed
Merge branch 'master'
2 parents 8e40b9b + ab8c9de commit d35c1b0

File tree

318 files changed

+3579
-1635
lines changed

Some content is hidden

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

318 files changed

+3579
-1635
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ GRAALPYTHON_UNIT_TESTS.dist
2121
mx.graalpython/eclipse-launches
2222
asv
2323
*.json
24+
!**/resources/*.json
2425
language
2526
*.bc
2627
*.iml

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/nodes/literal/FormatStringTests.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2020, 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
@@ -41,14 +41,15 @@
4141

4242
package com.oracle.graal.python.nodes.literal;
4343

44+
import org.junit.Assert;
45+
import org.junit.Test;
46+
4447
import com.oracle.graal.python.runtime.PythonParser;
4548
import com.oracle.graal.python.test.parser.ParserTestBase;
4649
import com.oracle.truffle.api.Truffle;
4750
import com.oracle.truffle.api.frame.FrameDescriptor;
4851
import com.oracle.truffle.api.frame.VirtualFrame;
4952
import com.oracle.truffle.api.nodes.Node;
50-
import org.junit.Assert;
51-
import org.junit.Test;
5253

5354
public class FormatStringTests extends ParserTestBase {
5455

@@ -207,6 +208,11 @@ public void quotes01() throws Exception {
207208
testFormatString("f'{\"{{}}\"}'", "format((\"{{}}\"))");
208209
}
209210

211+
@Test
212+
public void embeddedColon() throws Exception {
213+
testFormatString("f'{var[:1]}'", "format((var[:1]))");
214+
}
215+
210216
@Test
211217
public void parser01() throws Exception {
212218
testFormatString("f'{name}'", "format((name))");
@@ -352,7 +358,7 @@ private void testFormatString(String text, String expected) throws Exception {
352358

353359
Assert.assertTrue("The source has to be just fstring", parserResult instanceof FormatStringLiteralNode);
354360
FormatStringLiteralNode fsl = (FormatStringLiteralNode) parserResult;
355-
int[][] tokens = FormatStringLiteralNode.createTokens(fsl, fsl.getValues(), true);
361+
int[][] tokens = FormatStringLiteralNode.createTokens(fsl, fsl.getValues());
356362
FormatStringLiteralNode.StringPart[] fslParts = fsl.getValues();
357363
String[] expressions = FormatStringLiteralNode.createExpressionSources(fslParts, tokens, 0, tokens.length);
358364
int expressionsIndex = 0;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
def test_special_descriptor():
41+
class A:
42+
@property
43+
def __eq__(self):
44+
def inner(other):
45+
return True
46+
return inner
47+
48+
assert A() == A()
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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 unittest
41+
42+
43+
class Polymorph:
44+
def __index__(self):
45+
return 42
46+
def __int__(self):
47+
return 1
48+
def __float__(self):
49+
return 3.14
50+
def __str__(self):
51+
return "hello"
52+
def __bytes__(self):
53+
return b"bytes"
54+
55+
56+
# This is all one needs to implement to satisfy PyCheck_Mapping
57+
class MyPseudoMapping:
58+
def __getitem__(self, item):
59+
return item
60+
61+
62+
def test_formatting():
63+
# tests some corner-cases that the standard tests do not cover
64+
assert format(-12e8, "0=30,.4f") == '-0,000,000,001,200,000,000.0000'
65+
assert b"%(mykey)d" % {b'mykey': 42} == b"42"
66+
assert b"%c" % b'q' == b"q"
67+
assert "%-5d" % 42 == "42 "
68+
assert "%.*f" % (-2, 2.5) == "2"
69+
assert "%.*f" % (True, 2.51) == "2.5"
70+
assert "%ld" % 42 == "42"
71+
72+
assert "%c" % Polymorph() == "*"
73+
assert "%d" % Polymorph() == "1"
74+
assert "%x" % Polymorph() == "2a"
75+
assert "%s" % Polymorph() == "hello"
76+
assert "%.2f" % Polymorph() == "3.14"
77+
assert b"%c" % Polymorph() == b"*"
78+
assert b"%s" % Polymorph() == b"bytes"
79+
80+
assert type(bytearray("hello %d", "ascii") % 42) == bytearray
81+
assert type(b"hello %d" % 42) == bytes
82+
83+
# No error about too many arguments,
84+
# because the object is considered as a mapping...
85+
assert " " % MyPseudoMapping() == " "
86+
87+
88+
def test_complex_formatting():
89+
assert format(3+2j, ">20,.4f") == " 3.0000+2.0000j"
90+
assert format(3+2j, "+.2f") == "+3.00+2.00j"
91+
assert format(-3+2j, "+.2f") == "-3.00+2.00j"
92+
assert format(3+2j, "-.3f") == "3.000+2.000j"
93+
assert format(3-2j, "-.3f") == "3.000-2.000j"
94+
assert format(-3-2j, "-.3f") == "-3.000-2.000j"
95+
assert format(3+2j, " .1f") == " 3.0+2.0j"
96+
assert format(-3+2j, " .1f") == "-3.0+2.0j"
97+
assert format(complex(3), ".1g") == "3+0j"
98+
assert format(3j, ".1g") == "0+3j"
99+
assert format(-3j, ".1g") == "-0-3j"
100+
assert format(3j, "") == "3j"
101+
assert format(1+0j, "") == "(1+0j)"
102+
assert format(1+2j, "") == "(1+2j)"
103+
assert format(complex(1, float("NaN")), "") == "(1+nanj)"
104+
assert format(complex(1, float("Inf")), "") == "(1+infj)"
105+
106+
107+
class AnyRepr:
108+
def __init__(self, val):
109+
self.val = val
110+
def __repr__(self):
111+
return self.val
112+
113+
114+
def test_non_ascii_repr():
115+
assert "%a" % AnyRepr("\t") == "\t"
116+
assert "%a" % AnyRepr("\\") == "\\"
117+
assert "%a" % AnyRepr("\\") == "\\"
118+
assert "%a" % AnyRepr("\u0378") == "\\u0378"
119+
assert "%r" % AnyRepr("\u0378") == "\u0378"
120+
assert "%a" % AnyRepr("\u0374") == "\\u0374"
121+
assert "%r" % AnyRepr("\u0374") == "\u0374"
122+
123+
assert b"%a" % AnyRepr("\t") == b"\t"
124+
assert b"%a" % AnyRepr("\\") == b"\\"
125+
assert b"%a" % AnyRepr("\\") == b"\\"
126+
assert b"%a" % AnyRepr("\u0378") == b"\\u0378"
127+
assert b"%r" % AnyRepr("\u0378") == b"\\u0378"
128+
assert b"%a" % AnyRepr("\u0374") == b"\\u0374"
129+
assert b"%r" % AnyRepr("\u0374") == b"\\u0374"
130+
131+
132+
class FormattingErrorsTest(unittest.TestCase):
133+
def test_formatting_errors(self):
134+
self.assertRaises(TypeError, lambda: format(-12e8, b"0=30,.4f"))
135+
self.assertRaises(TypeError, lambda: format(42, b"0=30,.4f"))
136+
self.assertRaises(TypeError, lambda: format("str", b"0=30,.4f"))
137+
self.assertRaises(TypeError, lambda: format(3+1j, b"0=30,.4f"))
138+
self.assertRaises(TypeError, lambda: b"hello" % b"world")
139+
self.assertRaises(TypeError, lambda: b"%f" % "str")
140+
self.assertRaises(TypeError, lambda: b"%c" % "str")
141+
142+
self.assertRaises(KeyError, lambda: b"%(mykey)d" % {"mykey": 42})
143+
self.assertRaises(KeyError, lambda: "%(mykey)d" % {b"mykey": 42})
144+
self.assertRaises(OverflowError, lambda: b"%c" % 260)
145+
146+
self.assertRaises(ValueError, lambda: format(3+2j, "f=30,.4f"))
147+
self.assertRaises(ValueError, lambda: format(3+2j, "0=30,.4f"))
148+
149+
150+
class MyFloat(float):
151+
def __str__(self):
152+
return "__str__ overridden for float"
153+
154+
155+
def test_overridden_str():
156+
assert "{}".format(MyFloat(2)) == "__str__ overridden for float"
157+
assert "{0:10}".format(MyFloat(2)) == " 2.0"

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ def test_small_int_id_is_constant():
4444
assert id(x) == id(y) == id(128)
4545

4646

47-
def test_string_id_is_constant():
48-
assert id("str") == id("str")
49-
x = "str"
50-
y = "str"
51-
assert id(x) == id(y) == id("str")
52-
53-
5447
def test_object_id_is_constant():
5548
x = object()
5649
xid = id(x)

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_exec
1111
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_exec_redirected
1212
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_filter
13+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_filter_pickle
1314
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_hex
1415
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_id
1516
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_isinstance
@@ -31,6 +32,16 @@
3132
*graalpython.lib-python.3.test.test_builtin.PtyTests.test_input_tty
3233
*graalpython.lib-python.3.test.test_builtin.PtyTests.test_input_tty_non_ascii
3334
*graalpython.lib-python.3.test.test_builtin.PtyTests.test_input_tty_non_ascii_unicode_errors
35+
*graalpython.lib-python.3.test.test_builtin.TestBreakpoint.test_breakpoint
36+
*graalpython.lib-python.3.test.test_builtin.TestBreakpoint.test_breakpoint_with_args_and_keywords
37+
*graalpython.lib-python.3.test.test_builtin.TestBreakpoint.test_breakpoint_with_breakpointhook_reset
38+
*graalpython.lib-python.3.test.test_builtin.TestBreakpoint.test_breakpoint_with_breakpointhook_set
3439
*graalpython.lib-python.3.test.test_builtin.TestBreakpoint.test_breakpoint_with_passthru_error
40+
*graalpython.lib-python.3.test.test_builtin.TestBreakpoint.test_envar_good_path_builtin
41+
*graalpython.lib-python.3.test.test_builtin.TestBreakpoint.test_envar_good_path_empty_string
42+
*graalpython.lib-python.3.test.test_builtin.TestBreakpoint.test_envar_good_path_noop_0
43+
*graalpython.lib-python.3.test.test_builtin.TestBreakpoint.test_envar_good_path_other
44+
*graalpython.lib-python.3.test.test_builtin.TestBreakpoint.test_envar_ignored_when_hook_is_set
45+
*graalpython.lib-python.3.test.test_builtin.TestBreakpoint.test_envar_unimportable
3546
*graalpython.lib-python.3.test.test_builtin.TestSorted.test_basic
3647
*graalpython.lib-python.3.test.test_builtin.TestSorted.test_inputtypes

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
*graalpython.lib-python.3.test.test_bytes.ByteArrayTest.test_getslice
3535
*graalpython.lib-python.3.test.test_bytes.ByteArrayTest.test_iconcat
3636
*graalpython.lib-python.3.test.test_bytes.ByteArrayTest.test_iterator_length_hint
37+
*graalpython.lib-python.3.test.test_bytes.ByteArrayTest.test_iterator_pickling
3738
*graalpython.lib-python.3.test.test_bytes.ByteArrayTest.test_join
3839
*graalpython.lib-python.3.test.test_bytes.ByteArrayTest.test_maketrans
3940
*graalpython.lib-python.3.test.test_bytes.ByteArrayTest.test_nosort
@@ -81,6 +82,7 @@
8182
*graalpython.lib-python.3.test.test_bytes.BytesTest.test_from_ssize
8283
*graalpython.lib-python.3.test.test_bytes.BytesTest.test_from_tuple
8384
*graalpython.lib-python.3.test.test_bytes.BytesTest.test_getslice
85+
*graalpython.lib-python.3.test.test_bytes.BytesTest.test_iterator_pickling
8486
*graalpython.lib-python.3.test.test_bytes.BytesTest.test_join
8587
*graalpython.lib-python.3.test.test_bytes.BytesTest.test_maketrans
8688
*graalpython.lib-python.3.test.test_bytes.BytesTest.test_ord

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
*graalpython.lib-python.3.test.test_calendar.CalendarTestCase.test_months
1111
*graalpython.lib-python.3.test.test_calendar.CalendarTestCase.test_setfirstweekday
1212
*graalpython.lib-python.3.test.test_calendar.CommandLineTestCase.test_help
13+
*graalpython.lib-python.3.test.test_calendar.CommandLineTestCase.test_html_output_current_year
14+
*graalpython.lib-python.3.test.test_calendar.CommandLineTestCase.test_html_output_year_css
15+
*graalpython.lib-python.3.test.test_calendar.CommandLineTestCase.test_html_output_year_encoding
16+
*graalpython.lib-python.3.test.test_calendar.CommandLineTestCase.test_illegal_arguments
1317
*graalpython.lib-python.3.test.test_calendar.LeapdaysTestCase.test_no_leapdays
1418
*graalpython.lib-python.3.test.test_calendar.LeapdaysTestCase.test_no_leapdays_upper_boundary
1519
*graalpython.lib-python.3.test.test_calendar.LeapdaysTestCase.test_no_range

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*graalpython.lib-python.3.test.test_class.ClassTests.testBadTypeReturned
2+
*graalpython.lib-python.3.test.test_class.ClassTests.testForExceptionsRaisedInInstanceGetattr2
23
*graalpython.lib-python.3.test.test_class.ClassTests.testGetSetAndDel
34
*graalpython.lib-python.3.test.test_class.ClassTests.testInit
45
*graalpython.lib-python.3.test.test_class.ClassTests.testMisc

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
*graalpython.lib-python.3.test.test_dict.DictTest.test_init_use_after_free
2727
*graalpython.lib-python.3.test.test_dict.DictTest.test_instance_dict_getattr_str_subclass
2828
*graalpython.lib-python.3.test.test_dict.DictTest.test_invalid_keyword_arguments
29+
*graalpython.lib-python.3.test.test_dict.DictTest.test_itemiterator_pickling
2930
*graalpython.lib-python.3.test.test_dict.DictTest.test_items
31+
*graalpython.lib-python.3.test.test_dict.DictTest.test_iterator_pickling
3032
*graalpython.lib-python.3.test.test_dict.DictTest.test_keys
3133
*graalpython.lib-python.3.test.test_dict.DictTest.test_keys_contained
3234
*graalpython.lib-python.3.test.test_dict.DictTest.test_len
@@ -46,6 +48,9 @@
4648
*graalpython.lib-python.3.test.test_dict.DictTest.test_reverse_iterator_for_empty_dict
4749
*graalpython.lib-python.3.test.test_dict.DictTest.test_reverse_iterator_for_shared_shared_dicts
4850
*graalpython.lib-python.3.test.test_dict.DictTest.test_reversed
51+
*graalpython.lib-python.3.test.test_dict.DictTest.test_reverseitemiterator_pickling
52+
*graalpython.lib-python.3.test.test_dict.DictTest.test_reverseiterator_pickling
53+
*graalpython.lib-python.3.test.test_dict.DictTest.test_reversevaluesiterator_pickling
4954
*graalpython.lib-python.3.test.test_dict.DictTest.test_setdefault
5055
*graalpython.lib-python.3.test.test_dict.DictTest.test_setitem_atomic_at_resize
5156
*graalpython.lib-python.3.test.test_dict.DictTest.test_splittable_del
@@ -60,6 +65,7 @@
6065
*graalpython.lib-python.3.test.test_dict.DictTest.test_tuple_keyerror
6166
*graalpython.lib-python.3.test.test_dict.DictTest.test_update
6267
*graalpython.lib-python.3.test.test_dict.DictTest.test_values
68+
*graalpython.lib-python.3.test.test_dict.DictTest.test_valuesiterator_pickling
6369
*graalpython.lib-python.3.test.test_dict.GeneralMappingTests.test_bool
6470
*graalpython.lib-python.3.test.test_dict.GeneralMappingTests.test_constructor
6571
*graalpython.lib-python.3.test.test_dict.GeneralMappingTests.test_get

0 commit comments

Comments
 (0)