Skip to content

Commit 4919813

Browse files
committed
[GR-29404] [GR-28486] Expand our TCK coverage to iterables/iterators, exceptions, meta objects, date/time/duration
PullRequest: graalpython/1658
2 parents 484ee94 + a703d75 commit 4919813

36 files changed

+789
-562
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ language runtime. The main focus is on user-observable behavior of the engine.
77

88
* Added subclassing of Java classes in JVM mode
99
* Use native posix functions in the GraalPython Launcher
10+
* Support iterating over Python objects from Java and other languages as well as iterating over foreign objects in Python
11+
* Support catching foreign exceptions in catch-all except clauses
12+
13+
## Version 21.1.0
14+
15+
* Support catching exceptions from other languages or Java with catch-all except blocks
16+
* Support iterating over iterables from other languages, as well as allow other languages to iterate over Python iterables and iterators
17+
* Support isinstance and issubclass with instances and classes of other languages
1018

1119
## Version 21.0.0
1220

graalpython/com.oracle.graal.python.tck/src/com/oracle/graal/python/tck/PythonProvider.java

Lines changed: 159 additions & 289 deletions
Large diffs are not rendered by default.

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/builtins/modules/DirFdConversionNodeTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import com.oracle.truffle.api.nodes.RootNode;
5757
import org.graalvm.polyglot.Context;
5858
import org.hamcrest.CoreMatchers;
59+
import org.junit.After;
5960
import org.junit.Assert;
6061
import org.junit.Before;
6162
import org.junit.Rule;
@@ -74,6 +75,11 @@ public void setUp() {
7475
PythonTests.enterContext();
7576
}
7677

