Skip to content

Commit 73442f7

Browse files
authored
chore: test cleanups (#129)
1 parent 5316b0b commit 73442f7

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

tests/async/test_dialog.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414

1515
import asyncio
16-
from asyncio import Future
1716

1817
import pytest
1918

@@ -22,64 +21,69 @@
2221

2322

2423
async def test_should_fire(page: Page, server):
25-
on_dialog_actions_complete: Future[None] = asyncio.Future()
24+
result = []
2625

27-
async def on_dialog(dialog: Dialog):
26+
def on_dialog(dialog: Dialog):
27+
result.append(True)
2828
assert dialog.type == "alert"
2929
assert dialog.defaultValue == ""
3030
assert dialog.message == "yo"
31-
on_dialog_actions_complete.set_result(await dialog.accept())
31+
asyncio.create_task(dialog.accept())
3232

33-
page.on("dialog", lambda dialog: asyncio.create_task(on_dialog(dialog)))
33+
page.on("dialog", on_dialog)
3434
await page.evaluate("alert('yo')")
35-
await on_dialog_actions_complete
35+
assert result
3636

3737

3838
async def test_should_allow_accepting_prompts(page: Page, server):
39-
on_dialog_actions_complete: Future[None] = asyncio.Future()
39+
result = []
4040

41-
async def on_dialog(dialog: Dialog):
41+
def on_dialog(dialog: Dialog):
42+
result.append(True)
4243
assert dialog.type == "prompt"
4344
assert dialog.defaultValue == "yes."
4445
assert dialog.message == "question?"
45-
on_dialog_actions_complete.set_result(await dialog.accept("answer!"))
46+
asyncio.create_task(dialog.accept("answer!"))
4647

47-
page.on("dialog", lambda dialog: asyncio.create_task(on_dialog(dialog)))
48+
page.on("dialog", on_dialog)
4849
assert await page.evaluate("prompt('question?', 'yes.')") == "answer!"
49-
await on_dialog_actions_complete
50+
assert result
5051

5152

5253
async def test_should_dismiss_the_prompt(page: Page, server):
53-
on_dialog_actions_complete: Future[None] = asyncio.Future()
54+
result = []
5455

55-
async def on_dialog(dialog: Dialog):
56-
on_dialog_actions_complete.set_result(await dialog.dismiss())
56+
def on_dialog(dialog: Dialog):
57+
result.append(True)
58+
asyncio.create_task(dialog.dismiss())
5759

58-
page.on("dialog", lambda dialog: asyncio.create_task(on_dialog(dialog)))
60+
page.on("dialog", on_dialog)
5961
assert await page.evaluate("prompt('question?')") is None
60-
await on_dialog_actions_complete
62+
assert result
6163

6264

6365
async def test_should_accept_the_confirm_prompt(page: Page, server):
64-
on_dialog_actions_complete: Future[None] = asyncio.Future()
66+
result = []
6567

66-
async def on_dialog(dialog: Dialog):
67-
on_dialog_actions_complete.set_result(await dialog.accept())
68+
def on_dialog(dialog: Dialog):
69+
result.append(True)
70+
asyncio.create_task(dialog.accept())
6871

69-
page.on("dialog", lambda dialog: asyncio.create_task(on_dialog(dialog)))
72+
page.on("dialog", on_dialog)
7073
assert await page.evaluate("confirm('boolean?')") is True
71-
await on_dialog_actions_complete
74+
assert result
7275

7376

7477
async def test_should_dismiss_the_confirm_prompt(page: Page, server):
75-
on_dialog_actions_complete: Future[None] = asyncio.Future()
78+
result = []
7679

77-
async def on_dialog(dialog: Dialog):
78-
on_dialog_actions_complete.set_result(await dialog.dismiss())
80+
def on_dialog(dialog: Dialog):
81+
result.append(True)
82+
asyncio.create_task(dialog.dismiss())
7983

80-
page.on("dialog", lambda dialog: asyncio.create_task(on_dialog(dialog)))
84+
page.on("dialog", on_dialog)
8185
assert await page.evaluate("confirm('boolean?')") is False
82-
await on_dialog_actions_complete
86+
assert result
8387

8488

8589
# TODO: Logger support not yet here

tests/async/test_focus.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,3 @@ async def test_should_traverse_only_form_elements(page):
106106
assert await page.evaluate("() => document.activeElement.id") == "button"
107107
await page.keyboard.press("Alt+Shift+Tab")
108108
assert await page.evaluate("() => document.activeElement.id") == "input-1"
109-
110-
111-
# });
112-
# });

0 commit comments

Comments
 (0)