Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove 'Implicit Async', Don't Await runtime.run() #928

Merged
merged 17 commits into from
Nov 16, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 69 additions & 0 deletions pyscriptjs/tests/py-unit/test_pyscript.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import textwrap
from unittest.mock import Mock

import pyscript
Expand Down Expand Up @@ -48,3 +49,71 @@ def test_format_mime_HTML():
out, mime = pyscript.format_mime(obj)
assert out == "<p>hello</p>"
assert mime == "text/html"


def test_uses_top_level_await():
# Basic Case
src = "x = 1"
assert pyscript.uses_top_level_await(src) is False

# Comments are not top-level await
src = textwrap.dedent(
"""
#await async for async with asyncio
"""
)

assert pyscript.uses_top_level_await(src) is False

# Top-level-await cases
src = textwrap.dedent(
"""
async def foo():
pass
await foo
"""
)
assert pyscript.uses_top_level_await(src) is True

src = textwrap.dedent(
"""
async with object():
pass
"""
)
assert pyscript.uses_top_level_await(src) is True

src = textwrap.dedent(
"""
async for _ in range(10):
pass
"""
)
assert pyscript.uses_top_level_await(src) is True

# Acceptable await/async for/async with cases
src = textwrap.dedent(
"""
async def foo():
await foo()
"""
)
assert pyscript.uses_top_level_await(src) is False

src = textwrap.dedent(
"""
async def foo():
async with object():
pass
"""
)
assert pyscript.uses_top_level_await(src) is False

src = textwrap.dedent(
"""
async def foo():
async for _ in range(10):
pass
"""
)
assert pyscript.uses_top_level_await(src) is False
JeffersGlass marked this conversation as resolved.
Show resolved Hide resolved