mirror of
https://github.com/pyscript/pyscript.git
synced 2026-02-26 08:03:59 -05:00
Upgrade to Pyodide 0.23 (#1347)
* Upgrade to Pyodide 0.23.2 * Update changelog * Use @param decorator to fix kmeans examlpe * Separate zz_example tests to run sequentially * Remove pytest.raises from pyscript_src_not_found test, use check_js_errors instead * Add 'check_js_errors' to wait_for_pyscript
This commit is contained in:
@@ -493,7 +493,13 @@ class PyScriptTest:
|
||||
return doc
|
||||
|
||||
def pyscript_run(
|
||||
self, snippet, *, extra_head="", wait_for_pyscript=True, timeout=None
|
||||
self,
|
||||
snippet,
|
||||
*,
|
||||
extra_head="",
|
||||
wait_for_pyscript=True,
|
||||
timeout=None,
|
||||
check_js_errors=True,
|
||||
):
|
||||
"""
|
||||
Main entry point for pyscript tests.
|
||||
@@ -517,7 +523,7 @@ class PyScriptTest:
|
||||
self.writefile(filename, doc)
|
||||
self.goto(filename)
|
||||
if wait_for_pyscript:
|
||||
self.wait_for_pyscript(timeout=timeout)
|
||||
self.wait_for_pyscript(timeout=timeout, check_js_errors=check_js_errors)
|
||||
|
||||
def iter_locator(self, loc):
|
||||
"""
|
||||
@@ -630,7 +636,7 @@ TEST_ITERATIONS = math.ceil(
|
||||
) # 120 iters of 1/4 second
|
||||
|
||||
|
||||
def wait_for_render(page, selector, pattern):
|
||||
def wait_for_render(page, selector, pattern, timeout_seconds: int | None = None):
|
||||
"""
|
||||
Assert that rendering inserts data into the page as expected: search the
|
||||
DOM from within the timing loop for a string that is not present in the
|
||||
@@ -639,7 +645,12 @@ def wait_for_render(page, selector, pattern):
|
||||
re_sub_content = re.compile(pattern)
|
||||
py_rendered = False # Flag to be set to True when condition met
|
||||
|
||||
for _ in range(TEST_ITERATIONS):
|
||||
if timeout_seconds:
|
||||
check_iterations = math.ceil(timeout_seconds / TEST_TIME_INCREMENT)
|
||||
else:
|
||||
check_iterations = TEST_ITERATIONS
|
||||
|
||||
for _ in range(check_iterations):
|
||||
content = page.inner_html(selector)
|
||||
if re_sub_content.search(content):
|
||||
py_rendered = True
|
||||
|
||||
@@ -2,7 +2,7 @@ import re
|
||||
|
||||
import pytest
|
||||
|
||||
from .support import PageErrors, PyScriptTest, skip_worker
|
||||
from .support import PyScriptTest, skip_worker
|
||||
|
||||
|
||||
class TestBasic(PyScriptTest):
|
||||
@@ -246,22 +246,23 @@ class TestBasic(PyScriptTest):
|
||||
assert self.console.log.lines[-1] == "hello from foo"
|
||||
|
||||
def test_py_script_src_not_found(self):
|
||||
with pytest.raises(PageErrors) as exc:
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script src="foo.py"></py-script>
|
||||
"""
|
||||
)
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script src="foo.py"></py-script>
|
||||
""",
|
||||
check_js_errors=False,
|
||||
)
|
||||
assert "Failed to load resource" in self.console.error.lines[0]
|
||||
|
||||
error_msgs = str(exc.value)
|
||||
expected_msg = "(PY0404): Fetching from URL foo.py failed with error 404"
|
||||
assert expected_msg in error_msgs
|
||||
assert any((expected_msg in line) for line in self.console.js_error.lines)
|
||||
assert self.assert_banner_message(expected_msg)
|
||||
|
||||
pyscript_tag = self.page.locator("py-script")
|
||||
assert pyscript_tag.inner_html() == ""
|
||||
|
||||
self.check_js_errors(expected_msg)
|
||||
|
||||
def test_js_version(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
|
||||
@@ -80,9 +80,9 @@ class TestConfig(PyScriptTest):
|
||||
)
|
||||
assert self.console.log.lines[-1] == "config name: app with external config"
|
||||
|
||||
# The default pyodide version is 0.22.1 as of writing
|
||||
# this test which is newer than the one we are loading below
|
||||
# (after downloading locally) -- which is 0.22.0
|
||||
# The default pyodide version is newer than
|
||||
# the one we are loading below (after downloading locally)
|
||||
# which is 0.22.0
|
||||
|
||||
# The test checks if loading a different interpreter is possible
|
||||
# and that too from a locally downloaded file without needing
|
||||
@@ -234,8 +234,8 @@ class TestConfig(PyScriptTest):
|
||||
{
|
||||
"interpreters": [
|
||||
{
|
||||
"src": "https://cdn.jsdelivr.net/pyodide/v0.22.1/full/pyodide.js",
|
||||
"name": "pyodide-0.22.1",
|
||||
"src": "https://cdn.jsdelivr.net/pyodide/v0.23.2/full/pyodide.js",
|
||||
"name": "pyodide-0.23.2",
|
||||
"lang": "python"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -276,18 +276,20 @@ class TestExamples(PyScriptTest):
|
||||
self.check_tutor_generated_code()
|
||||
|
||||
def test_panel_kmeans(self):
|
||||
# XXX improve this test
|
||||
# XXX improve this test>>>>>>> main
|
||||
self.goto("examples/panel_kmeans.html")
|
||||
self.wait_for_pyscript(timeout=90 * 1000)
|
||||
self.wait_for_pyscript(timeout=120 * 1000)
|
||||
assert self.page.title() == "Pyscript/Panel KMeans Demo"
|
||||
wait_for_render(self.page, "*", "<div.*?class=['\"]bk-root['\"].*?>")
|
||||
wait_for_render(
|
||||
self.page, "*", "<div.*?class=['\"]bk-root['\"].*?>", timeout_seconds=60 * 2
|
||||
)
|
||||
self.assert_no_banners()
|
||||
self.check_tutor_generated_code()
|
||||
|
||||
def test_panel_stream(self):
|
||||
# XXX improve this test
|
||||
self.goto("examples/panel_stream.html")
|
||||
self.wait_for_pyscript(timeout=90 * 1000)
|
||||
self.wait_for_pyscript(timeout=3 * 60 * 1000)
|
||||
assert self.page.title() == "PyScript/Panel Streaming Demo"
|
||||
wait_for_render(self.page, "*", "<div.*?class=['\"]bk-root['\"].*?>")
|
||||
self.assert_no_banners()
|
||||
@@ -316,7 +318,7 @@ class TestExamples(PyScriptTest):
|
||||
|
||||
def test_repl2(self):
|
||||
self.goto("examples/repl2.html")
|
||||
self.wait_for_pyscript()
|
||||
self.wait_for_pyscript(timeout=1.5 * 60 * 1000)
|
||||
assert self.page.title() == "Custom REPL Example"
|
||||
wait_for_render(self.page, "*", "<py-repl.*?>")
|
||||
# confirm we can import utils and run one command
|
||||
|
||||
@@ -130,12 +130,13 @@ class TestDocsSnippets(PyScriptTest):
|
||||
self.assert_no_banners()
|
||||
|
||||
def test_tutorials_py_config_interpreter(self):
|
||||
"""Load a previous version of Pyodide"""
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-config>
|
||||
[[interpreters]]
|
||||
src = "https://cdn.jsdelivr.net/pyodide/v0.22.0a3/full/pyodide.js"
|
||||
name = "pyodide-0.22.0a3"
|
||||
src = "https://cdn.jsdelivr.net/pyodide/v0.23.0/full/pyodide.js"
|
||||
name = "pyodide-0.23.0"
|
||||
lang = "python"
|
||||
</py-config>
|
||||
<py-script>
|
||||
@@ -146,7 +147,7 @@ class TestDocsSnippets(PyScriptTest):
|
||||
)
|
||||
|
||||
py_terminal = self.page.wait_for_selector("py-terminal")
|
||||
assert "0.22.0a3" in py_terminal.inner_text()
|
||||
assert "0.23.0" in py_terminal.inner_text()
|
||||
self.assert_no_banners()
|
||||
|
||||
@skip_worker("FIXME: display()")
|
||||
|
||||
Reference in New Issue
Block a user