Skip to content

Commit

Permalink
miscellaneous lint, clean-up and modernization changes to webdriver/t…
Browse files Browse the repository at this point in the history
…ests/support (#40470)
  • Loading branch information
thiagowfx committed Jun 16, 2023
1 parent fb57353 commit ff6a3b2
Show file tree
Hide file tree
Showing 48 changed files with 124 additions and 210 deletions.
1 change: 1 addition & 0 deletions webdriver/tests/bidi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def _(actual: Any) -> None:

return _


def positive_int(actual: Any) -> None:
assert isinstance(actual, int) and actual > 0

Expand Down
1 change: 1 addition & 0 deletions webdriver/tests/bidi/browsing_context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
recursive_compare,
)


def assert_browsing_context(
info, context, children=None, is_root=True, parent=None, url=None
):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from webdriver.bidi.modules.script import ContextTarget


async def viewport_dimensions(bidi_session, context):
"""Get the dimensions of the context's viewport.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@pytest.mark.asyncio
async def test_capture(bidi_session, url, top_context, inline, compare_png_bidi):
async def test_capture(bidi_session, top_context, inline, compare_png_bidi):
expected_size = await viewport_dimensions(bidi_session, top_context)

await bidi_session.browsing_context.navigate(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import asyncio

import pytest
from webdriver.error import TimeoutException
from webdriver.bidi.modules.script import ContextTarget
Expand All @@ -19,7 +17,7 @@ async def test_not_unsubscribed(bidi_session):
# Track all received browsingContext.contextCreated events in the events array
events = []

async def on_event(method, data):
async def on_event(_, data):
events.append(data)

remove_listener = bidi_session.add_event_listener(CONTEXT_CREATED_EVENT, on_event)
Expand All @@ -38,7 +36,7 @@ async def test_new_context(bidi_session, wait_for_event, subscribe_events, type_
await subscribe_events([CONTEXT_CREATED_EVENT])

on_entry = wait_for_event(CONTEXT_CREATED_EVENT)
top_level_context = await bidi_session.browsing_context.create(type_hint="tab")
top_level_context = await bidi_session.browsing_context.create(type_hint=type_hint)
context_info = await on_entry

assert_browsing_context(
Expand Down Expand Up @@ -96,7 +94,7 @@ async def test_evaluate_window_open_with_url(bidi_session, subscribe_events, wai
async def test_navigate_creates_iframes(bidi_session, subscribe_events, top_context, test_page_multiple_frames):
events = []

async def on_event(method, data):
async def on_event(_, data):
events.append(data)

remove_listener = bidi_session.add_event_listener(CONTEXT_CREATED_EVENT, on_event)
Expand Down Expand Up @@ -144,7 +142,7 @@ async def on_event(method, data):
async def test_navigate_creates_nested_iframes(bidi_session, subscribe_events, top_context, test_page_nested_frames):
events = []

async def on_event(method, data):
async def on_event(_, data):
events.append(data)

remove_listener = bidi_session.add_event_listener(CONTEXT_CREATED_EVENT, on_event)
Expand Down Expand Up @@ -202,7 +200,7 @@ async def test_subscribe_to_one_context(
# Track all received browsingContext.contextCreated events in the events array
events = []

async def on_event(method, data):
async def on_event(_, data):
events.append(data)

remove_listener = bidi_session.add_event_listener(CONTEXT_CREATED_EVENT, on_event)
Expand Down
2 changes: 1 addition & 1 deletion webdriver/tests/bidi/browsing_context/print/background.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import base64
import pytest

from tests.support.asserts import assert_pdf
from tests.support.image import px_to_cm
from tests.support.pdf import assert_pdf

pytestmark = pytest.mark.asyncio

Expand Down
1 change: 1 addition & 0 deletions webdriver/tests/bidi/browsing_context/print/invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ async def test_params_page_ranges_invalid_type(bidi_session, top_context, page_r
context=top_context["context"], page_ranges=page_ranges
)


@pytest.mark.parametrize(
"page_ranges",
[
Expand Down
2 changes: 1 addition & 1 deletion webdriver/tests/bidi/browsing_context/print/orientation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from tests.support.asserts import assert_pdf
from tests.support.image import png_dimensions
from tests.support.pdf import assert_pdf


pytestmark = pytest.mark.asyncio
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion webdriver/tests/bidi/errors/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
'invalid module',
'invalid command name',
])
async def test_unknown_command(bidi_session, send_blocking_command, module_name, command_name):
async def test_unknown_command(send_blocking_command, module_name, command_name):
with pytest.raises(UnknownCommandException):
await send_blocking_command(f"{module_name}.{command_name}", {})
6 changes: 2 additions & 4 deletions webdriver/tests/bidi/log/entry_added/event_buffer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import asyncio

import pytest

from . import assert_base_entry, create_log
Expand All @@ -20,7 +18,7 @@ async def test_console_log_cached_messages(
# Track all received log.entryAdded events in the events array
events = []

async def on_event(method, data):
async def on_event(_, data):
events.append(data)

remove_listener = bidi_session.add_event_listener("log.entryAdded", on_event)
Expand Down Expand Up @@ -74,7 +72,7 @@ async def test_console_log_cached_message_after_refresh(
# Track all received log.entryAdded events in the events array
events = []

async def on_event(method, data):
async def on_event(_, data):
events.append(data)

remove_listener = bidi_session.add_event_listener("log.entryAdded", on_event)
Expand Down
5 changes: 1 addition & 4 deletions webdriver/tests/bidi/log/entry_added/javascript.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import math
import time

import pytest

from . import assert_javascript_entry, create_log
Expand All @@ -9,7 +6,7 @@

@pytest.mark.asyncio
async def test_types_and_values(
bidi_session, current_time, inline, top_context, wait_for_event
bidi_session, current_time, top_context, wait_for_event
):
await bidi_session.session.subscribe(events=["log.entryAdded"])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ async def test_request_headers(
):
text_url = url(PAGE_EMPTY_TEXT)


network_events = await setup_network_test(events=["network.beforeRequestSent"])
events = network_events["network.beforeRequestSent"]

Expand All @@ -153,7 +152,6 @@ async def test_request_cookies(
):
text_url = url(PAGE_EMPTY_TEXT)


network_events = await setup_network_test(events=["network.beforeRequestSent"])
events = network_events["network.beforeRequestSent"]

Expand Down Expand Up @@ -213,7 +211,6 @@ async def test_redirect(bidi_session, wait_for_event, url, fetch, setup_network_
f"/webdriver/tests/support/http_handlers/redirect.py?location={text_url}"
)


network_events = await setup_network_test(events=["network.beforeRequestSent"])
events = network_events["network.beforeRequestSent"]

Expand Down Expand Up @@ -248,7 +245,6 @@ async def test_redirect_http_equiv(
http_equiv_url = url(PAGE_REDIRECT_HTTP_EQUIV)
redirected_url = url(PAGE_REDIRECTED_HTML)


network_events = await setup_network_test(events=["network.beforeRequestSent"])
events = network_events["network.beforeRequestSent"]

Expand Down
4 changes: 1 addition & 3 deletions webdriver/tests/bidi/network/combined/network_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@


@pytest.mark.asyncio
async def test_same_request_id(
bidi_session, top_context, wait_for_event, url, setup_network_test, fetch
):
async def test_same_request_id(wait_for_event, url, setup_network_test, fetch):
network_events = await setup_network_test(
events=[
"network.beforeRequestSent",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import asyncio
import json
from urllib.parse import quote

import pytest

from webdriver.bidi.modules.script import ContextTarget

from tests.support.sync import AsyncPoll

from ... import any_int
from .. import assert_response_event, HTTP_STATUS_AND_STATUS_TEXT

PAGE_EMPTY_HTML = "/webdriver/tests/bidi/network/support/empty.html"
Expand All @@ -27,7 +23,7 @@ async def test_subscribe_status(bidi_session, top_context, wait_for_event, url,
# Track all received network.responseCompleted events in the events array
events = []

async def on_event(method, data):
async def on_event(_, data):
events.append(data)

remove_listener = bidi_session.add_event_listener(
Expand Down Expand Up @@ -93,7 +89,7 @@ async def on_event(method, data):

@pytest.mark.asyncio
async def test_load_page_twice(
bidi_session, top_context, wait_for_event, url, fetch, setup_network_test
bidi_session, top_context, wait_for_event, url, setup_network_test
):
html_url = url(PAGE_EMPTY_HTML)

Expand Down Expand Up @@ -132,7 +128,7 @@ async def test_load_page_twice(
)
@pytest.mark.asyncio
async def test_response_status(
bidi_session, wait_for_event, url, fetch, setup_network_test, status, status_text
wait_for_event, url, fetch, setup_network_test, status, status_text
):
status_url = url(
f"/webdriver/tests/support/http_handlers/status.py?status={status}&nocache={RESPONSE_COMPLETED_EVENT}"
Expand Down Expand Up @@ -164,7 +160,7 @@ async def test_response_status(

@pytest.mark.asyncio
async def test_response_headers(
bidi_session, wait_for_event, url, fetch, setup_network_test
wait_for_event, url, fetch, setup_network_test
):
headers_url = url(
"/webdriver/tests/support/http_handlers/headers.py?header=foo:bar&header=baz:biz"
Expand Down Expand Up @@ -211,7 +207,7 @@ async def test_response_headers(
)
@pytest.mark.asyncio
async def test_response_mime_type_file(
bidi_session, url, wait_for_event, fetch, setup_network_test, page_url, mime_type
url, wait_for_event, fetch, setup_network_test, page_url, mime_type
):
network_events = await setup_network_test(events=[RESPONSE_COMPLETED_EVENT])
events = network_events[RESPONSE_COMPLETED_EVENT]
Expand All @@ -233,7 +229,7 @@ async def test_response_mime_type_file(


@pytest.mark.asyncio
async def test_redirect(bidi_session, wait_for_event, url, fetch, setup_network_test):
async def test_redirect(bidi_session, url, fetch, setup_network_test):
text_url = url(PAGE_EMPTY_TEXT)
redirect_url = url(
f"/webdriver/tests/support/http_handlers/redirect.py?location={text_url}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

@pytest.mark.asyncio
async def test_cached(
bidi_session,
top_context,
wait_for_event,
url,
fetch,
Expand Down Expand Up @@ -69,8 +67,6 @@ async def test_cached(
@pytest.mark.asyncio
async def test_cached_redirect(
bidi_session,
top_context,
wait_for_event,
url,
fetch,
setup_network_test,
Expand Down Expand Up @@ -144,7 +140,7 @@ async def test_cached_redirect(

@pytest.mark.asyncio
async def test_cached_revalidate(
bidi_session, top_context, wait_for_event, url, fetch, setup_network_test
bidi_session, wait_for_event, url, fetch, setup_network_test
):
network_events = await setup_network_test(
events=[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import asyncio
import json

import pytest

from webdriver.bidi.modules.script import ContextTarget

from tests.support.sync import AsyncPoll

from ... import any_int
from .. import assert_response_event, HTTP_STATUS_AND_STATUS_TEXT

PAGE_EMPTY_HTML = "/webdriver/tests/bidi/network/support/empty.html"
Expand All @@ -32,7 +30,7 @@ async def test_subscribe_status(bidi_session, top_context, wait_for_event, url,
# Track all received network.responseStarted events in the events array
events = []

async def on_event(method, data):
async def on_event(_, data):
events.append(data)

remove_listener = bidi_session.add_event_listener(
Expand Down Expand Up @@ -73,7 +71,7 @@ async def on_event(method, data):

@pytest.mark.asyncio
async def test_load_page_twice(
bidi_session, top_context, wait_for_event, url, fetch, setup_network_test
bidi_session, top_context, wait_for_event, url, setup_network_test
):
html_url = url(PAGE_EMPTY_HTML)

Expand Down Expand Up @@ -112,7 +110,7 @@ async def test_load_page_twice(
)
@pytest.mark.asyncio
async def test_response_status(
bidi_session, wait_for_event, url, fetch, setup_network_test, status, status_text
wait_for_event, url, fetch, setup_network_test, status, status_text
):
status_url = url(f"/webdriver/tests/support/http_handlers/status.py?status={status}&nocache={RESPONSE_STARTED_EVENT}")

Expand Down Expand Up @@ -142,7 +140,7 @@ async def test_response_status(

@pytest.mark.asyncio
async def test_response_headers(
bidi_session, wait_for_event, url, fetch, setup_network_test
wait_for_event, url, fetch, setup_network_test
):
headers_url = url(
"/webdriver/tests/support/http_handlers/headers.py?header=foo:bar&header=baz:biz"
Expand Down Expand Up @@ -189,7 +187,7 @@ async def test_response_headers(
)
@pytest.mark.asyncio
async def test_response_mime_type_file(
bidi_session, url, wait_for_event, fetch, setup_network_test, page_url, mime_type
url, wait_for_event, fetch, setup_network_test, page_url, mime_type
):
network_events = await setup_network_test(events=[RESPONSE_STARTED_EVENT])
events = network_events[RESPONSE_STARTED_EVENT]
Expand All @@ -211,7 +209,7 @@ async def test_response_mime_type_file(


@pytest.mark.asyncio
async def test_redirect(bidi_session, wait_for_event, url, fetch, setup_network_test):
async def test_redirect(bidi_session, url, fetch, setup_network_test):
text_url = url(PAGE_EMPTY_TEXT)
redirect_url = url(f"/webdriver/tests/support/http_handlers/redirect.py?location={text_url}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

@pytest.mark.asyncio
async def test_cached(
bidi_session,
top_context,
wait_for_event,
url,
fetch,
Expand Down Expand Up @@ -69,8 +67,6 @@ async def test_cached(
@pytest.mark.asyncio
async def test_cached_redirect(
bidi_session,
top_context,
wait_for_event,
url,
fetch,
setup_network_test,
Expand Down Expand Up @@ -152,7 +148,7 @@ async def test_cached_redirect(
)
@pytest.mark.asyncio
async def test_cached_revalidate(
bidi_session, top_context, wait_for_event, url, fetch, setup_network_test, method
wait_for_event, url, fetch, setup_network_test, method
):
network_events = await setup_network_test(
events=[
Expand Down
Loading

0 comments on commit ff6a3b2

Please sign in to comment.