Enable worker tests (#1757)

This PR re-enables tests on `worker`s. Highlights:
 
* by default, each test is run twice: the main thread version uses `<script type="py">`, the worker version automatically turn the tags into `<script type="py" worker>`

* you can tweak the settings per-class by using the `@with_execution_thread` decorator. In particular, `@with_execution_thread(None)` is for those tests which don't care about it (e.g., `test_py_config.py`)

* inside each class, there might be some test which should be run only in the main thread (because it doesn't make sense to test it in a worker). For those, I introduced the `@only_main` decorator

* we might introduce `@only_worker` in the future, if needed

* `@skip_worker` is for those tests which currently pass on main but not on workers. These are meant to be temporary, and eventually they should all be fixed
 
During the process, I tweaked/improved/fixed/deleted some of the existing tests. Some of them were at risk of being flaky and I made them more robust, others depended on some very precise implementation detail, and I made them more generic (for example, `test_image_renders_correctly` relied on pillow to render an image with a very specific string of bytes, and it broke due to the recent upgrade to pyodide 0.24.1)
 
I also renamed all the skip messages to start with `NEXT`, so that they are easier to grep.
This commit is contained in:
Antonio Cuni
2023-09-27 08:05:40 +00:00
committed by GitHub
parent 3ac2ac0982
commit abfc68765f
18 changed files with 166 additions and 509 deletions

View File

@@ -4,6 +4,7 @@ import pytest
from .support import PyScriptTest, with_execution_thread
# Disable the main/worker dual testing, for two reasons:
#
# 1. the <py-config> logic happens before we start the worker, so there is
@@ -30,7 +31,7 @@ class TestConfig(PyScriptTest):
)
assert self.console.log.lines[-1] == "config name: foobar"
@pytest.mark.skip("ERROR_SCRIPT: works with <py-script> not with <script>")
@pytest.mark.skip("NEXT: works with <py-script> not with <script>")
def test_py_config_inline_scriptpy(self):
self.pyscript_run(
"""
@@ -47,8 +48,7 @@ class TestConfig(PyScriptTest):
)
assert self.console.log.lines[-1] == "config name: foobar"
@pytest.mark.skip("ERROR_SCRIPT: works with <py-script> not with <script>")
@pytest.mark.skip("NEXT: works with <py-script> not with <script>")
def test_py_config_external(self):
pyconfig_toml = """
name = "app with external config"
@@ -67,8 +67,7 @@ class TestConfig(PyScriptTest):
)
assert self.console.log.lines[-1] == "config name: app with external config"
@pytest.mark.skip("FIXME: We need to restore the banner.")
@pytest.mark.skip("NEXT: We need to restore the banner.")
def test_invalid_json_config(self):
# we need wait_for_pyscript=False because we bail out very soon,
# before being able to write 'PyScript page fully initialized'
@@ -81,11 +80,8 @@ class TestConfig(PyScriptTest):
wait_for_pyscript=False,
)
banner = self.page.wait_for_selector(".py-error")
#assert "Unexpected end of JSON input" in self.console.error.text
expected = (
"(PY1000): Invalid JSON\n"
"Unexpected end of JSON input"
)
# assert "Unexpected end of JSON input" in self.console.error.text
expected = "(PY1000): Invalid JSON\n" "Unexpected end of JSON input"
assert banner.inner_text() == expected
def test_invalid_toml_config(self):
@@ -100,7 +96,7 @@ class TestConfig(PyScriptTest):
wait_for_pyscript=False,
)
banner = self.page.wait_for_selector(".py-error")
#assert "Expected DoubleQuote" in self.console.error.text
# assert "Expected DoubleQuote" in self.console.error.text
expected = (
"(PY1000): Invalid TOML\n"
"Expected DoubleQuote, Whitespace, or [a-z], [A-Z], "
@@ -108,7 +104,7 @@ class TestConfig(PyScriptTest):
)
assert banner.inner_text() == expected
@pytest.mark.skip("FIXME: emit a warning in case of multiple py-config")
@pytest.mark.skip("NEXT: emit a warning in case of multiple py-config")
def test_multiple_py_config(self):
self.pyscript_run(
"""
@@ -157,7 +153,7 @@ class TestConfig(PyScriptTest):
"hello from B",
]
@pytest.mark.skip("FIXME: emit an error if fetch fails")
@pytest.mark.skip("NEXT: emit an error if fetch fails")
def test_paths_that_do_not_exist(self):
self.pyscript_run(
"""