mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
Fix <script src> + test all py-script attributes (#1434)
This commit is contained in:
committed by
GitHub
parent
92643539cf
commit
0a4e36ae09
@@ -89,7 +89,7 @@ export function make_PyScript(interpreter: InterpreterClient, app: PyScriptApp)
|
||||
const pyScriptTag = document.createElement('py-script-tag') as PyScript;
|
||||
|
||||
// move attributes to the live resulting pyScriptTag reference
|
||||
for (const name of ['output', 'stderr']) {
|
||||
for (const name of ['output', 'src', 'stderr']) {
|
||||
const value = script.getAttribute(name);
|
||||
if (value) {
|
||||
pyScriptTag.setAttribute(name, value);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from .support import PyScriptTest, skip_worker
|
||||
|
||||
|
||||
class TestDisplayLineBreak(PyScriptTest):
|
||||
@skip_worker("FIXME: there is no document in a worker")
|
||||
class TestScriptTypePyScript(PyScriptTest):
|
||||
@skip_worker("FIXME: js.document")
|
||||
def test_display_line_break(self):
|
||||
self.pyscript_run(
|
||||
r"""
|
||||
@@ -14,7 +14,7 @@ class TestDisplayLineBreak(PyScriptTest):
|
||||
text_content = self.page.locator("py-script-tag").text_content()
|
||||
assert "hello\nworld" == text_content
|
||||
|
||||
@skip_worker("FIXME: there is no document in a worker")
|
||||
@skip_worker("FIXME: js.document")
|
||||
def test_amp(self):
|
||||
self.pyscript_run(
|
||||
r"""
|
||||
@@ -26,7 +26,7 @@ class TestDisplayLineBreak(PyScriptTest):
|
||||
text_content = self.page.locator("py-script-tag").text_content()
|
||||
assert "a & b" == text_content
|
||||
|
||||
@skip_worker("FIXME: there is no document in a worker")
|
||||
@skip_worker("FIXME: js.document")
|
||||
def test_quot(self):
|
||||
self.pyscript_run(
|
||||
r"""
|
||||
@@ -38,7 +38,7 @@ class TestDisplayLineBreak(PyScriptTest):
|
||||
text_content = self.page.locator("py-script-tag").text_content()
|
||||
assert "a " b" == text_content
|
||||
|
||||
@skip_worker("FIXME: there is no document in a worker")
|
||||
@skip_worker("FIXME: js.document")
|
||||
def test_lt_gt(self):
|
||||
self.pyscript_run(
|
||||
r"""
|
||||
@@ -49,3 +49,62 @@ class TestDisplayLineBreak(PyScriptTest):
|
||||
)
|
||||
text_content = self.page.locator("py-script-tag").text_content()
|
||||
assert "< < > >" == text_content
|
||||
|
||||
@skip_worker("FIXME: js.document")
|
||||
def test_dynamically_add_script_type_py_tag(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<script>
|
||||
function addPyScriptTag() {
|
||||
let tag = document.createElement('script');
|
||||
tag.type = 'py-script';
|
||||
tag.textContent = "print('hello world')";
|
||||
document.body.appendChild(tag);
|
||||
}
|
||||
</script>
|
||||
<button onclick="addPyScriptTag()">Click me</button>
|
||||
"""
|
||||
)
|
||||
self.page.locator("button").click()
|
||||
|
||||
self.page.wait_for_selector("py-terminal")
|
||||
assert self.console.log.lines[-1] == "hello world"
|
||||
|
||||
@skip_worker("FIXME: js.document")
|
||||
def test_script_type_py_src_attribute(self):
|
||||
self.writefile("foo.py", "print('hello from foo')")
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<script type="py-script" src="foo.py"></script>
|
||||
"""
|
||||
)
|
||||
assert self.console.log.lines[-1] == "hello from foo"
|
||||
|
||||
@skip_worker("FIXME: js.document")
|
||||
def test_script_type_py_output_attribute(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<div id="first"></div>
|
||||
<script type="py-script" output="first">
|
||||
print("<p>Hello</p>")
|
||||
</script>
|
||||
"""
|
||||
)
|
||||
text = self.page.locator("#first").text_content()
|
||||
assert "<p>Hello</p>" in text
|
||||
|
||||
@skip_worker("FIXME: js.document")
|
||||
def test_script_type_py_stderr_attribute(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<div id="stdout-div"></div>
|
||||
<div id="stderr-div"></div>
|
||||
<py-script output="stdout-div" stderr="stderr-div">
|
||||
import sys
|
||||
print("one.", file=sys.stderr)
|
||||
print("two.")
|
||||
</py-script>
|
||||
"""
|
||||
)
|
||||
assert self.page.locator("#stdout-div").text_content() == "one.two."
|
||||
assert self.page.locator("#stderr-div").text_content() == "one."
|
||||
|
||||
Reference in New Issue
Block a user