mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 02:37:41 -05:00
Add more integration tests for py-components and examples (#709)
* Add more integration tests for py-components and examples for more information, see https://pre-commit.ci * remove xfail mark since we merged fix for issue 707 Co-authored-by: Fabio Pliger <fabio.pliger@gmail.com>
This commit is contained in:
@@ -74,11 +74,22 @@ class TestExamples(PyScriptTest):
|
||||
assert False, "Espresso time not found :("
|
||||
|
||||
def test_altair(self):
|
||||
# XXX improve this test
|
||||
self.goto("examples/altair.html")
|
||||
self.wait_for_pyscript()
|
||||
assert self.page.title() == "Altair"
|
||||
wait_for_render(self.page, "*", '<canvas.*?class=\\"marks\\".*?>')
|
||||
save_as_png_link = self.page.locator("text=Save as PNG")
|
||||
see_source_link = self.page.locator("text=View Source")
|
||||
|
||||
# These shouldn't be visible since we didn't click the menu
|
||||
assert not save_as_png_link.is_visible()
|
||||
assert not see_source_link.is_visible()
|
||||
|
||||
self.page.locator("summary").click()
|
||||
|
||||
# Let's confirm that the links are visible now after clicking the menu
|
||||
assert save_as_png_link.is_visible()
|
||||
assert see_source_link.is_visible()
|
||||
|
||||
def test_bokeh(self):
|
||||
# XXX improve this test
|
||||
@@ -159,25 +170,61 @@ class TestExamples(PyScriptTest):
|
||||
wait_for_render(self.page, "*", "<div.*?class=['\"]bk-root['\"].*?>")
|
||||
|
||||
def test_repl(self):
|
||||
# XXX improve this test
|
||||
self.goto("examples/repl.html")
|
||||
self.wait_for_pyscript()
|
||||
assert self.page.title() == "REPL"
|
||||
wait_for_render(self.page, "*", "<py-repl.*?>")
|
||||
|
||||
self.page.locator("py-repl").type("print('Hello, World!')")
|
||||
self.page.locator("button").click()
|
||||
|
||||
assert self.page.locator("#my-repl-1").text_content() == "Hello, World!"
|
||||
|
||||
# Confirm that using the second repl still works properly
|
||||
self.page.locator("#my-repl-2").type("2*2")
|
||||
self.page.keyboard.press("Shift+Enter")
|
||||
|
||||
assert self.page.locator("#my-repl-2-2").text_content() == "4"
|
||||
|
||||
def test_repl2(self):
|
||||
# XXX improve this test
|
||||
self.goto("examples/repl2.html")
|
||||
self.wait_for_pyscript()
|
||||
assert self.page.title() == "Custom REPL Example"
|
||||
wait_for_render(self.page, "*", "<py-repl.*?>")
|
||||
# confirm we can import utils and run one command
|
||||
self.page.locator("py-repl").type("import utils\nutils.now()")
|
||||
self.page.locator("button").click()
|
||||
# utils.now returns current date time
|
||||
content = self.page.content()
|
||||
pattern = "\\d+/\\d+/\\d+, \\d+:\\d+:\\d+" # e.g. 08/09/2022 15:57:32
|
||||
assert re.search(pattern, content)
|
||||
|
||||
def test_todo(self):
|
||||
# XXX improve this test
|
||||
self.goto("examples/todo.html")
|
||||
self.wait_for_pyscript()
|
||||
assert self.page.title() == "Todo App"
|
||||
wait_for_render(self.page, "*", "<input.*?id=['\"]new-task-content['\"].*?>")
|
||||
todo_input = self.page.locator("input")
|
||||
submit_task_button = self.page.locator("button")
|
||||
|
||||
todo_input.type("Fold laundry")
|
||||
submit_task_button.click()
|
||||
|
||||
first_task = self.page.locator("#task-0")
|
||||
assert "Fold laundry" in first_task.inner_text()
|
||||
|
||||
task_checkbox = first_task.locator("input")
|
||||
# Confirm that the new task isn't checked
|
||||
assert not task_checkbox.is_checked()
|
||||
|
||||
# Let's mark it as done now
|
||||
task_checkbox.check()
|
||||
|
||||
# Basic check that the task has the line-through class
|
||||
assert (
|
||||
'<p class="m-0 inline line-through">Fold laundry</p>'
|
||||
in first_task.inner_html()
|
||||
)
|
||||
|
||||
@pytest.mark.xfail(reason="JsError, issue #673")
|
||||
def test_todo_pylist(self):
|
||||
@@ -188,12 +235,21 @@ class TestExamples(PyScriptTest):
|
||||
wait_for_render(self.page, "*", "<input.*?id=['\"]new-task-content['\"].*?>")
|
||||
|
||||
def test_toga_freedom(self):
|
||||
# XXX improve this test
|
||||
self.goto("examples/toga/freedom.html")
|
||||
self.wait_for_pyscript()
|
||||
assert self.page.title() in ["Loading...", "Freedom Units"]
|
||||
wait_for_render(self.page, "*", "<(main|div).*?id=['\"]toga_\\d+['\"].*?>")
|
||||
|
||||
page_content = self.page.content()
|
||||
|
||||
assert "Fahrenheit" in page_content
|
||||
assert "Celsius" in page_content
|
||||
|
||||
self.page.locator("#toga_f_input").fill("105")
|
||||
self.page.locator("button#toga_calculate").click()
|
||||
result = self.page.locator("#toga_c_input")
|
||||
assert "40.555" in result.input_value()
|
||||
|
||||
@pytest.mark.xfail(reason="it never finishes loading, issue #678")
|
||||
def test_webgl_raycaster_index(self):
|
||||
# XXX improve this test
|
||||
|
||||
Reference in New Issue
Block a user