Skip to content

Commit 85bfd22

Browse files
committed
[GR-23234] More fixes for test_generators doctests
PullRequest: graalpython/1173
2 parents 4703b87 + 24359ad commit 85bfd22

Some content is hidden

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

43 files changed

+1194
-610
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.graal.python.test.generator;
42+
43+
import org.junit.Ignore;
44+
import org.junit.Test;
45+
46+
import com.oracle.graal.python.test.PythonTests;
47+
48+
public class YieldExpressionTests {
49+
@Test
50+
public void testYieldExprAnd1() {
51+
String source = "list((lambda: str(print('x')) and str((yield)) and str(print('y')))())";
52+
PythonTests.assertPrints("x\ny\n", source);
53+
}
54+
55+
@Test
56+
public void testYieldExprAnd2() {
57+
String source = "list((lambda: str(print('x')) and (yield) and str(print('y')))())";
58+
PythonTests.assertPrints("x\n", source);
59+
}
60+
61+
@Test
62+
public void testYieldExprOr1() {
63+
String source = "list((lambda: print('x') or (yield) or print('y'))())";
64+
PythonTests.assertPrints("x\ny\n", source);
65+
}
66+
67+
@Test
68+
public void testYieldExprOr2() {
69+
String source = "list((lambda: print('x') or str((yield)) or print('y'))())";
70+
PythonTests.assertPrints("x\n", source);
71+
}
72+
73+
@Test
74+
public void testYieldExprAdd() {
75+
String source = "list((lambda: str(print('x')) + str((yield)) + str(print('y')))())";
76+
PythonTests.assertPrints("x\ny\n", source);
77+
}
78+
79+
@Test
80+
public void testYieldExprSub() {
81+
String source = "list((lambda: int(print('x') or 5) - int((yield) or 5) - int(print('y') or 5))())";
82+
PythonTests.assertPrints("x\ny\n", source);
83+
}
84+
85+
@Test
86+
public void testYieldExprMul() {
87+
String source = "list((lambda: int(print('x') or 5) * int((yield) or 5) * int(print('y') or 5))())";
88+
PythonTests.assertPrints("x\ny\n", source);
89+
}
90+
91+
@Test
92+
public void testYieldExprFloordiv() {
93+
String source = "list((lambda: int(print('x') or 5) // int((yield) or 5) // int(print('y') or 5))())";
94+
PythonTests.assertPrints("x\ny\n", source);
95+
}
96+
97+
@Test
98+
public void testYieldExprTruediv() {
99+
String source = "list((lambda: int(print('x') or 5) / int((yield) or 5) / int(print('y') or 5))())";
100+
PythonTests.assertPrints("x\ny\n", source);
101+
}
102+
103+
@Test
104+
public void testYieldExprMod() {
105+
String source = "list((lambda: int(print('x') or 5) % int((yield) or 5) % int(print('y') or 5))())";
106+
PythonTests.assertPrints("x\ny\n", source);
107+
}
108+
109+
@Test
110+
public void testYieldExprPow() {
111+
String source = "list((lambda: int(print('x') or 5) ** int((yield) or 5) ** int(print('y') or 5))())";
112+
PythonTests.assertPrints("x\ny\n", source);
113+
}
114+
115+
@Test
116+
public void testYieldExprBitAnd() {
117+
String source = "list((lambda: int(print('x') or 5) & int((yield) or 5) & int(print('y') or 5))())";
118+
PythonTests.assertPrints("x\ny\n", source);
119+
}
120+
121+
@Test
122+
public void testYieldExprBitOr() {
123+
String source = "list((lambda: int(print('x') or 5) | int((yield) or 5) | int(print('y') or 5))())";
124+
PythonTests.assertPrints("x\ny\n", source);
125+
}
126+
127+
@Test
128+
public void testYieldExprBitXor() {
129+
String source = "list((lambda: int(print('x') or 5) ^ int((yield) or 5) ^ int(print('y') or 5))())";
130+
PythonTests.assertPrints("x\ny\n", source);
131+
}
132+
133+
@Test
134+
public void testYieldExprBitLShift() {
135+
String source = "list((lambda: int(print('x') or 5) << int((yield) or 5) << int(print('y') or 5))())";
136+
PythonTests.assertPrints("x\ny\n", source);
137+
}
138+
139+
@Test
140+
public void testYieldExprBitRShift() {
141+
String source = "list((lambda: int(print('x') or 5) >> int((yield) or 5) >> int(print('y') or 5))())";
142+
PythonTests.assertPrints("x\ny\n", source);
143+
}
144+
145+
@Test
146+
public void testYieldExprEq() {
147+
String source = "list((lambda: int(print('x') or 5) == int((yield) or 5))())";
148+
PythonTests.assertPrints("x\n", source);
149+
}
150+
151+
@Test
152+
public void testYieldExprNe() {
153+
String source = "list((lambda: int(print('x') or 5) != int((yield) or 5))())";
154+
PythonTests.assertPrints("x\n", source);
155+
}
156+
157+
@Test
158+
public void testYieldExprGt() {
159+
String source = "list((lambda: int(print('x') or 5) > int((yield) or 5))())";
160+
PythonTests.assertPrints("x\n", source);
161+
}
162+
163+
@Test
164+
public void testYieldExprGe() {
165+
String source = "list((lambda: int(print('x') or 5) >= int((yield) or 5))())";
166+
PythonTests.assertPrints("x\n", source);
167+
}
168+
169+
@Test
170+
public void testYieldExprLt() {
171+
String source = "list((lambda: int(print('x') or 5) < int((yield) or 5))())";
172+
PythonTests.assertPrints("x\n", source);
173+
}
174+
175+
@Test
176+
public void testYieldExprLe() {
177+
String source = "list((lambda: int(print('x') or 5) <= int((yield) or 5))())";
178+
PythonTests.assertPrints("x\n", source);
179+
}
180+
181+
@Test
182+
public void testYieldExprIs() {
183+
String source = "list((lambda: int(print('x') or 5) is int((yield) or 5))())";
184+
PythonTests.assertPrints("x\n", source);
185+
}
186+
187+
@Test
188+
public void testYieldExprIn() {
189+
String source = "list((lambda: int(print('x') or 5) in [(yield) or 5])())";
190+
PythonTests.assertPrints("x\n", source);
191+
}
192+
193+
@Test
194+
public void testYieldExprTuple() {
195+
String source = "list((lambda: (print('x'), (yield), print('y')))())";
196+
PythonTests.assertPrints("x\ny\n", source);
197+
}
198+
199+
@Test
200+
public void testYieldExprList() {
201+
String source = "list((lambda: [print('x'), (yield), print('y')])())";
202+
PythonTests.assertPrints("x\ny\n", source);
203+
}
204+
205+
@Test
206+
public void testYieldExprSet() {
207+
String source = "list((lambda: {print('x'), (yield), print('y')})())";
208+
PythonTests.assertPrints("x\ny\n", source);
209+
}
210+
211+
@Test
212+
public void testYieldExprDict() {
213+
String source = "list((lambda: {'a': print('x'), 'b': (yield), 'c': print('y')})())";
214+
PythonTests.assertPrints("x\ny\n", source);
215+
}
216+
217+
@Test
218+
@Ignore // TODO
219+
public void testYieldExprCall() {
220+
String source = "list((lambda: dict({'a': print('x')}, b=(yield), c=print('y'), d=(yield)))())";
221+
PythonTests.assertPrints("x\ny\n", source);
222+
}
223+
224+
@Test
225+
@Ignore // TODO
226+
public void testYieldExprDef() {
227+
String source = "def gen():\n" +
228+
" def inner(a=print('x'), b=(yield), c=print('y')):\n" +
229+
" pass\n" +
230+
"list(gen())";
231+
PythonTests.assertPrints("x\ny\n", source);
232+
}
233+
234+
@Test
235+
@Ignore // TODO
236+
public void testYieldExprSlice() {
237+
String source = "list((lambda: [][print('x') or 1:(yield) or 1:print('y') or 1])())";
238+
PythonTests.assertPrints("x\ny\n", source);
239+
}
240+
241+
@Test
242+
@Ignore // TODO
243+
public void testYieldExprTernaryIf1() {
244+
String source = "list((lambda: (yield) if print('x') else print('y'))())";
245+
PythonTests.assertPrints("x\ny\n", source);
246+
}
247+
248+
@Test
249+
@Ignore // TODO
250+
public void testYieldExprTernaryIf2() {
251+
String source = "list((lambda: print('y') if print('x') else (yield))())";
252+
PythonTests.assertPrints("x\n", source);
253+
}
254+
255+
@Test
256+
public void testYieldExprWith() {
257+
String source = "class cm:\n" +
258+
" def __init__(self):\n" +
259+
" print('init')\n" +
260+
" def __enter__(self, *args):\n" +
261+
" print('enter')\n" +
262+
" def __exit__(self, *args):\n" +
263+
" print('exit')\n" +
264+
"def gen():\n" +
265+
" with cm() as x, ((yield) or cm()) as y:\n" +
266+
" pass\n" +
267+
"list(gen())";
268+
PythonTests.assertPrints("init\nenter\ninit\nenter\nexit\nexit\n", source);
269+
}
270+
271+
@Test
272+
@Ignore // TODO
273+
public void testYieldExprFString() {
274+
String source = "list((lambda: f\"{print('x')}{(yield)}{print('y')}\")())";
275+
PythonTests.assertPrints("x\ny\n", source);
276+
}
277+
}

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

