8000 Enable worker tests by antocuni · Pull Request #1757 · pyscript/pyscript · GitHub
[go: up one dir, main page]

Skip to content

Enable worker tests #1757

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

Merged
merged 19 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP
  • Loading branch information
antocuni committed Sep 26, 2023
commit 79033de6f99af89868991bd3a113e4d25fed358c
6 changes: 3 additions & 3 deletions pyscript.core/tests/integration/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def wait_for_pyscript(self, *, timeout=None, check_js_errors=True):
"""
# this is printed by interpreter.ts:Interpreter.initialize
elapsed_ms = self.wait_for_console(
"[pyscript/main] PyScript Ready",
"---PyScript init done---",
timeout=timeout,
check_js_errors=check_js_errors,
)
Expand Down Expand Up @@ -494,11 +494,11 @@ def _inject_execution_thread_config(self, snippet, execution_thread):
#
return snippet, py_config_maybe

SCRIPT_WORKER_REGEX = re.compile('<script type="py"')
SCRIPT_WORKER_REGEX = re.compile('(<script type="py"|<py-script)')

def _pyscript_format(self, snippet, *, execution_thread, extra_head=""):
if execution_thread == 'worker':
snippet = self.SCRIPT_WORKER_REGEX.sub('<script type="py" worker', snippet)
snippet = self.SCRIPT_WORKER_REGEX.sub(r'\1 worker', snippet)

doc = f"""
<html>
Expand Down
18 changes: 14 additions & 4 deletions pyscript.core/tests/integration/test_01_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,26 @@ def test_script_py_hello(self):
"""
<script type="py">
import js
js.console.log('hello from script py')
js.console.log('1. hello from script py')
</script>

<py-script>
import js
js.console.log('hello from py-script')
js.console.log('2. hello from py-script')
js.console.debug("---PyScript init done---")
</py-script>
"""
)
assert self.console.log.lines == ["hello from script py",
"hello from py-script"]
if self.execution_thread == "main":
# in main, the order of execution is guaranteed
assert self.console.log.lines == ["1. hello from script py",
"2. hello from py-script"]
else:
# in workers, each tag is executed by its own worker, so they can
# come out of order
lines = sorted(self.console.log.lines)
assert lines == ["1. hello from script py",
"2. hello from py-script"]

def test_execution_thread(self):
self.pyscript_run(
Expand All @@ -30,6 +39,7 @@ def test_execution_thread(self):
import pyscript
import js
js.console.log("worker?", pyscript.RUNNING_IN_WORKER)
js.console.debug("---PyScript init done---")
</script>
""",
)
Expand Down
0