mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-21 19:25:35 -05:00
Fix clashing test names (#1018)
* rename tests * rename tests for element
This commit is contained in:
42
pyscriptjs/tests/integration/test_runtime.py
Normal file
42
pyscriptjs/tests/integration/test_runtime.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from .support import PyScriptTest
|
||||
|
||||
|
||||
class TestRuntimeAccess(PyScriptTest):
|
||||
"""Test accessing Python objects from JS via pyscript.runtime"""
|
||||
|
||||
def test_runtime_python_access(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script>
|
||||
x = 1
|
||||
def py_func():
|
||||
return 2
|
||||
</py-script>
|
||||
"""
|
||||
)
|
||||
|
||||
self.page.add_script_tag(
|
||||
content="""
|
||||
console.log(`x is ${pyscript.runtime.globals.get('x')}`);
|
||||
console.log(`py_func() returns ${pyscript.runtime.globals.get('py_func')()}`);
|
||||
"""
|
||||
)
|
||||
|
||||
assert self.console.log.lines[0] == self.PY_COMPLETE
|
||||
assert self.console.log.lines[-2:] == [
|
||||
"x is 1",
|
||||
"py_func() returns 2",
|
||||
]
|
||||
|
||||
def test_runtime_script_execution(self):
|
||||
"""Test running Python code from js via pyscript.runtime"""
|
||||
self.pyscript_run("")
|
||||
|
||||
self.page.add_script_tag(
|
||||
content="""
|
||||
const interpreter = pyscript.runtime.interpreter;
|
||||
interpreter.runPython('console.log("Interpreter Ran This")');
|
||||
"""
|
||||
)
|
||||
assert self.console.log.lines[0] == self.PY_COMPLETE
|
||||
assert self.console.log.lines[-1] == "Interpreter Ran This"
|
||||
Reference in New Issue
Block a user