mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 02:37:41 -05:00
* Add display impl, remove outputManage, print and console.log defaults to terminal * Fixing tests * Lint * Erase unecessary code, add cuter CSS formating for errors, fix problems around REPL output * Add fix to repl2 and lint * lint * Allow for list of display, fix elif to else * Add better global option * test work * xfails * (antocuni, mariana): let's try to start again with TDD methodology: write the minimum test and code for a simple display() * (antocuni, mariana): this test works out of the box * WIP: this test is broken, mariana is going to fix it * add a failing test * Add ability to deal with targets * Add append arg and append tests * Add multiple values to display * Small adjustments to tests. I noticed I wasn;t running all at some point * add display test * Add console tests * Add async tests * Fix repl tests * Fixing merging issues * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Address antocuni's review * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fixing more tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * linting * Improve repl tests * Change my test so codespell is hapy with it * Test: change test_runtime_config to use json instead of toml to see if stops failing on CI * kill this file: it is a merge artifact since it was renamed into test_py_config.py on the main branch * Change test execution order and add async tests to async test file Co-authored-by: Antonio Cuni <anto.cuni@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
116 lines
4.0 KiB
Python
116 lines
4.0 KiB
Python
import pytest
|
|
from playwright.sync_api import expect
|
|
|
|
from .support import PyScriptTest
|
|
|
|
|
|
class TestPyRepl(PyScriptTest):
|
|
def test_repl_loads(self):
|
|
self.pyscript_run(
|
|
"""
|
|
<py-repl id="my-repl" auto-generate="true"> </py-repl>
|
|
"""
|
|
)
|
|
|
|
py_repl = self.page.query_selector("py-repl")
|
|
assert py_repl
|
|
assert "Python" in py_repl.inner_text()
|
|
|
|
def test_repl_runs_on_button_press(self):
|
|
self.pyscript_run(
|
|
"""
|
|
<py-repl id="my-repl" auto-generate="true"> </py-repl>
|
|
"""
|
|
)
|
|
|
|
self.page.locator("py-repl").type('display("hello")')
|
|
|
|
# We only have one button in the page
|
|
self.page.locator("button").click()
|
|
|
|
# The result gets the id of the repl + n
|
|
repl_result = self.page.wait_for_selector("#my-repl-2", state="attached")
|
|
|
|
assert repl_result.inner_text() == "hello"
|
|
|
|
def test_repl_runs_with_shift_enter(self):
|
|
self.pyscript_run(
|
|
"""
|
|
<py-repl id="my-repl" auto-generate="true"> </py-repl>
|
|
"""
|
|
)
|
|
self.page.locator("py-repl").type('display("hello")')
|
|
|
|
# Confirm that we get a result by using the keys shortcut
|
|
self.page.keyboard.press("Shift+Enter")
|
|
py_repl = self.page.query_selector("#my-repl-2")
|
|
assert "hello" in py_repl.inner_text()
|
|
|
|
def test_repl_console_ouput(self):
|
|
self.pyscript_run(
|
|
"""
|
|
<py-repl id="my-repl" auto-generate="true"> </py-repl>
|
|
"""
|
|
)
|
|
self.page.locator("py-repl").type("print('apple')")
|
|
self.page.keyboard.press("Enter")
|
|
self.page.locator("py-repl").type("console.log('banana')")
|
|
self.page.locator("button").click()
|
|
|
|
# The result gets the id of the repl + n
|
|
repl_result = self.page.wait_for_selector("#my-repl-1", state="attached")
|
|
|
|
assert repl_result.inner_text() == ""
|
|
|
|
def test_repl_error_ouput(self):
|
|
self.pyscript_run(
|
|
"""
|
|
<py-repl id="my-repl" auto-generate="true"> </py-repl>
|
|
"""
|
|
)
|
|
self.page.locator("py-repl").type("this is an error")
|
|
self.page.locator("button").click()
|
|
expect(self.page.locator(".py-error")).to_be_visible()
|
|
|
|
# console errors are observable on the headed instance
|
|
# but is just not possible to access them using the self object
|
|
@pytest.mark.xfail(reason="Cannot access console errors")
|
|
def test_repl_error_ouput_console(self):
|
|
self.pyscript_run(
|
|
"""
|
|
<py-repl id="my-repl" auto-generate="true"> </py-repl>
|
|
"""
|
|
)
|
|
self.page.locator("py-repl").type("this is an error")
|
|
self.page.locator("button").click()
|
|
|
|
def test_repl_error_and_fail_moving_forward_ouput(self):
|
|
self.pyscript_run(
|
|
"""
|
|
<py-repl id="my-repl" auto-generate="true"> </py-repl>
|
|
"""
|
|
)
|
|
self.page.locator("py-repl").type("this is an error")
|
|
self.page.locator("button").click()
|
|
expect(self.page.locator(".py-error")).to_be_visible()
|
|
self.page.keyboard.press("Shift+Enter")
|
|
expect(self.page.locator(".py-error")).to_be_visible()
|
|
|
|
# this tests the fact that a new error div should be created once there's
|
|
# an error but also that it should disappear automatically once the error
|
|
# is fixed
|
|
def test_repl_show_error_fix_error_check_for_ouput(self):
|
|
self.pyscript_run(
|
|
"""
|
|
<py-repl id="my-repl" auto-generate="true"> </py-repl>
|
|
"""
|
|
)
|
|
self.page.locator("py-repl").type("d")
|
|
self.page.keyboard.press("Shift+Enter")
|
|
expect(self.page.locator(".py-error")).to_be_visible()
|
|
self.page.keyboard.press("Backspace")
|
|
self.page.locator("py-repl").type("display('ok')")
|
|
self.page.keyboard.press("Shift+Enter")
|
|
repl_result = self.page.wait_for_selector("#my-repl-2", state="attached")
|
|
assert repl_result.inner_text() == "ok"
|