mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-22 19:53:00 -05:00
[next] improve integration tests (#1684)
This commit is contained in:
committed by
GitHub
parent
59db56feec
commit
7d2df4895e
@@ -17,26 +17,23 @@ class TestBasic(PyScriptTest):
|
||||
)
|
||||
assert self.console.log.lines == ["hello pyscript"]
|
||||
|
||||
# TODO: I think this test actually should test that we don't load anything if there aren't
|
||||
# any pyscrpt related tags or features. Meaning that the Platform is not invasive.
|
||||
@pytest.mark.skip(
|
||||
reason="DIFFERENT BEHAVIOUR: We don't print anything in the console once loaded"
|
||||
)
|
||||
def test_execution_thread(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<!-- we don't really need anything here, we just want to check that
|
||||
pyscript starts -->
|
||||
"""
|
||||
pyscript does not bootstrap -->
|
||||
""",
|
||||
wait_for_pyscript=False,
|
||||
)
|
||||
assert self.execution_thread in ("main", "worker")
|
||||
if self.execution_thread == "main":
|
||||
pass
|
||||
elif self.execution_thread == "worker":
|
||||
pass
|
||||
expected = ("[pyscript/main] PyScript Ready",)
|
||||
assert expected in self.console.info.lines
|
||||
assert self.console.log.lines == []
|
||||
|
||||
# TODO: if there's no py-script there are surely no plugins neither
|
||||
# this test must be discussed or rewritten to make sense now
|
||||
@pytest.mark.skip(
|
||||
reason="FIXME: No banner and should also add a WARNING about CORS"
|
||||
)
|
||||
@@ -74,7 +71,6 @@ class TestBasic(PyScriptTest):
|
||||
)
|
||||
assert self.console.log.lines[-1] == "hello pyscript"
|
||||
|
||||
@pytest.mark.skip("FIXME: No banner")
|
||||
def test_python_exception(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
@@ -89,19 +85,17 @@ class TestBasic(PyScriptTest):
|
||||
#
|
||||
# check that we sent the traceback to the console
|
||||
tb_lines = self.console.error.lines[-1].splitlines()
|
||||
assert tb_lines[0] == "Python Error: Traceback (most recent call last):"
|
||||
assert tb_lines[-1] == "Exception: this is an error"
|
||||
assert tb_lines[0] == "PythonError: Traceback (most recent call last):"
|
||||
#
|
||||
# check that we show the traceback in the page. Note that here we
|
||||
# display the "raw" python traceback, without the "[pyexec] Python
|
||||
# exception:" line (which is useful in the console, but not for the
|
||||
# user)
|
||||
pre = self.page.locator("py-script > pre")
|
||||
tb_lines = pre.inner_text().splitlines()
|
||||
banner = self.page.locator(".py-error")
|
||||
tb_lines = banner.inner_text().splitlines()
|
||||
assert tb_lines[0] == "Traceback (most recent call last):"
|
||||
assert tb_lines[-1] == "Exception: this is an error"
|
||||
|
||||
@pytest.mark.skip(reason="FIX TEST: Works on CHROME")
|
||||
def test_python_exception_in_event_handler(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
@@ -122,9 +116,7 @@ class TestBasic(PyScriptTest):
|
||||
|
||||
## error in console
|
||||
tb_lines = self.console.error.lines[-1].splitlines()
|
||||
assert tb_lines[0] == "[pyexec] Python exception:"
|
||||
assert tb_lines[1] == "Traceback (most recent call last):"
|
||||
assert tb_lines[-1] == "Exception: this is an error inside handler"
|
||||
assert tb_lines[0] == "PythonError: Traceback (most recent call last):"
|
||||
|
||||
## error in DOM
|
||||
tb_lines = self.page.locator(".py-error").inner_text().splitlines()
|
||||
@@ -151,7 +143,6 @@ class TestBasic(PyScriptTest):
|
||||
"four",
|
||||
]
|
||||
|
||||
@pytest.mark.skip(reason="FIXME: log('<div></div>') now logs an empty string.")
|
||||
def test_escaping_of_angle_brackets(self):
|
||||
"""
|
||||
Check that py-script tags escape angle brackets
|
||||
@@ -186,6 +177,8 @@ class TestBasic(PyScriptTest):
|
||||
"hello asciitree", # printed by us
|
||||
]
|
||||
|
||||
# TODO: if there's no py-script there are surely no plugins neither
|
||||
# this test must be discussed or rewritten to make sense now
|
||||
@pytest.mark.skip("FIXME: No banner")
|
||||
def test_non_existent_package(self):
|
||||
self.pyscript_run(
|
||||
@@ -207,6 +200,8 @@ class TestBasic(PyScriptTest):
|
||||
assert expected_alert_banner_msg in alert_banner.inner_text()
|
||||
self.check_py_errors("Can't fetch metadata for 'i-dont-exist'")
|
||||
|
||||
# TODO: if there's no py-script there are surely no plugins neither
|
||||
# this test must be discussed or rewritten to make sense now
|
||||
@pytest.mark.skip("FIXME: No banner")
|
||||
def test_no_python_wheel(self):
|
||||
self.pyscript_run(
|
||||
@@ -227,7 +222,6 @@ class TestBasic(PyScriptTest):
|
||||
assert expected_alert_banner_msg in alert_banner.inner_text()
|
||||
self.check_py_errors("Can't find a pure Python 3 wheel for 'opsdroid'")
|
||||
|
||||
@pytest.mark.skip("""FIXME: Dynamically adding a py-script tag fails""")
|
||||
def test_dynamically_add_py_script_tag(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
@@ -237,14 +231,13 @@ class TestBasic(PyScriptTest):
|
||||
tag.innerHTML = "print('hello world')";
|
||||
document.body.appendChild(tag);
|
||||
}
|
||||
addPyScriptTag()
|
||||
</script>
|
||||
<button onclick="addPyScriptTag()">Click me</button>
|
||||
""",
|
||||
timeout=20000,
|
||||
)
|
||||
self.page.locator("button").click()
|
||||
self.page.locator("py-script")
|
||||
|
||||
self.page.wait_for_selector("py-terminal")
|
||||
assert self.console.log.lines[-1] == "hello world"
|
||||
|
||||
def test_py_script_src_attribute(self):
|
||||
@@ -256,7 +249,6 @@ class TestBasic(PyScriptTest):
|
||||
)
|
||||
assert self.console.log.lines[-1] == "hello from foo"
|
||||
|
||||
@pytest.mark.skip("FIXME: No banner")
|
||||
def test_py_script_src_not_found(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
@@ -266,16 +258,18 @@ class TestBasic(PyScriptTest):
|
||||
)
|
||||
assert "Failed to load resource" in self.console.error.lines[0]
|
||||
|
||||
expected_msg = "(PY0404): Fetching from URL foo.py failed with error 404"
|
||||
assert any((expected_msg in line) for line in self.console.js_error.lines)
|
||||
assert self.assert_banner_message(expected_msg)
|
||||
# TODO: we need to be sure errors make sense from both main and worker worlds
|
||||
# expected_msg = "(PY0404): Fetching from URL foo.py failed with error 404"
|
||||
# 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() == ""
|
||||
# pyscript_tag = self.page.locator("py-script")
|
||||
# assert pyscript_tag.inner_html() == ""
|
||||
|
||||
self.check_js_errors(expected_msg)
|
||||
# self.check_js_errors(expected_msg)
|
||||
|
||||
@pytest.mark.skip("DIFFERENT BEHAVIOUR?: we don't expose pyscript on window")
|
||||
# TODO: ... and we shouldn't: it's a module and we better don't leak in global
|
||||
@pytest.mark.skip("DIFFERENT BEHAVIOUR: we don't expose pyscript on window")
|
||||
def test_js_version(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
@@ -290,7 +284,8 @@ class TestBasic(PyScriptTest):
|
||||
is not None
|
||||
)
|
||||
|
||||
@pytest.mark.skip("DIFFERENT BEHAVIOUR?: we don't expose pyscript on window")
|
||||
# TODO: ... and we shouldn't: it's a module and we better don't leak in global
|
||||
@pytest.mark.skip("DIFFERENT BEHAVIOUR: we don't expose pyscript on window")
|
||||
def test_python_version(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
@@ -314,7 +309,6 @@ class TestBasic(PyScriptTest):
|
||||
is not None
|
||||
)
|
||||
|
||||
@pytest.mark.skip("FIXME: No banner")
|
||||
def test_assert_no_banners(self):
|
||||
"""
|
||||
Test that the DOM doesn't contain error/warning banners
|
||||
@@ -322,16 +316,13 @@ class TestBasic(PyScriptTest):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script>
|
||||
from _pyscript_js import showWarning
|
||||
showWarning("hello")
|
||||
showWarning("world")
|
||||
import sys
|
||||
print("hello world", file=sys.stderr)
|
||||
</py-script>
|
||||
"""
|
||||
)
|
||||
|
||||
# check that we have 2 banners
|
||||
with pytest.raises(AssertionError, match="Found 2 alert banners"):
|
||||
self.assert_no_banners()
|
||||
assert self.page.locator(".py-error").inner_text() == "hello world"
|
||||
|
||||
def test_getPySrc_returns_source_code(self):
|
||||
self.pyscript_run(
|
||||
@@ -360,19 +351,3 @@ class TestBasic(PyScriptTest):
|
||||
self.wait_for_console("hello world!")
|
||||
assert self.console.log.lines[-1] == "hello world!"
|
||||
assert self.console.error.lines == []
|
||||
|
||||
# TODO: THis can actually be removed since we are removing `py-mount`
|
||||
@pytest.mark.skip("REMOVE TEST: No py-mount anymore")
|
||||
def test_py_mount_shows_deprecation_warning(self):
|
||||
# last non-deprecated version: 2023.03.1
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<div id="foo" py-mount></div>
|
||||
"""
|
||||
)
|
||||
banner = self.page.locator(".alert-banner")
|
||||
expected_message = (
|
||||
'The "py-mount" attribute is deprecated. '
|
||||
+ "Please add references to HTML Elements manually in your script."
|
||||
)
|
||||
assert banner.inner_text() == expected_message
|
||||
|
||||
Reference in New Issue
Block a user