mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-22 19:53:00 -05:00
* bring Makefile to root folder * add back the print to console when pyscript is ready * fix build path on tests, link to core.js and overall timeout since it now loads faster * fix and mark some tests accordingly * change default timeout to 20s * review tests and skip what is a known regression * more tests review until pycondif and skip what is a known regression * fix pyodide version used on tests * remove display from config test since it's not testing anything more than console already tests and display as its own tests * disable config tests that rely on the banner * skip REPL tests since it's not included in pyscript NEXT * skip PyTerminal tests since it's not included in pyscript NEXT * skip more tests relying on Element * Fix wrong script type from py-script to py * review more tests related to attributes and add test for worker * skip spashscreen tests * wrap up reviews on remaining tests * update core * update display tests to use import * fix more tests and skip some that have known issues * skip other 2 tests that fail because the test framework injects values that cause the config to fail * fix getPySrc test due to changed interface * another round of fixes and commenting on specific tests --------- Co-authored-by: Fabio Pliger <fpliger@anaconda.com>
99 lines
3.0 KiB
Python
99 lines
3.0 KiB
Python
import pytest
|
|
|
|
from .support import PyScriptTest
|
|
|
|
pytest.skip(
|
|
reason="FIXME: pyscript API changed doesn't expose pyscript to window anymore",
|
|
allow_module_level=True,
|
|
)
|
|
|
|
|
|
class TestInterpreterAccess(PyScriptTest):
|
|
"""Test accessing Python objects from JS via pyscript.interpreter"""
|
|
|
|
def test_interpreter_python_access(self):
|
|
self.pyscript_run(
|
|
"""
|
|
<py-script>
|
|
x = 1
|
|
def py_func():
|
|
return 2
|
|
</py-script>
|
|
"""
|
|
)
|
|
|
|
self.run_js(
|
|
"""
|
|
const x = await pyscript.interpreter.globals.get('x');
|
|
const py_func = await pyscript.interpreter.globals.get('py_func');
|
|
const py_func_res = await py_func();
|
|
console.log(`x is ${x}`);
|
|
console.log(`py_func() returns ${py_func_res}`);
|
|
"""
|
|
)
|
|
assert self.console.log.lines[-2:] == [
|
|
"x is 1",
|
|
"py_func() returns 2",
|
|
]
|
|
|
|
def test_interpreter_script_execution(self):
|
|
"""Test running Python code from js via pyscript.interpreter"""
|
|
self.pyscript_run("")
|
|
|
|
self.run_js(
|
|
"""
|
|
const interface = pyscript.interpreter._remote.interface;
|
|
await interface.runPython('print("Interpreter Ran This")');
|
|
"""
|
|
)
|
|
|
|
expected_message = "Interpreter Ran This"
|
|
assert self.console.log.lines[-1] == expected_message
|
|
|
|
py_terminal = self.page.wait_for_selector("py-terminal")
|
|
assert py_terminal.text_content() == expected_message
|
|
|
|
def test_backward_compatibility_runtime_script_execution(self):
|
|
"""Test running Python code from js via pyscript.runtime"""
|
|
self.pyscript_run("")
|
|
|
|
self.run_js(
|
|
"""
|
|
const interface = pyscript.runtime._remote.interpreter;
|
|
await interface.runPython('print("Interpreter Ran This")');
|
|
"""
|
|
)
|
|
|
|
expected_message = "Interpreter Ran This"
|
|
assert self.console.log.lines[-1] == expected_message
|
|
|
|
py_terminal = self.page.wait_for_selector("py-terminal")
|
|
assert py_terminal.text_content() == expected_message
|
|
|
|
def test_backward_compatibility_runtime_python_access(self):
|
|
"""Test accessing Python objects from JS via pyscript.runtime"""
|
|
self.pyscript_run(
|
|
"""
|
|
<py-script>
|
|
x = 1
|
|
def py_func():
|
|
return 2
|
|
</py-script>
|
|
"""
|
|
)
|
|
|
|
self.run_js(
|
|
"""
|
|
const x = await pyscript.interpreter.globals.get('x');
|
|
const py_func = await pyscript.interpreter.globals.get('py_func');
|
|
const py_func_res = await py_func();
|
|
console.log(`x is ${x}`);
|
|
console.log(`py_func() returns ${py_func_res}`);
|
|
"""
|
|
)
|
|
|
|
assert self.console.log.lines[-2:] == [
|
|
"x is 1",
|
|
"py_func() returns 2",
|
|
]
|