mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
Use <script type="py"> instead of <py-script> in most tests (#1723)
This is mostly a global search&replace, to replace <py-script> with <script type="py">. The vast majority of tests just works, some needed some tweak.
This commit is contained in:
@@ -6,16 +6,22 @@ from .support import PyScriptTest
|
||||
|
||||
|
||||
class TestBasic(PyScriptTest):
|
||||
def test_pyscript_hello(self):
|
||||
def test_script_py_hello(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<script type="py">
|
||||
import js
|
||||
js.console.log('hello pyscript')
|
||||
js.console.log('hello from script py')
|
||||
</script>
|
||||
|
||||
<py-script>
|
||||
import js
|
||||
js.console.log('hello from py-script')
|
||||
</py-script>
|
||||
"""
|
||||
)
|
||||
assert self.console.log.lines == ["hello pyscript"]
|
||||
assert self.console.log.lines == ["hello from script py",
|
||||
"hello from py-script"]
|
||||
|
||||
def test_execution_thread(self):
|
||||
self.pyscript_run(
|
||||
@@ -64,9 +70,9 @@ class TestBasic(PyScriptTest):
|
||||
def test_print(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script>
|
||||
<script type="py">
|
||||
print('hello pyscript')
|
||||
</py-script>
|
||||
</script>
|
||||
"""
|
||||
)
|
||||
assert self.console.log.lines[-1] == "hello pyscript"
|
||||
@@ -74,10 +80,10 @@ class TestBasic(PyScriptTest):
|
||||
def test_python_exception(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script>
|
||||
<script type="py">
|
||||
print('hello pyscript')
|
||||
raise Exception('this is an error')
|
||||
</py-script>
|
||||
</script>
|
||||
"""
|
||||
)
|
||||
assert "hello pyscript" in self.console.log.lines
|
||||
@@ -100,10 +106,10 @@ class TestBasic(PyScriptTest):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<button py-click="onclick">Click me</button>
|
||||
<py-script>
|
||||
<script type="py">
|
||||
def onclick(event):
|
||||
raise Exception("this is an error inside handler")
|
||||
</py-script>
|
||||
</script>
|
||||
"""
|
||||
)
|
||||
|
||||
@@ -125,15 +131,15 @@ class TestBasic(PyScriptTest):
|
||||
|
||||
def test_execution_in_order(self):
|
||||
"""
|
||||
Check that they py-script tags are executed in the same order they are
|
||||
Check that they script py tags are executed in the same order they are
|
||||
defined
|
||||
"""
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script>import js; js.console.log('one')</py-script>
|
||||
<py-script>js.console.log('two')</py-script>
|
||||
<py-script>js.console.log('three')</py-script>
|
||||
<py-script>js.console.log('four')</py-script>
|
||||
<script type="py">import js; js.console.log('one')</script>
|
||||
<script type="py">js.console.log('two')</script>
|
||||
<script type="py">js.console.log('three')</script>
|
||||
<script type="py">js.console.log('four')</script>
|
||||
"""
|
||||
)
|
||||
assert self.console.log.lines[-4:] == [
|
||||
@@ -145,16 +151,21 @@ class TestBasic(PyScriptTest):
|
||||
|
||||
def test_escaping_of_angle_brackets(self):
|
||||
"""
|
||||
Check that py-script tags escape angle brackets
|
||||
Check that script tags escape angle brackets
|
||||
"""
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script>import js; js.console.log(1<2, 1>2)</py-script>
|
||||
<py-script>js.console.log("<div></div>")</py-script>
|
||||
<script type="py">import js; js.console.log("A", 1<2, 1>2)</script>
|
||||
<script type="py">js.console.log("B <div></div>")</script>
|
||||
<py-script>import js; js.console.log("C", 1<2, 1>2)</py-script>
|
||||
<py-script>js.console.log("D <div></div>")</py-script>
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
assert self.console.log.lines[-2:] == ["true false", "<div></div>"]
|
||||
assert self.console.log.lines[-4:] == ["A true false",
|
||||
"B <div></div>",
|
||||
"C true false",
|
||||
"D <div></div>"]
|
||||
|
||||
@pytest.mark.skip(reason="FIX TEST: Works on CHROME")
|
||||
def test_packages(self):
|
||||
@@ -163,11 +174,11 @@ class TestBasic(PyScriptTest):
|
||||
<py-config>
|
||||
packages = ["asciitree"]
|
||||
</py-config>
|
||||
<py-script>
|
||||
<script type="py">
|
||||
import js
|
||||
import asciitree
|
||||
js.console.log('hello', asciitree.__name__)
|
||||
</py-script>
|
||||
</script>
|
||||
"""
|
||||
)
|
||||
|
||||
@@ -177,7 +188,7 @@ class TestBasic(PyScriptTest):
|
||||
"hello asciitree", # printed by us
|
||||
]
|
||||
|
||||
# TODO: if there's no py-script there are surely no plugins neither
|
||||
# TODO: if there's no <script type="py"> 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):
|
||||
@@ -200,7 +211,7 @@ 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
|
||||
# TODO: if there's no <script type="py"> 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):
|
||||
@@ -244,7 +255,7 @@ class TestBasic(PyScriptTest):
|
||||
self.writefile("foo.py", "print('hello from foo')")
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script src="foo.py"></py-script>
|
||||
<script type="py" src="foo.py"></script>
|
||||
"""
|
||||
)
|
||||
assert self.console.log.lines[-1] == "hello from foo"
|
||||
@@ -252,7 +263,7 @@ class TestBasic(PyScriptTest):
|
||||
def test_py_script_src_not_found(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script src="foo.py"></py-script>
|
||||
<script type="py" src="foo.py"></script>
|
||||
""",
|
||||
check_js_errors=False,
|
||||
)
|
||||
@@ -263,7 +274,7 @@ class TestBasic(PyScriptTest):
|
||||
# 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")
|
||||
# pyscript_tag = self.page.locator("script-py")
|
||||
# assert pyscript_tag.inner_html() == ""
|
||||
|
||||
# self.check_js_errors(expected_msg)
|
||||
@@ -273,8 +284,8 @@ class TestBasic(PyScriptTest):
|
||||
def test_js_version(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script>
|
||||
</py-script>
|
||||
<script type="py">
|
||||
</script>
|
||||
"""
|
||||
)
|
||||
self.page.add_script_tag(content="console.log(pyscript.version)")
|
||||
@@ -289,11 +300,11 @@ class TestBasic(PyScriptTest):
|
||||
def test_python_version(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script>
|
||||
<script type="py">
|
||||
import js
|
||||
js.console.log(pyscript.__version__)
|
||||
js.console.log(str(pyscript.version_info))
|
||||
</py-script>
|
||||
</script>
|
||||
"""
|
||||
)
|
||||
assert (
|
||||
@@ -315,35 +326,39 @@ class TestBasic(PyScriptTest):
|
||||
"""
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script>
|
||||
<script type="py">
|
||||
import sys
|
||||
print("hello world", file=sys.stderr)
|
||||
</py-script>
|
||||
</script>
|
||||
"""
|
||||
)
|
||||
|
||||
assert self.page.locator(".py-error").inner_text() == "hello world"
|
||||
|
||||
@pytest.mark.skip("ERROR_SCRIPT: works with <py-script> not with <script>")
|
||||
def test_getPySrc_returns_source_code(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script>print("hello world!")</py-script>
|
||||
<py-script>print("hello from py-script")</py-script>
|
||||
<script type="py">print("hello from script py")</script>
|
||||
"""
|
||||
)
|
||||
|
||||
pyscript_tag = self.page.locator("py-script")
|
||||
assert pyscript_tag.inner_html() == ""
|
||||
assert pyscript_tag.evaluate("node => node.srcCode") == 'print("hello world!")'
|
||||
assert pyscript_tag.evaluate("node => node.srcCode") == 'print("hello from py-script")'
|
||||
script_py_tag = self.page.locator('script[type="py"]')
|
||||
assert script_py_tag.evaluate("node => node.srcCode") == 'print("hello from script py")'
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="FIX TEST: works in chrome!")
|
||||
def test_py_attribute_without_id(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<button py-click="myfunc">Click me</button>
|
||||
<py-script>
|
||||
<script type="py">
|
||||
def myfunc(event):
|
||||
print("hello world!")
|
||||
</py-script>
|
||||
</script>
|
||||
"""
|
||||
)
|
||||
btn = self.page.wait_for_selector("button")
|
||||
|
||||
Reference in New Issue
Block a user