From f371be968607ed2fa8affc75e6fed19179ccf2e9 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 30 Nov 2023 10:06:48 -0800 Subject: [PATCH] chore: unskip tests / unignore linting in tests (#2180) --- playwright/_impl/_api_structures.py | 1 + scripts/generate_api.py | 12 +----------- tests/async/test_browsercontext_add_cookies.py | 1 + tests/async/test_launcher.py | 2 +- tests/sync/test_assertions.py | 8 ++------ tests/sync/test_browsercontext_request_fallback.py | 3 ++- tests/sync/test_fetch_browser_context.py | 11 ++++++----- 7 files changed, 14 insertions(+), 24 deletions(-) diff --git a/playwright/_impl/_api_structures.py b/playwright/_impl/_api_structures.py index f45f713a1..c20f8d845 100644 --- a/playwright/_impl/_api_structures.py +++ b/playwright/_impl/_api_structures.py @@ -39,6 +39,7 @@ class Cookie(TypedDict, total=False): sameSite: Literal["Lax", "None", "Strict"] +# TODO: We are waiting for PEP705 so SetCookieParam can be readonly and matches Cookie. class SetCookieParam(TypedDict, total=False): name: str value: str diff --git a/scripts/generate_api.py b/scripts/generate_api.py index 388db89e1..274740bda 100644 --- a/scripts/generate_api.py +++ b/scripts/generate_api.py @@ -15,17 +15,7 @@ import re import sys from types import FunctionType -from typing import ( # type: ignore - Any, - Dict, - List, - Match, - Optional, - Union, - cast, - get_args, - get_origin, -) +from typing import Any, Dict, List, Match, Optional, Union, cast, get_args, get_origin from typing import get_type_hints as typing_get_type_hints from playwright._impl._accessibility import Accessibility diff --git a/tests/async/test_browsercontext_add_cookies.py b/tests/async/test_browsercontext_add_cookies.py index 6f457a11f..9423ccd63 100644 --- a/tests/async/test_browsercontext_add_cookies.py +++ b/tests/async/test_browsercontext_add_cookies.py @@ -49,6 +49,7 @@ async def test_should_roundtrip_cookie( cookies = await context.cookies() await context.clear_cookies() assert await context.cookies() == [] + # TODO: We are waiting for PEP705 so SetCookieParam can be readonly and matches the Cookie type. await context.add_cookies(cookies) # type: ignore assert await context.cookies() == cookies diff --git a/tests/async/test_launcher.py b/tests/async/test_launcher.py index 95734cb35..d29b20989 100644 --- a/tests/async/test_launcher.py +++ b/tests/async/test_launcher.py @@ -130,7 +130,7 @@ async def test_browser_launch_should_return_background_pages( f"--disable-extensions-except={extension_path}", f"--load-extension={extension_path}", ], - }, # type: ignore + }, ) background_page = None if len(context.background_pages): diff --git a/tests/sync/test_assertions.py b/tests/sync/test_assertions.py index ef66e2af3..f2df44ab5 100644 --- a/tests/sync/test_assertions.py +++ b/tests/sync/test_assertions.py @@ -90,9 +90,7 @@ def test_assertions_locator_to_contain_text(page: Page, server: Server) -> None: expect(page.locator("div#foobar")).to_contain_text("bar", timeout=100) page.set_content("
Text \n1
Text2
Text3
") - expect(page.locator("div")).to_contain_text( - ["ext 1", re.compile("ext3")] # type: ignore - ) + expect(page.locator("div")).to_contain_text(["ext 1", re.compile("ext3")]) def test_assertions_locator_to_have_attribute(page: Page, server: Server) -> None: @@ -244,9 +242,7 @@ def test_assertions_locator_to_have_text(page: Page, server: Server) -> None: page.set_content("
Text \n1
Text 2a
") # Should only normalize whitespace in the first item. - expect(page.locator("div")).to_have_text( - ["Text 1", re.compile(r"Text \d+a")] # type: ignore - ) + expect(page.locator("div")).to_have_text(["Text 1", re.compile(r"Text \d+a")]) @pytest.mark.parametrize( diff --git a/tests/sync/test_browsercontext_request_fallback.py b/tests/sync/test_browsercontext_request_fallback.py index 24c25f131..e653800d7 100644 --- a/tests/sync/test_browsercontext_request_fallback.py +++ b/tests/sync/test_browsercontext_request_fallback.py @@ -204,7 +204,8 @@ def capture_and_continue(route: Route, request: Request) -> None: def delete_foo_header(route: Route, request: Request) -> None: headers = request.all_headers() - route.fallback(headers={**headers, "foo": None}) # type: ignore + del headers["foo"] + route.fallback(headers=headers) context.route(server.PREFIX + "/something", delete_foo_header) with server.expect_request("/something") as server_req_info: diff --git a/tests/sync/test_fetch_browser_context.py b/tests/sync/test_fetch_browser_context.py index edb00993b..5a8b38769 100644 --- a/tests/sync/test_fetch_browser_context.py +++ b/tests/sync/test_fetch_browser_context.py @@ -20,6 +20,7 @@ from playwright.sync_api import BrowserContext, Error, FilePayload, Page from tests.server import Server +from tests.utils import must def test_get_should_work(context: BrowserContext, server: Server) -> None: @@ -150,11 +151,11 @@ def support_post_data(fetch_data: Any, request_post_data: Any) -> None: server.PREFIX + "/simple.json", data=fetch_data ) assert request.value.method.decode() == method.upper() - assert request.value.post_body == request_post_data # type: ignore + assert request.value.post_body == request_post_data assert response.status == 200 assert response.url == server.PREFIX + "/simple.json" assert request.value.getHeader("Content-Length") == str( - len(request.value.post_body) # type: ignore + len(must(request.value.post_body)) ) support_post_data("My request", "My request".encode()) @@ -182,9 +183,9 @@ def test_should_support_application_x_www_form_urlencoded( server_req.value.getHeader("Content-Type") == "application/x-www-form-urlencoded" ) - body = server_req.value.post_body.decode() # type: ignore + body = must(server_req.value.post_body).decode() assert server_req.value.getHeader("Content-Length") == str(len(body)) - params: Dict[bytes, List[bytes]] = parse_qs(server_req.value.post_body) # type: ignore + params: Dict[bytes, List[bytes]] = parse_qs(server_req.value.post_body) assert params[b"firstName"] == [b"John"] assert params[b"lastName"] == [b"Doe"] assert params[b"file"] == [b"f.js"] @@ -212,7 +213,7 @@ def test_should_support_multipart_form_data( assert content_type assert content_type.startswith("multipart/form-data; ") assert server_req.value.getHeader("Content-Length") == str( - len(server_req.value.post_body) # type: ignore + len(must(server_req.value.post_body)) ) assert server_req.value.args[b"firstName"] == [b"John"] assert server_req.value.args[b"lastName"] == [b"Doe"]