diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3c8055c74..7d9782550 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,14 +2,14 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.1.0 + rev: v3.2.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer exclude: ^playwright/drivers/browsers.json$ - id: check-yaml - repo: https://github.com/psf/black - rev: 19.10b0 + rev: 20.8b1 hooks: - id: black - repo: https://github.com/pre-commit/mirrors-mypy @@ -17,10 +17,10 @@ repos: hooks: - id: mypy - repo: https://gitlab.com/pycqa/flake8 - rev: 'a7be77f761a4c29121d6bb6f61c11902281f9105' + rev: '3.8.3' hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-isort - rev: v5.1.3 + rev: v5.5.4 hooks: - id: isort diff --git a/build_driver.py b/build_driver.py index da49b71ed..f2e03307c 100644 --- a/build_driver.py +++ b/build_driver.py @@ -43,7 +43,8 @@ node_modules_playwright = driver_path / "node_modules" / "playwright" shutil.copyfile( - node_modules_playwright / "browsers.json", drivers_path / "browsers.json", + node_modules_playwright / "browsers.json", + drivers_path / "browsers.json", ) upstream_readme = (node_modules_playwright / "README.md").read_text() diff --git a/local-requirements.txt b/local-requirements.txt index 5f43ce4e8..2ba92a371 100644 --- a/local-requirements.txt +++ b/local-requirements.txt @@ -1,17 +1,17 @@ -pytest==5.4.3 +pytest==6.1.0 pytest-asyncio==0.14.0 -pytest-cov==2.10.0 +pytest-cov==2.10.1 pytest-sugar==0.9.4 -pytest-xdist==1.33.0 +pytest-xdist==2.1.0 pytest-timeout==1.4.2 pixelmatch==0.2.1 Pillow==7.2.0 mypy==0.782 -setuptools==49.1.0 +setuptools==50.3.0 twisted==20.3.0 -wheel==0.34.2 -black==19.10b0 -pre-commit==2.6.0 +wheel==0.35.1 +black==20.8b1 +pre-commit==2.7.1 flake8==3.8.3 twine==3.2.0 pyOpenSSL==19.1.0 diff --git a/playwright/async_api.py b/playwright/async_api.py index ae17c3a51..b687d4624 100644 --- a/playwright/async_api.py +++ b/playwright/async_api.py @@ -3042,8 +3042,7 @@ async def accept(self, promptText: str = None) -> NoneType: ) async def dismiss(self) -> NoneType: - """Dialog.dismiss - """ + """Dialog.dismiss""" return mapping.from_maybe_impl(await self._impl_obj.dismiss()) diff --git a/playwright/browser.py b/playwright/browser.py index e3b46c874..13a2ddd4b 100644 --- a/playwright/browser.py +++ b/playwright/browser.py @@ -39,7 +39,9 @@ class Browser(ChannelOwner): - Events = SimpleNamespace(Disconnected="disconnected",) + Events = SimpleNamespace( + Disconnected="disconnected", + ) def __init__( self, parent: "BrowserType", type: str, guid: str, initializer: Dict diff --git a/playwright/browser_context.py b/playwright/browser_context.py index d00b1bf6a..0376c5529 100644 --- a/playwright/browser_context.py +++ b/playwright/browser_context.py @@ -41,7 +41,10 @@ class BrowserContext(ChannelOwner): - Events = SimpleNamespace(Close="close", Page="page",) + Events = SimpleNamespace( + Close="close", + Page="page", + ) def __init__( self, parent: ChannelOwner, type: str, guid: str, initializer: Dict @@ -219,11 +222,16 @@ async def close(self) -> None: await self._channel.send("close") def expect_event( - self, event: str, predicate: Callable[[Any], bool] = None, timeout: int = None, + self, + event: str, + predicate: Callable[[Any], bool] = None, + timeout: int = None, ) -> EventContextManagerImpl: return EventContextManagerImpl(self.waitForEvent(event, predicate, timeout)) def expect_page( - self, predicate: Callable[[Page], bool] = None, timeout: int = None, + self, + predicate: Callable[[Page], bool] = None, + timeout: int = None, ) -> EventContextManagerImpl[Page]: return EventContextManagerImpl(self.waitForEvent("page", predicate, timeout)) diff --git a/playwright/chromium_browser_context.py b/playwright/chromium_browser_context.py index bc13fb54d..03ec0286f 100644 --- a/playwright/chromium_browser_context.py +++ b/playwright/chromium_browser_context.py @@ -24,7 +24,8 @@ class ChromiumBrowserContext(BrowserContext): Events = SimpleNamespace( - BackgroundPage="backgroundpage", ServiceWorker="serviceworker", + BackgroundPage="backgroundpage", + ServiceWorker="serviceworker", ) def __init__( diff --git a/playwright/connection.py b/playwright/connection.py index e964cf011..3b302a9cb 100644 --- a/playwright/connection.py +++ b/playwright/connection.py @@ -66,12 +66,12 @@ def __init__( self._loop: asyncio.AbstractEventLoop = parent._loop self._type = type self._guid = guid - self._connection: Connection = parent._connection if isinstance( - parent, ChannelOwner - ) else parent - self._parent: Optional[ChannelOwner] = parent if isinstance( - parent, ChannelOwner - ) else None + self._connection: Connection = ( + parent._connection if isinstance(parent, ChannelOwner) else parent + ) + self._parent: Optional[ChannelOwner] = ( + parent if isinstance(parent, ChannelOwner) else None + ) self._objects: Dict[str, "ChannelOwner"] = {} self._channel = Channel(self._connection, guid) self._channel._object = self diff --git a/playwright/frame.py b/playwright/frame.py index 641d6972e..406d23be4 100644 --- a/playwright/frame.py +++ b/playwright/frame.py @@ -79,7 +79,8 @@ def __init__( lambda params: self._on_load_state(params.get("add"), params.get("remove")), ) self._channel.on( - "navigated", lambda params: self._on_frame_navigated(params), + "navigated", + lambda params: self._on_frame_navigated(params), ) def _on_load_state( @@ -156,7 +157,9 @@ def predicate(event: Any) -> bool: return not matcher or matcher.matches(event["url"]) event = await wait_helper.wait_for_event( - self._event_emitter, "navigated", predicate=predicate, + self._event_emitter, + "navigated", + predicate=predicate, ) if "error" in event: raise Error(event["error"]) @@ -293,7 +296,10 @@ async def content(self) -> str: return await self._channel.send("content") async def setContent( - self, html: str, timeout: int = None, waitUntil: DocumentLoadState = None, + self, + html: str, + timeout: int = None, + waitUntil: DocumentLoadState = None, ) -> None: await self._channel.send("setContent", locals_to_params(locals())) @@ -484,7 +490,9 @@ async def title(self) -> str: return await self._channel.send("title") def expect_load_state( - self, state: DocumentLoadState = None, timeout: int = None, + self, + state: DocumentLoadState = None, + timeout: int = None, ) -> EventContextManagerImpl[Optional[Response]]: return EventContextManagerImpl(self.waitForLoadState(state, timeout)) diff --git a/playwright/input.py b/playwright/input.py index 6fdac66f5..246503b00 100644 --- a/playwright/input.py +++ b/playwright/input.py @@ -45,10 +45,18 @@ def __init__(self, channel: Channel) -> None: async def move(self, x: float, y: float, steps: int = None) -> None: await self._channel.send("mouseMove", locals_to_params(locals())) - async def down(self, button: MouseButton = None, clickCount: int = None,) -> None: + async def down( + self, + button: MouseButton = None, + clickCount: int = None, + ) -> None: await self._channel.send("mouseDown", locals_to_params(locals())) - async def up(self, button: MouseButton = None, clickCount: int = None,) -> None: + async def up( + self, + button: MouseButton = None, + clickCount: int = None, + ) -> None: await self._channel.send("mouseUp", locals_to_params(locals())) async def click( @@ -62,6 +70,10 @@ async def click( await self._channel.send("mouseClick", locals_to_params(locals())) async def dblclick( - self, x: float, y: float, delay: int = None, button: MouseButton = None, + self, + x: float, + y: float, + delay: int = None, + button: MouseButton = None, ) -> None: await self.click(x, y, delay=delay, button=button, clickCount=2) diff --git a/playwright/page.py b/playwright/page.py index 2b5c5c29e..cc8f15c28 100644 --- a/playwright/page.py +++ b/playwright/page.py @@ -396,7 +396,10 @@ async def content(self) -> str: return await self._main_frame.content() async def setContent( - self, html: str, timeout: int = None, waitUntil: DocumentLoadState = None, + self, + html: str, + timeout: int = None, + waitUntil: DocumentLoadState = None, ) -> None: return await self._main_frame.setContent(**locals_to_params(locals())) @@ -410,7 +413,9 @@ async def goto( return await self._main_frame.goto(**locals_to_params(locals())) async def reload( - self, timeout: int = None, waitUntil: DocumentLoadState = None, + self, + timeout: int = None, + waitUntil: DocumentLoadState = None, ) -> Optional[Response]: return from_nullable_channel( await self._channel.send("reload", locals_to_params(locals())) @@ -489,21 +494,27 @@ async def waitForEvent( return await wait_helper.wait_for_event(self, event, predicate) async def goBack( - self, timeout: int = None, waitUntil: DocumentLoadState = None, + self, + timeout: int = None, + waitUntil: DocumentLoadState = None, ) -> Optional[Response]: return from_nullable_channel( await self._channel.send("goBack", locals_to_params(locals())) ) async def goForward( - self, timeout: int = None, waitUntil: DocumentLoadState = None, + self, + timeout: int = None, + waitUntil: DocumentLoadState = None, ) -> Optional[Response]: return from_nullable_channel( await self._channel.send("goForward", locals_to_params(locals())) ) async def emulateMedia( - self, media: Literal["print", "screen"] = None, colorScheme: ColorScheme = None, + self, + media: Literal["print", "screen"] = None, + colorScheme: ColorScheme = None, ) -> None: await self._channel.send("emulateMedia", locals_to_params(locals())) @@ -760,36 +771,49 @@ async def pdf( return decoded_binary def expect_event( - self, event: str, predicate: Callable[[Any], bool] = None, timeout: int = None, + self, + event: str, + predicate: Callable[[Any], bool] = None, + timeout: int = None, ) -> EventContextManagerImpl: return EventContextManagerImpl(self.waitForEvent(event, predicate, timeout)) def expect_console_message( - self, predicate: Callable[[ConsoleMessage], bool] = None, timeout: int = None, + self, + predicate: Callable[[ConsoleMessage], bool] = None, + timeout: int = None, ) -> EventContextManagerImpl[ConsoleMessage]: return EventContextManagerImpl(self.waitForEvent("console", predicate, timeout)) def expect_dialog( - self, predicate: Callable[[Dialog], bool] = None, timeout: int = None, + self, + predicate: Callable[[Dialog], bool] = None, + timeout: int = None, ) -> EventContextManagerImpl[Dialog]: return EventContextManagerImpl(self.waitForEvent("dialog", predicate, timeout)) def expect_download( - self, predicate: Callable[[Download], bool] = None, timeout: int = None, + self, + predicate: Callable[[Download], bool] = None, + timeout: int = None, ) -> EventContextManagerImpl[Download]: return EventContextManagerImpl( self.waitForEvent("download", predicate, timeout) ) def expect_file_chooser( - self, predicate: Callable[[FileChooser], bool] = None, timeout: int = None, + self, + predicate: Callable[[FileChooser], bool] = None, + timeout: int = None, ) -> EventContextManagerImpl[FileChooser]: return EventContextManagerImpl( self.waitForEvent("filechooser", predicate, timeout) ) def expect_load_state( - self, state: DocumentLoadState = None, timeout: int = None, + self, + state: DocumentLoadState = None, + timeout: int = None, ) -> EventContextManagerImpl[Optional[Response]]: return EventContextManagerImpl(self.waitForLoadState(state, timeout)) @@ -802,7 +826,9 @@ def expect_navigation( return EventContextManagerImpl(self.waitForNavigation(url, waitUntil, timeout)) def expect_popup( - self, predicate: Callable[["Page"], bool] = None, timeout: int = None, + self, + predicate: Callable[["Page"], bool] = None, + timeout: int = None, ) -> EventContextManagerImpl["Page"]: return EventContextManagerImpl(self.waitForEvent("popup", predicate, timeout)) @@ -823,7 +849,9 @@ def expect_response( return EventContextManagerImpl(self.waitForResponse(url, predicate, timeout)) def expect_worker( - self, predicate: Callable[["Worker"], bool] = None, timeout: int = None, + self, + predicate: Callable[["Worker"], bool] = None, + timeout: int = None, ) -> EventContextManagerImpl["Worker"]: return EventContextManagerImpl(self.waitForEvent("worker", predicate, timeout)) diff --git a/playwright/sync_api.py b/playwright/sync_api.py index c4f029870..7e2a01b2c 100644 --- a/playwright/sync_api.py +++ b/playwright/sync_api.py @@ -3170,8 +3170,7 @@ def accept(self, promptText: str = None) -> NoneType: ) def dismiss(self) -> NoneType: - """Dialog.dismiss - """ + """Dialog.dismiss""" return mapping.from_maybe_impl(self._sync(self._impl_obj.dismiss())) diff --git a/scripts/documentation_provider.py b/scripts/documentation_provider.py index b064e0546..460d8f5d2 100644 --- a/scripts/documentation_provider.py +++ b/scripts/documentation_provider.py @@ -193,7 +193,9 @@ def compare_types(self, value: Any, doc_value: Any, fqname: str) -> None: return code_type = self.serialize_python_type(value) doc_type = self.serialize_doc_type( - doc_value["type"]["name"], fqname, doc_value["type"], + doc_value["type"]["name"], + fqname, + doc_value["type"], ) if not doc_value["required"]: doc_type = self.make_optional(doc_type) diff --git a/scripts/report_downstream_test_diffs.py b/scripts/report_downstream_test_diffs.py index 8750ae9c1..6b594814e 100644 --- a/scripts/report_downstream_test_diffs.py +++ b/scripts/report_downstream_test_diffs.py @@ -26,7 +26,9 @@ def pytest_test_cases() -> typing.Generator[TestCase, None, None]: matches = re.finditer(regex, p.stdout.decode(), re.MULTILINE) for match in matches: yield TestCase( - match.group("api"), match.group("file"), match.group("test"), + match.group("api"), + match.group("file"), + match.group("test"), ) diff --git a/tests/async/test_accessibility.py b/tests/async/test_accessibility.py index c94846ddb..b3a3b0257 100644 --- a/tests/async/test_accessibility.py +++ b/tests/async/test_accessibility.py @@ -203,7 +203,8 @@ async def test_accessibility_filtering_children_of_leaf_nodes_rich_text_editable # WebKit rich text accessibility is iffy @pytest.mark.skip_browser("webkit") async def test_accessibility_filtering_children_of_leaf_nodes_rich_text_editable_fields_with_role_should_have_children( - page, is_firefox, + page, + is_firefox, ): await page.setContent( """ diff --git a/tests/async/test_browsercontext.py b/tests/async/test_browsercontext.py index 1082f9162..b3ed35c06 100644 --- a/tests/async/test_browsercontext.py +++ b/tests/async/test_browsercontext.py @@ -146,7 +146,8 @@ async def test_close_should_abort_wait_for_event(browser): async def test_close_should_be_callable_twice(browser): context = await browser.newContext() await asyncio.gather( - context.close(), context.close(), + context.close(), + context.close(), ) await context.close() @@ -164,7 +165,8 @@ async def override(): context = await browser.newContext(userAgent="foobar") page = await context.newPage() [request, _] = await asyncio.gather( - server.wait_for_request("/empty.html"), page.goto(server.EMPTY_PAGE), + server.wait_for_request("/empty.html"), + page.goto(server.EMPTY_PAGE), ) assert request.getHeader("user-agent") == "foobar" await context.close() @@ -199,7 +201,8 @@ async def test_user_agent_should_make_a_copy_of_default_options(browser, server) options["userAgent"] = "wrong" page = await context.newPage() [request, _] = await asyncio.gather( - server.wait_for_request("/empty.html"), page.goto(server.EMPTY_PAGE), + server.wait_for_request("/empty.html"), + page.goto(server.EMPTY_PAGE), ) assert request.getHeader("user-agent") == "foobar" await context.close() diff --git a/tests/async/test_browsercontext_add_cookies.py b/tests/async/test_browsercontext_add_cookies.py index 19e026cfc..3256268ba 100644 --- a/tests/async/test_browsercontext_add_cookies.py +++ b/tests/async/test_browsercontext_add_cookies.py @@ -87,7 +87,10 @@ async def test_should_isolate_cookies_in_browser_contexts(context, server, brows async def test_should_isolate_session_cookies(context, server, browser): server.set_route( "/setcookie.html", - lambda r: (r.setHeader("Set-Cookie", "session=value"), r.finish(),), + lambda r: ( + r.setHeader("Set-Cookie", "session=value"), + r.finish(), + ), ) page_1 = await context.newPage() diff --git a/tests/async/test_browsercontext_cookies.py b/tests/async/test_browsercontext_cookies.py index 1537d6c3f..c40a8a53d 100644 --- a/tests/async/test_browsercontext_cookies.py +++ b/tests/async/test_browsercontext_cookies.py @@ -113,7 +113,10 @@ async def test_should_properly_report_lax_samesite_cookie( server.set_route( "/empty.html", - lambda r: (r.setHeader("Set-Cookie", "name=value;SameSite=Lax"), r.finish(),), + lambda r: ( + r.setHeader("Set-Cookie", "name=value;SameSite=Lax"), + r.finish(), + ), ) await page.goto(server.EMPTY_PAGE) cookies = await context.cookies() diff --git a/tests/async/test_click.py b/tests/async/test_click.py index de1b80371..1895e8034 100644 --- a/tests/async/test_click.py +++ b/tests/async/test_click.py @@ -71,7 +71,8 @@ async def test_click_not_throw_when_page_closes(browser, server): page = await context.newPage() try: await asyncio.gather( - page.close(), page.mouse.click(1, 2), + page.close(), + page.mouse.click(1, 2), ) except Error: pass diff --git a/tests/async/test_console.py b/tests/async/test_console.py index e00a431c4..88961387c 100644 --- a/tests/async/test_console.py +++ b/tests/async/test_console.py @@ -111,7 +111,8 @@ async def test_console_should_have_location_for_console_api_calls(page, server): await page.goto(server.EMPTY_PAGE) message = ( await asyncio.gather( - page.waitForEvent("console"), page.goto(server.PREFIX + "/consolelog.html"), + page.waitForEvent("console"), + page.goto(server.PREFIX + "/consolelog.html"), ) )[0] assert message.text == "yellow" diff --git a/tests/async/test_defaultbrowsercontext.py b/tests/async/test_defaultbrowsercontext.py index eeec24a41..cffec4546 100644 --- a/tests/async/test_defaultbrowsercontext.py +++ b/tests/async/test_defaultbrowsercontext.py @@ -160,7 +160,8 @@ async def test_should_support_user_agent_option(launch_persistent, server): (page, context) = await launch_persistent(userAgent="foobar") assert await page.evaluate("() => navigator.userAgent") == "foobar" [request, _] = await asyncio.gather( - server.wait_for_request("/empty.html"), page.goto(server.EMPTY_PAGE), + server.wait_for_request("/empty.html"), + page.goto(server.EMPTY_PAGE), ) assert request.getHeader("user-agent") == "foobar" @@ -264,7 +265,8 @@ async def test_should_support_ignore_https_errors_option( async def test_should_support_extra_http_headers_option(server, launch_persistent): (page, context) = await launch_persistent(extraHTTPHeaders={"foo": "bar"}) [request, _] = await asyncio.gather( - server.wait_for_request("/empty.html"), page.goto(server.EMPTY_PAGE), + server.wait_for_request("/empty.html"), + page.goto(server.EMPTY_PAGE), ) assert request.getHeader("foo") == "bar" diff --git a/tests/async/test_download.py b/tests/async/test_download.py index 70c317610..0d5a3ac08 100644 --- a/tests/async/test_download.py +++ b/tests/async/test_download.py @@ -207,7 +207,8 @@ async def on_download(download): on_download_path.set_result(await download.path()) page.once( - "download", lambda res: asyncio.create_task(on_download(res)), + "download", + lambda res: asyncio.create_task(on_download(res)), ) await page.setContent(f'download') await page.click("a") @@ -226,7 +227,8 @@ async def on_download(download): on_download_path.set_result(await download.path()) page.once( - "download", lambda res: asyncio.create_task(on_download(res)), + "download", + lambda res: asyncio.create_task(on_download(res)), ) await page.goto(server.PREFIX + "/download-blob.html") diff --git a/tests/async/test_emulation_focus.py b/tests/async/test_emulation_focus.py index 1d446d0fd..74a0ccaaf 100644 --- a/tests/async/test_emulation_focus.py +++ b/tests/async/test_emulation_focus.py @@ -42,14 +42,19 @@ async def test_should_provide_target_for_keyboard_events(page, server): page2.goto(server.PREFIX + "/input/textarea.html"), ) await asyncio.gather( - page.focus("input"), page2.focus("input"), + page.focus("input"), + page2.focus("input"), ) text = "first" text2 = "second" await asyncio.gather( - page.keyboard.type(text), page2.keyboard.type(text2), + page.keyboard.type(text), + page2.keyboard.type(text2), + ) + results = await asyncio.gather( + page.evaluate("result"), + page2.evaluate("result"), ) - results = await asyncio.gather(page.evaluate("result"), page2.evaluate("result"),) assert results == [text, text2] @@ -65,10 +70,12 @@ async def test_should_not_affect_mouse_event_target_page(page, server): page2.focus("body"), ) await asyncio.gather( - page.mouse.click(1, 1), page2.mouse.click(1, 1), + page.mouse.click(1, 1), + page2.mouse.click(1, 1), ) counters = await asyncio.gather( - page.evaluate("window.clickCount"), page2.evaluate("window.clickCount"), + page.evaluate("window.clickCount"), + page2.evaluate("window.clickCount"), ) assert counters == [1, 1] @@ -80,7 +87,8 @@ async def test_should_change_document_activeElement(page, server): page2.goto(server.PREFIX + "/input/textarea.html"), ) await asyncio.gather( - page.focus("input"), page2.focus("textarea"), + page.focus("input"), + page2.focus("textarea"), ) active = await asyncio.gather( page.evaluate("document.activeElement.tagName"), @@ -99,9 +107,13 @@ async def test_should_not_affect_screenshots(page, server, assert_to_be_golden): page2.goto(server.PREFIX + "/grid.html"), ) await asyncio.gather( - page.focus("body"), page2.focus("body"), + page.focus("body"), + page2.focus("body"), + ) + screenshots = await asyncio.gather( + page.screenshot(), + page2.screenshot(), ) - screenshots = await asyncio.gather(page.screenshot(), page2.screenshot(),) assert_to_be_golden(screenshots[0], "screenshot-sanity.png") assert_to_be_golden(screenshots[1], "grid-cell-0.png") @@ -118,27 +130,33 @@ async def test_should_change_focused_iframe(page, server, utils): element.onfocus = element.onblur = (e) => self._events.push(e.type); }""" await asyncio.gather( - frame1.evaluate(logger), frame2.evaluate(logger), + frame1.evaluate(logger), + frame2.evaluate(logger), ) focused = await asyncio.gather( - frame1.evaluate("document.hasFocus()"), frame2.evaluate("document.hasFocus()"), + frame1.evaluate("document.hasFocus()"), + frame2.evaluate("document.hasFocus()"), ) assert focused == [False, False] await frame1.focus("input") events = await asyncio.gather( - frame1.evaluate("self._events"), frame2.evaluate("self._events"), + frame1.evaluate("self._events"), + frame2.evaluate("self._events"), ) assert events == [["focus"], []] focused = await asyncio.gather( - frame1.evaluate("document.hasFocus()"), frame2.evaluate("document.hasFocus()"), + frame1.evaluate("document.hasFocus()"), + frame2.evaluate("document.hasFocus()"), ) assert focused == [True, False] await frame2.focus("input") events = await asyncio.gather( - frame1.evaluate("self._events"), frame2.evaluate("self._events"), + frame1.evaluate("self._events"), + frame2.evaluate("self._events"), ) assert events == [["focus", "blur"], ["focus"]] focused = await asyncio.gather( - frame1.evaluate("document.hasFocus()"), frame2.evaluate("document.hasFocus()"), + frame1.evaluate("document.hasFocus()"), + frame2.evaluate("document.hasFocus()"), ) assert focused == [False, True] diff --git a/tests/async/test_input.py b/tests/async/test_input.py index eddc46ec0..490d9fbbc 100644 --- a/tests/async/test_input.py +++ b/tests/async/test_input.py @@ -112,7 +112,10 @@ async def test_should_return_the_same_file_chooser_when_there_are_many_watchdogs async def test_should_accept_single_file(page: Page, server): await page.setContent('') file_chooser = ( - await asyncio.gather(page.waitForEvent("filechooser"), page.click("input"),) + await asyncio.gather( + page.waitForEvent("filechooser"), + page.click("input"), + ) )[0] assert file_chooser.page == page assert file_chooser.element @@ -192,7 +195,10 @@ async def test_should_not_accept_multiple_files_for_single_file_input( ): await page.setContent("") file_chooser = ( - await asyncio.gather(page.waitForEvent("filechooser"), page.click("input"),) + await asyncio.gather( + page.waitForEvent("filechooser"), + page.click("input"), + ) )[0] error = None try: @@ -228,7 +234,10 @@ async def test_should_emit_input_and_change_events(page, server): async def test_should_work_for_single_file_pick(page, server): await page.setContent("") file_chooser = ( - await asyncio.gather(page.waitForEvent("filechooser"), page.click("input"),) + await asyncio.gather( + page.waitForEvent("filechooser"), + page.click("input"), + ) )[0] assert file_chooser.isMultiple is False @@ -236,7 +245,10 @@ async def test_should_work_for_single_file_pick(page, server): async def test_should_work_for_multiple(page, server): await page.setContent("") file_chooser = ( - await asyncio.gather(page.waitForEvent("filechooser"), page.click("input"),) + await asyncio.gather( + page.waitForEvent("filechooser"), + page.click("input"), + ) )[0] assert file_chooser.isMultiple @@ -244,6 +256,9 @@ async def test_should_work_for_multiple(page, server): async def test_should_work_for_webkitdirectory(page, server): await page.setContent("") file_chooser = ( - await asyncio.gather(page.waitForEvent("filechooser"), page.click("input"),) + await asyncio.gather( + page.waitForEvent("filechooser"), + page.click("input"), + ) )[0] assert file_chooser.isMultiple diff --git a/tests/async/test_interception.py b/tests/async/test_interception.py index f2e7c0b44..0a8e8f4b1 100644 --- a/tests/async/test_interception.py +++ b/tests/async/test_interception.py @@ -269,7 +269,8 @@ async def test_page_route_should_send_referer(page, server): await page.route("**/*", lambda route, _: asyncio.create_task(route.continue_())) [request, _] = await asyncio.gather( - server.wait_for_request("/grid.html"), page.goto(server.PREFIX + "/grid.html"), + server.wait_for_request("/grid.html"), + page.goto(server.PREFIX + "/grid.html"), ) assert request.getHeader("referer") == "http://google.com/" @@ -770,7 +771,8 @@ async def test_request_fulfill_should_allow_mocking_binary_responses( "**/*", lambda route, request: asyncio.create_task( route.fulfill( - contentType="image/png", body=(assetdir / "pptr.png").read_bytes(), + contentType="image/png", + body=(assetdir / "pptr.png").read_bytes(), ) ), ) diff --git a/tests/async/test_launcher.py b/tests/async/test_launcher.py index e847b21b0..7618611e5 100644 --- a/tests/async/test_launcher.py +++ b/tests/async/test_launcher.py @@ -238,7 +238,9 @@ async def handle_waitForResponse(): asyncio.create_task(handle_waitForResponse()) await asyncio.sleep(0) # execute scheduled tasks, but don't await them results = await asyncio.gather( - wait_for_request_future, wait_for_response_future, browser_server.close(), + wait_for_request_future, + wait_for_response_future, + browser_server.close(), ) for i in range(2): message = results[i].message @@ -260,7 +262,8 @@ async def test_browser_close_should_fire_close_event_for_all_contexts( async def test_browser_close_should_be_callable_twice(browser_type, launch_arguments): browser = await browser_type.launch(**launch_arguments) await asyncio.gather( - browser.close(), browser.close(), + browser.close(), + browser.close(), ) await browser.close() @@ -294,7 +297,8 @@ async def test_browser_type_launch_server_should_fire_disconnected_when_closing_ await browser_server.kill() await asyncio.gather( - disconnected_promise, closed_promise, + disconnected_promise, + closed_promise, ) diff --git a/tests/async/test_navigation.py b/tests/async/test_navigation.py index e629ed5b5..5e09c209a 100644 --- a/tests/async/test_navigation.py +++ b/tests/async/test_navigation.py @@ -481,7 +481,10 @@ def handle(r): async def test_wait_for_nav_should_work_with_clicking_on_anchor_links(page, server): await page.goto(server.EMPTY_PAGE) await page.setContent('foobar') - [response, _] = await asyncio.gather(page.waitForNavigation(), page.click("a"),) + [response, _] = await asyncio.gather( + page.waitForNavigation(), + page.click("a"), + ) assert response is None assert page.url == server.EMPTY_PAGE + "#foobar" @@ -493,7 +496,8 @@ async def test_wait_for_nav_should_work_with_clicking_on_links_which_do_not_comm await page.setContent(f"foobar") with pytest.raises(Error) as exc_info: await asyncio.gather( - page.waitForNavigation(), page.click("a"), + page.waitForNavigation(), + page.click("a"), ) expect_ssl_error(exc_info.value.message, browser_name) @@ -508,7 +512,10 @@ async def test_wait_for_nav_should_work_with_history_push_state(page, server): """ ) - [response, _] = await asyncio.gather(page.waitForNavigation(), page.click("a"),) + [response, _] = await asyncio.gather( + page.waitForNavigation(), + page.click("a"), + ) assert response is None assert page.url == server.PREFIX + "/wow.html" @@ -523,7 +530,10 @@ async def test_wait_for_nav_should_work_with_history_replace_state(page, server) """ ) - [response, _] = await asyncio.gather(page.waitForNavigation(), page.click("a"),) + [response, _] = await asyncio.gather( + page.waitForNavigation(), + page.click("a"), + ) assert response is None assert page.url == server.PREFIX + "/replaced.html" @@ -544,12 +554,14 @@ async def test_wait_for_nav_should_work_with_dom_history_back_forward(page, serv ) assert page.url == server.PREFIX + "/second.html" [back_response, _] = await asyncio.gather( - page.waitForNavigation(), page.click("a#back"), + page.waitForNavigation(), + page.click("a#back"), ) assert back_response is None assert page.url == server.PREFIX + "/first.html" [forward_response, _] = await asyncio.gather( - page.waitForNavigation(), page.click("a#forward"), + page.waitForNavigation(), + page.click("a#forward"), ) assert forward_response is None assert page.url == server.PREFIX + "/second.html" diff --git a/tests/async/test_network.py b/tests/async/test_network.py index aa9e7d6b0..6cd0034f0 100644 --- a/tests/async/test_network.py +++ b/tests/async/test_network.py @@ -308,14 +308,20 @@ async def test_response_json_should_work(page, server): async def test_response_body_should_work(page, server, assetdir): response = await page.goto(server.PREFIX + "/pptr.png") - with open(assetdir / "pptr.png", "rb",) as fd: + with open( + assetdir / "pptr.png", + "rb", + ) as fd: assert fd.read() == await response.body() async def test_response_body_should_work_with_compression(page, server, assetdir): server.enable_gzip("/pptr.png") response = await page.goto(server.PREFIX + "/pptr.png") - with open(assetdir / "pptr.png", "rb",) as fd: + with open( + assetdir / "pptr.png", + "rb", + ) as fd: assert fd.read() == await response.body() @@ -501,7 +507,8 @@ async def test_set_extra_http_headers_should_work(page, server): request = ( await asyncio.gather( - server.wait_for_request("/empty.html"), page.goto(server.EMPTY_PAGE), + server.wait_for_request("/empty.html"), + page.goto(server.EMPTY_PAGE), ) )[0] assert request.getHeader("foo") == "bar" @@ -529,7 +536,8 @@ async def test_set_extra_http_headers_should_work_with_extra_headers_from_browse page = await context.newPage() request = ( await asyncio.gather( - server.wait_for_request("/empty.html"), page.goto(server.EMPTY_PAGE), + server.wait_for_request("/empty.html"), + page.goto(server.EMPTY_PAGE), ) )[0] await context.close() @@ -546,7 +554,8 @@ async def test_set_extra_http_headers_should_override_extra_headers_from_browser request = ( await asyncio.gather( - server.wait_for_request("/empty.html"), page.goto(server.EMPTY_PAGE), + server.wait_for_request("/empty.html"), + page.goto(server.EMPTY_PAGE), ) )[0] await context.close() diff --git a/tests/async/test_page.py b/tests/async/test_page.py index 819a868f0..5b94cc137 100644 --- a/tests/async/test_page.py +++ b/tests/async/test_page.py @@ -105,14 +105,16 @@ async def wait_for_response(): async def test_close_should_be_callable_twice(context): page = await context.newPage() await asyncio.gather( - page.close(), page.close(), + page.close(), + page.close(), ) await page.close() async def test_load_should_fire_when_expected(page): await asyncio.gather( - page.goto("about:blank"), page.waitForEvent("load"), + page.goto("about:blank"), + page.waitForEvent("load"), ) @@ -130,7 +132,8 @@ async def test_async_stacks_should_work(page, server): async def test_opener_should_provide_access_to_the_opener_page(page): [popup, _] = await asyncio.gather( - page.waitForEvent("popup"), page.evaluate("window.open('about:blank')"), + page.waitForEvent("popup"), + page.evaluate("window.open('about:blank')"), ) opener = await popup.opener() assert opener == page @@ -138,7 +141,8 @@ async def test_opener_should_provide_access_to_the_opener_page(page): async def test_opener_should_return_null_if_parent_page_has_been_closed(page): [popup, _] = await asyncio.gather( - page.waitForEvent("popup"), page.evaluate("window.open('about:blank')"), + page.waitForEvent("popup"), + page.evaluate("window.open('about:blank')"), ) await page.close() opener = await popup.opener() @@ -383,7 +387,8 @@ async def test_expose_function_should_work_with_complex_objects(page, server): async def test_page_error_should_fire(page, server, is_webkit): [error, _] = await asyncio.gather( - page.waitForEvent("pageerror"), page.goto(server.PREFIX + "/error.html"), + page.waitForEvent("pageerror"), + page.goto(server.PREFIX + "/error.html"), ) assert error.message == "Fancy error!" stack = await page.evaluate("window.e.stack") @@ -771,7 +776,8 @@ async def test_select_option_should_not_throw_when_select_causes_navigation( "select => select.addEventListener('input', () => window.location = '/empty.html')", ) await asyncio.gather( - page.waitForNavigation(), page.selectOption("select", "blue"), + page.waitForNavigation(), + page.selectOption("select", "blue"), ) assert "empty.html" in page.url diff --git a/tests/async/test_popup.py b/tests/async/test_popup.py index a4b6e2946..24ac5610f 100644 --- a/tests/async/test_popup.py +++ b/tests/async/test_popup.py @@ -31,7 +31,13 @@ async def test_link_navigation_inherit_user_agent_from_browser_context( request_waitable = asyncio.create_task(server.wait_for_request("/popup/popup.html")) await asyncio.sleep(0) # execute scheduled tasks, but don't await them popup = cast( - Page, (await asyncio.gather(context.waitForEvent("page"), page.click("a"),))[0] + Page, + ( + await asyncio.gather( + context.waitForEvent("page"), + page.click("a"), + ) + )[0], ) await popup.waitForLoadState("domcontentloaded") user_agent = await popup.evaluate("window.initialUserAgent") @@ -56,7 +62,8 @@ def handle_request(route: Route, request: Request, intercepted) -> None: lambda route, request: handle_request(route, request, intercepted), ) await asyncio.gather( - context.waitForEvent("page"), page.click("a"), + context.waitForEvent("page"), + page.click("a"), ) assert intercepted == [True] @@ -407,7 +414,12 @@ async def test_should_work_with_clicking_target__blank(context, server): page = await context.newPage() await page.goto(server.EMPTY_PAGE) await page.setContent('yo') - popup = (await asyncio.gather(page.waitForEvent("popup"), page.click("a"),))[0] + popup = ( + await asyncio.gather( + page.waitForEvent("popup"), + page.click("a"), + ) + )[0] assert await page.evaluate("!!window.opener") is False assert await popup.evaluate("!!window.opener") @@ -420,7 +432,8 @@ async def test_should_work_with_fake_clicking_target__blank_and_rel_noopener( await page.setContent('yo') popup = ( await asyncio.gather( - page.waitForEvent("popup"), page.evalOnSelector("a", "a => a.click()"), + page.waitForEvent("popup"), + page.evalOnSelector("a", "a => a.click()"), ) )[0] assert await page.evaluate("!!window.opener") is False @@ -433,7 +446,12 @@ async def test_should_work_with_clicking_target__blank_and_rel_noopener( page = await context.newPage() await page.goto(server.EMPTY_PAGE) await page.setContent('yo') - popup = (await asyncio.gather(page.waitForEvent("popup"), page.click("a"),))[0] + popup = ( + await asyncio.gather( + page.waitForEvent("popup"), + page.click("a"), + ) + )[0] assert await page.evaluate("!!window.opener") is False assert await popup.evaluate("!!window.opener") is False @@ -446,7 +464,8 @@ async def test_should_not_treat_navigations_as_new_popups(context, server): handled_popups = [] page.on( - "popup", lambda popup: handled_popups.append(True), + "popup", + lambda popup: handled_popups.append(True), ) await popup.goto(server.CROSS_PROCESS_PREFIX + "/empty.html") diff --git a/tests/async/test_worker.py b/tests/async/test_worker.py index fb7871117..c75889a9b 100644 --- a/tests/async/test_worker.py +++ b/tests/async/test_worker.py @@ -137,7 +137,8 @@ async def test_workers_should_clear_upon_cross_process_navigation(server, page): async def test_workers_should_report_network_activity(page, server): [worker, _] = await asyncio.gather( - page.waitForEvent("worker"), page.goto(server.PREFIX + "/worker/worker.html"), + page.waitForEvent("worker"), + page.goto(server.PREFIX + "/worker/worker.html"), ) url = server.PREFIX + "/one-style.css" request_promise = asyncio.create_task(page.waitForRequest(url)) diff --git a/tests/sync/test_accessibility.py b/tests/sync/test_accessibility.py index 79189c65a..5805ad1c9 100644 --- a/tests/sync/test_accessibility.py +++ b/tests/sync/test_accessibility.py @@ -199,7 +199,8 @@ def test_accessibility_filtering_children_of_leaf_nodes_rich_text_editable_field # WebKit rich text accessibility is iffy @pytest.mark.skip_browser("webkit") def test_accessibility_filtering_children_of_leaf_nodes_rich_text_editable_fields_with_role_should_have_children( - page, is_firefox, + page, + is_firefox, ): page.setContent( """ @@ -245,7 +246,9 @@ def test_accessibility_plain_text_field_with_role_should_not_have_children(page) @pytest.mark.only_browser("chromium") -def test_accessibility_plain_text_field_without_role_should_not_have_content(page,): +def test_accessibility_plain_text_field_without_role_should_not_have_content( + page, +): page.setContent( """
Edit this image:my fake image
""" @@ -379,7 +382,9 @@ def test_accessibility_should_work_on_a_menu(page, is_webkit): assert page.accessibility.snapshot(root=menu) == golden -def test_accessibility_should_return_null_when_the_element_is_no_longer_in_DOM(page,): +def test_accessibility_should_return_null_when_the_element_is_no_longer_in_DOM( + page, +): page.setContent("") button = page.querySelector("button") page.evalOnSelector("button", "button => button.remove()")