78+
@After
79+
public void tearDown() {
80+
PythonTests.closeContext();
81+
}
82+
7783
@Test
7884
public void none() {
7985
Assert.assertEquals(PosixSupportLibrary.DEFAULT_DIR_FD, call(PNone.NONE));

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/builtins/modules/FileDescriptorConversionNodeTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
import org.graalvm.polyglot.Context;
4848
import org.hamcrest.CoreMatchers;
49+
import org.junit.After;
4950
import org.junit.Assert;
5051
import org.junit.Before;
5152
import org.junit.Rule;
@@ -75,6 +76,11 @@ public void setUp() {
7576
PythonTests.enterContext();
7677
}
7778

79+
@After
80+
public void tearDown() {
81+
PythonTests.closeContext();
82+
}
83+
7884
@Test
7985
public void none() {
8086
expectedException.expect(PException.class);

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/nodes/util/CastToJavaUnsignedLongNodeTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.oracle.truffle.api.Truffle;
5050
import com.oracle.truffle.api.frame.VirtualFrame;
5151
import com.oracle.truffle.api.nodes.RootNode;
52+
import org.junit.After;
5253
import org.junit.Assert;
5354
import org.junit.Before;
5455
import org.junit.Test;
@@ -66,6 +67,11 @@ public void setUp() {
6667
PythonTests.enterContext();
6768
}
6869

70+
@After
71+
public void tearDown() {
72+
PythonTests.closeContext();
73+
}
74+
6975
@Test
7076
public void positiveInt() {
7177
Assert.assertEquals(0, castInt(0));

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/nodes/util/NarrowBigIntegerNodeTests.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@
4141

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

44-
import com.oracle.graal.python.builtins.objects.ints.PInt;
45-
import com.oracle.graal.python.test.PythonTests;
44+
import java.math.BigInteger;
45+
46+
import org.junit.After;
4647
import org.junit.Assert;
4748
import org.junit.Before;
4849
import org.junit.Test;
4950

50-
import java.math.BigInteger;
51+
import com.oracle.graal.python.builtins.objects.ints.PInt;
52+
import com.oracle.graal.python.test.PythonTests;
5153

5254
public class NarrowBigIntegerNodeTests {
5355

@@ -56,6 +58,11 @@ public void setUp() {
5658
PythonTests.enterContext();
5759
}
5860

61+
@After
62+
public void tearDown() {
63+
PythonTests.closeContext();
64+
}
65+
5966
private static NarrowBigIntegerNode narrow = NarrowBigIntegerNodeGen.getUncached();
6067

6168
@Test

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/PythonTests.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,19 @@ public class PythonTests {
9898
executable = sb.toString();
9999
}
100100

101-
public static void enterContext(String... newArgs) {
102-
enterContext(Collections.emptyMap(), newArgs);
101+
public static Context enterContext(String... newArgs) {
102+
return enterContext(Collections.emptyMap(), newArgs);
103103
}
104104

105-
public static void enterContext(Map<String, String> options, String[] args) {
105+
public static Context enterContext(Map<String, String> options, String[] args) {
106106
PythonTests.outArray.reset();
107107
PythonTests.errArray.reset();
108108
Context prevContext = context;
109109
context = Context.newBuilder().engine(engine).allowExperimentalOptions(true).allowAllAccess(true).options(options).arguments("python", args).option("python.Executable", executable).build();
110110
context.initialize("python");
111-
if (prevContext != null) {
112-
closeContext(prevContext);
113-
}
111+
assert prevContext == null;
114112
context.enter();
113+
return context;
115114
}
116115

117116
private static void closeContext(Context ctxt) {
@@ -290,11 +289,15 @@ private static String getFileContent(File file) {
290289
}
291290

292291
public static RootNode getParseResult(com.oracle.truffle.api.source.Source source, PrintStream out, PrintStream err) {
293-
PythonTests.enterContext();
294-
PythonContext ctx = PythonLanguage.getContext();
295-
ctx.setOut(out);
296-
ctx.setErr(err);
297-
return (RootNode) ctx.getCore().getParser().parse(ParserMode.File, 0, ctx.getCore(), source, null, null);
292+
enterContext();
293+
try {
294+
PythonContext ctx = PythonLanguage.getContext();
295+
ctx.setOut(out);
296+
ctx.setErr(err);
297+
return (RootNode) ctx.getCore().getParser().parse(ParserMode.File, 0, ctx.getCore(), source, null, null);
298+
} finally {
299+
closeContext();
300+
}
298301
}
299302

300303
public static RootNode getParseResult(String code) {
@@ -336,6 +339,7 @@ public static Value runScript(String[] args, File path, OutputStream out, Output
336339
throw new RuntimeException(e);
337340
} finally {
338341
flush(out, err);
342+
closeContext();
339343
}
340344
}
341345

@@ -345,6 +349,7 @@ public static Value runScript(Map<String, String> options, String[] args, String
345349
return context.eval(org.graalvm.polyglot.Source.create("python", source));
346350
} finally {
347351
flush(out, err);
352+
closeContext();
348353
}
349354
}
350355

@@ -354,6 +359,7 @@ public static Value runScript(String[] args, String source, OutputStream out, Ou
354359
return context.eval(org.graalvm.polyglot.Source.create("python", source));
355360
} finally {
356361
flush(out, err);
362+
closeContext();
357363
}
358364
}
359365

@@ -363,6 +369,7 @@ public static Value runScript(String[] args, org.graalvm.polyglot.Source source,
363369
return context.eval(source);
364370
} finally {
365371
flush(out, err);
372+
closeContext();
366373
}
367374
}
368375

@@ -377,6 +384,7 @@ public static Value runScript(Map<String, String> options, String[] args, String
377384
} finally {
378385
cb.run();
379386
flush(out, err);
387+
closeContext();
380388
}
381389
}
382390

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/BuiltinFunctionTests.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import static org.junit.Assert.assertEquals;
3131
import static org.junit.Assert.assertTrue;
3232

33+
import org.graalvm.polyglot.Context;
3334
import org.graalvm.polyglot.Value;
3435
import org.junit.Test;
3536

@@ -369,11 +370,16 @@ public void cellType() {
369370
" return bar\n" +
370371
"\n" +
371372
"foo(3).__closure__[0]";
372-
Value eval = PythonTests.eval(source);
373-
assertTrue(eval.getMetaObject().hasMember("__name__"));
374-
Value type = eval.getMetaObject().getMember("__name__");
375-
assertTrue(type.isString());
376-
assertEquals("cell", type.asString());
373+
Context context = PythonTests.enterContext();
374+
try {
375+
Value eval = context.eval("python", source);
376+
assertTrue(eval.getMetaObject().hasMember("__name__"));
377+
Value type = eval.getMetaObject().getMember("__name__");
378+
assertTrue(type.isString());
379+
assertEquals("cell", type.asString());
380+
} finally {
381+
PythonTests.closeContext();
382+
}
377383
}
378384

379385
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/ImportTests.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,15 @@
2525
*/
2626
package com.oracle.graal.python.test.builtin;
2727

28-
import java.nio.file.*;
28+
import static com.oracle.graal.python.test.PythonTests.assertPrintContains;
29+
import static com.oracle.graal.python.test.PythonTests.assertPrints;
2930

30-
import org.junit.*;
31+
import java.nio.file.Path;
32+
import java.nio.file.Paths;
3133

32-
import com.oracle.graal.python.test.PythonTests;
33-
34-
import static com.oracle.graal.python.test.PythonTests.*;
34+
import org.junit.Test;
3535

3636
public class ImportTests {
37-
@Before
38-
public void setup() {
39-
PythonTests.enterContext();
40-
}
41-
4237
@Test
4338
public void relativeImportTest() {
4439
Path script = Paths.get("relative_import.py");

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/IteratorTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626
package com.oracle.graal.python.test.builtin;
2727

28+
import org.junit.After;
2829
import org.junit.Before;
2930

3031
import com.oracle.graal.python.test.PythonTests;
@@ -34,4 +35,9 @@ public class IteratorTests {
3435
public void setup() {
3536
PythonTests.enterContext();
3637
}
38+
39+
@After
40+
public void tearDown() {
41+
PythonTests.closeContext();
42+
}
3743
}

0 commit comments

Comments
 (0)