Lines changed: 7 additions & 1 deletion
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, 2020, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -65,4 +65,10 @@ public void notInList() {
6565
assertPrints("True\nFalse\nFalse\nFalse\n", source);
6666
}
6767

68+
@Test
69+
public void inEvaluationOrder() {
70+
String source = "print('a') in [print('b')]";
71+
assertPrints("a\nb\n", source);
72+
}
73+
6874
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
*graalpython.lib-python.3.test.test_generators.GeneratorTest.test_name
1414
*graalpython.lib-python.3.test.test_generators.GeneratorTest.test_pickle
1515
*graalpython.lib-python.3.test.test_generators.SignalAndYieldFromTest.test_raise_and_yield_from
16+
*graalpython.lib-python.3.test.test_generators.TestMain.test_main
1617
*graalpython.lib-python.3.test.test_generators.YieldFromTests.test_generator_gi_yieldfrom

graalpython/com.oracle.graal.python.test/testData/goldenFiles/BasicTests/for14.tast

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ ModuleRootNode Name: <module 'for14'> SourceSection: [0,165]`def merge(sequences
6767
YesNodeGen SourceSection: None
6868
IsBuiltinClassProfile SourceSection: None
6969
CachedDispatchFirst SourceSection: None
70+
ReadGlobalOrBuiltinNodeGen SourceSection: [91,100]`candidate`
71+
Identifier: candidate
72+
ReadAttributeFromObjectNotTypeNodeGen SourceSection: None
7073
GetItemNodeGen SourceSection: [104,110]`s2[1:]`
7174
ReadLocalVariableNode SourceSection: None
7275
Frame: [1,s2,Illegal]
@@ -77,9 +80,6 @@ ModuleRootNode Name: <module 'for14'> SourceSection: [0,165]`def merge(sequences
7780
Value: 1
7881
EmptyNode SourceSection: None
7982
EmptyNode SourceSection: None
80-
ReadGlobalOrBuiltinNodeGen SourceSection: [91,100]`candidate`
81-
Identifier: candidate
82-
ReadAttributeFromObjectNotTypeNodeGen SourceSection: None
8383
BreakNode SourceSection: [128,133]`break`
8484
BlockNode SourceSection: None
8585
GetIteratorExpressionNodeGen SourceSection: [65,74]`sequences`

graalpython/com.oracle.graal.python.test/testData/goldenFiles/YieldStatementTests/customIter01.scope

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Scope: []
1010
FreeVars: Empty
1111
Scope: gen
1212
Kind: Generator
13-
FrameDescriptor: [ret, MyIter, <return_val>]
13+
FrameDescriptor: [ret, MyIter, <>temp2, <return_val>]
1414
CellVars: Empty
1515
FreeVars: [MyIter, ret]
1616
Scope: MyIter

0 commit comments

Comments
 (0)