-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
93 changed files
with
12,262 additions
and
1,119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{ "overlay": "2c97f9a352b2773941722f15612bd5c531f63489" } | ||
{ "overlay": "410373502193976c276eb0c68eafd8d9d67fe54b" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...hon.test.integration/src/com/oracle/graal/python/test/integration/grammar/AsyncTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.oracle.graal.python.test.integration.grammar; | ||
|
||
import static com.oracle.graal.python.test.integration.PythonTests.assertPrints; | ||
|
||
import org.junit.Test; | ||
|
||
public class AsyncTests { | ||
@Test | ||
public void nativeCoroutine() { | ||
String source = "import asyncio\n" + | ||
"async def foo():\n" + | ||
" return 42\n" + | ||
"async def main():\n" + | ||
" print(await foo())\n" + | ||
"asyncio.run(main())"; | ||
assertPrints("42\n", source); | ||
} | ||
|
||
@Test | ||
public void asyncWith() { | ||
String source = "import asyncio\n" + | ||
"class AsyncContextManager:\n" + | ||
" async def __aenter__(self):\n" + | ||
" await asyncio.sleep(0.01)\n" + | ||
" print(\"entered\")\n" + | ||
" async def __aexit__(self, exc_type, exc_value, traceback):\n" + | ||
" await asyncio.sleep(0.01)\n" + | ||
" if exc_type:\n" + | ||
" print(\"exited exceptionally\")\n" + | ||
" else:\n" + | ||
" print(\"exited normally\")\n" + | ||
" return True\n" + | ||
"async def main(shouldRaise):\n" + | ||
" async with AsyncContextManager():\n" + | ||
" print(\"inside\")\n" + | ||
" if shouldRaise:\n" + | ||
" raise ValueError\n" + | ||
"asyncio.run(main(%s))"; | ||
assertPrints("entered\ninside\nexited normally\n", String.format(source, "False")); | ||
assertPrints("entered\ninside\nexited exceptionally\n", String.format(source, "True")); | ||
} | ||
|
||
@Test | ||
public void asyncWithExceptional() { | ||
String source = "import asyncio\n" + | ||
"class AsyncContextManager:\n" + | ||
" async def __aenter__(self):\n" + | ||
" await asyncio.sleep(0.01)\n" + | ||
" print(\"entered\")\n" + | ||
" async def __aexit__(self, exc_type, exc_value, traceback):\n" + | ||
" await asyncio.sleep(0.01)\n" + | ||
" print(\"exited\")\n" + | ||
" return False\n" + // don't handle exception | ||
"async def main(shouldRaise):\n" + | ||
" async with AsyncContextManager():\n" + | ||
" print(\"inside\")\n" + | ||
" if shouldRaise:\n" + | ||
" raise ValueError\n" + | ||
"try:\n" + | ||
" asyncio.run(main(%s))\n" + | ||
"except ValueError:\n" + | ||
" print(\"rethrew\")\n"; | ||
assertPrints("entered\ninside\nexited\n", String.format(source, "False")); | ||
assertPrints("entered\ninside\nexited\nrethrew\n", String.format(source, "True")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.