8000 Enable worker tests by antocuni · Pull Request #1757 · pyscript/pyscript · GitHub
[go: up one dir, main page]

Skip to content

Enable worker tests #1757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Sep 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improve the event_handling tests and skip one on workers
  • Loading branch information
antocuni committed Sep 26, 2023
commit a0bc4006cdd3eeb81a55460fb66dc089f5e08f90
54 changes: 22 additions & 32 deletions pyscript.core/tests/integration/test_event_handling.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import pytest

from .support import PyScriptTest
from .support import PyScriptTest, skip_worker


class TestEventHandler(PyScriptTest):

def test_when_decorator_with_event(self):
"""When the decorated function takes a single parameter,
it should be passed the event object
Expand All @@ -15,14 +16,12 @@ def test_when_decorator_with_event(self):
from pyscript import when
@when("click", selector="#foo_id")
def foo(evt):
print(f"I've clicked {evt.target} with id {evt.target.id}")
print(f"clicked {evt.target.id}")
</script>
"""
)
self.page.locator("text=foo_button").click()
console_text = self.console.all.lines
self.wait_for_console(" 10000 I've clicked [object HTMLButtonElement] with id foo_id")
assert "I've clicked [object HTMLButtonElement] with id foo_id" in console_text
self.wait_for_console("clicked foo_id")
self.assert_no_banners()

def test_when_decorator_without_event(self):
Expand All @@ -42,7 +41,6 @@ def foo():
)
self.page.locator("text=foo_button").click()
self.wait_for_console("The button was clicked")
assert "The button was clicked" in self.console.log.lines
self.assert_no_banners()

def test_multiple_when_decorators_with_event(self):
Expand All @@ -53,23 +51,18 @@ def test_multiple_when_decorators_with_event(self):
<script type="py">
from pyscript import when
@when("click", selector="#foo_id")
def foo(evt):
print(f"I've clicked {evt.target} with id {evt.target.id}")
def foo_click(evt):
print(f"foo_click! id={evt.target.id}")
@when("click", selector="#bar_id")
def foo(evt):
print(f"I've clicked {evt.target} with id {evt.target.id}")
def bar_click(evt):
print(f"bar_click! id={evt.target.id}")
</script>
"""
)
self.page.locator("text=foo_button").click()
console_text = self.console.all.lines
self.wait_for_console("I've clicked [object HTMLButtonElement] with id foo_id")
assert "I've clicked [object HTMLButtonElement] with id foo_id" in console_text

self.wait_for_console("foo_click! id=foo_id")
self.page.locator("text=bar_button").click()
console_text = self.console.all.lines
self.wait_for_console("I've clicked [object HTMLButtonElement] with id bar_id")
assert "I've clicked [object HTMLButtonElement] with id bar_id" in console_text
self.wait_for_console("bar_click! id=bar_id")
self.assert_no_banners()

def test_two_when_decorators(self):
Expand All @@ -83,15 +76,14 @@ def test_two_when_decorators(self):
@when("click", selector="#foo_id")
@when("mouseover", selector=".bar_class")
def foo(evt):
print(f"An event of type {evt.type} happened")
print(f"got event: {evt.type}")
</script>
"""
)
self.page.locator("text=bar_button").hover()
self.wait_for_console("got event: mouseover")
self.page.locator("text=foo_button").click()
self.wait_for_console("An event of type click happened")
assert "An event of type mouseover happened" in self.console.log.lines
assert "An event of type click happened" in self.console.log.lines
self.wait_for_console("got event: click")
self.assert_no_banners()

def test_two_when_decorators_same_element(self):
Expand All @@ -104,15 +96,14 @@ def test_two_when_decorators_same_element(self):
@when("click", selector="#foo_id")
@when("mouseover", selector="#foo_id")
def foo(evt):
print(f"An event of type {evt.type} happened")
print(f"got event: {evt.type}")
</script>
"""
)
self.page.locator("text=foo_button").hover()
self.wait_for_console("got event: mouseover")
self.page.locator("text=foo_button").click()
self.wait_for_console("An event of type click happened")
assert "An event of type mouseover happened" in self.console.log.lines
assert "An event of type click happened" in self.console.log.lines
self.wait_for_console("got event: click")
self.assert_no_banners()

def test_when_decorator_multiple_elements(self):
Expand Down Expand Up @@ -148,19 +139,18 @@ def test_when_decorator_duplicate_selectors(self):
@when("click", selector="#foo_id")
@when("click", selector="#foo_id")
def foo(evt):
print(f"I've clicked {evt.target} with id {evt.target.id}")
foo.n += 1
print(f"click {foo.n} on {evt.target.id}")
foo.n = 0
</script>
"""
)
self.page.locator("text=foo_button").click()
console_text = self.console.all.lines
self.wait_for_console("I've clicked [object HTMLButtonElement] with id foo_id")
assert (
console_text.count("I've clicked [object HTMLButtonElement] with id foo_id")
== 2
)
self.wait_for_console("click 1 on foo_id")
self.wait_for_console("click 2 on foo_id")
self.assert_no_banners()

@skip_worker("NEXT: error banner not shown")
def test_when_decorator_invalid_selector(self):
"""When the selector parameter of @when is invalid, it should show an error"""
self.pyscript_run(
Expand Down
0