Skip to content

Commit

Permalink
chore: enforce no underscores in impl class params (#2223)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Jan 3, 2024
1 parent d943ab8 commit 23a225e
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 231 deletions.
80 changes: 39 additions & 41 deletions playwright/_impl/_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,45 +89,45 @@ def _not(self) -> "PageAssertions":
)

async def to_have_title(
self, title_or_reg_exp: Union[Pattern[str], str], timeout: float = None
self, titleOrRegExp: Union[Pattern[str], str], timeout: float = None
) -> None:
expected_values = to_expected_text_values(
[title_or_reg_exp], normalize_white_space=True
[titleOrRegExp], normalize_white_space=True
)
__tracebackhide__ = True
await self._expect_impl(
"to.have.title",
FrameExpectOptions(expectedText=expected_values, timeout=timeout),
title_or_reg_exp,
titleOrRegExp,
"Page title expected to be",
)

async def not_to_have_title(
self, title_or_reg_exp: Union[Pattern[str], str], timeout: float = None
self, titleOrRegExp: Union[Pattern[str], str], timeout: float = None
) -> None:
__tracebackhide__ = True
await self._not.to_have_title(title_or_reg_exp, timeout)
await self._not.to_have_title(titleOrRegExp, timeout)

async def to_have_url(
self, url_or_reg_exp: Union[str, Pattern[str]], timeout: float = None
self, urlOrRegExp: Union[str, Pattern[str]], timeout: float = None
) -> None:
__tracebackhide__ = True
base_url = self._actual_page.context._options.get("baseURL")
if isinstance(url_or_reg_exp, str) and base_url:
url_or_reg_exp = urljoin(base_url, url_or_reg_exp)
expected_text = to_expected_text_values([url_or_reg_exp])
if isinstance(urlOrRegExp, str) and base_url:
urlOrRegExp = urljoin(base_url, urlOrRegExp)
expected_text = to_expected_text_values([urlOrRegExp])
await self._expect_impl(
"to.have.url",
FrameExpectOptions(expectedText=expected_text, timeout=timeout),
url_or_reg_exp,
urlOrRegExp,
"Page URL expected to be",
)

async def not_to_have_url(
self, url_or_reg_exp: Union[Pattern[str], str], timeout: float = None
self, urlOrRegExp: Union[Pattern[str], str], timeout: float = None
) -> None:
__tracebackhide__ = True
await self._not.to_have_url(url_or_reg_exp, timeout)
await self._not.to_have_url(urlOrRegExp, timeout)


class LocatorAssertions(AssertionsBase):
Expand Down Expand Up @@ -156,9 +156,9 @@ async def to_contain_text(
Pattern[str],
str,
],
use_inner_text: bool = None,
useInnerText: bool = None,
timeout: float = None,
ignore_case: bool = None,
ignoreCase: bool = None,
) -> None:
__tracebackhide__ = True
if isinstance(expected, collections.abc.Sequence) and not isinstance(
Expand All @@ -168,13 +168,13 @@ async def to_contain_text(
expected,
match_substring=True,
normalize_white_space=True,
ignore_case=ignore_case,
ignoreCase=ignoreCase,
)
await self._expect_impl(
"to.contain.text.array",
FrameExpectOptions(
expectedText=expected_text,
useInnerText=use_inner_text,
useInnerText=useInnerText,
timeout=timeout,
),
expected,
Expand All @@ -185,13 +185,13 @@ async def to_contain_text(
[expected],
match_substring=True,
normalize_white_space=True,
ignore_case=ignore_case,
ignoreCase=ignoreCase,
)
await self._expect_impl(
"to.have.text",
FrameExpectOptions(
expectedText=expected_text,
useInnerText=use_inner_text,
useInnerText=useInnerText,
timeout=timeout,
),
expected,
Expand All @@ -207,22 +207,22 @@ async def not_to_contain_text(
Pattern[str],
str,
],
use_inner_text: bool = None,
useInnerText: bool = None,
timeout: float = None,
ignore_case: bool = None,
ignoreCase: bool = None,
) -> None:
__tracebackhide__ = True
await self._not.to_contain_text(expected, use_inner_text, timeout, ignore_case)
await self._not.to_contain_text(expected, useInnerText, timeout, ignoreCase)

async def to_have_attribute(
self,
name: str,
value: Union[str, Pattern[str]],
ignore_case: bool = None,
ignoreCase: bool = None,
timeout: float = None,
) -> None:
__tracebackhide__ = True
expected_text = to_expected_text_values([value], ignore_case=ignore_case)
expected_text = to_expected_text_values([value], ignoreCase=ignoreCase)
await self._expect_impl(
"to.have.attribute.value",
FrameExpectOptions(
Expand All @@ -236,12 +236,12 @@ async def not_to_have_attribute(
self,
name: str,
value: Union[str, Pattern[str]],
ignore_case: bool = None,
ignoreCase: bool = None,
timeout: float = None,
) -> None:
__tracebackhide__ = True
await self._not.to_have_attribute(
name, value, ignore_case=ignore_case, timeout=timeout
name, value, ignoreCase=ignoreCase, timeout=timeout
)

async def to_have_class(
Expand Down Expand Up @@ -440,9 +440,9 @@ async def to_have_text(
Pattern[str],
str,
],
use_inner_text: bool = None,
useInnerText: bool = None,
timeout: float = None,
ignore_case: bool = None,
ignoreCase: bool = None,
) -> None:
__tracebackhide__ = True
if isinstance(expected, collections.abc.Sequence) and not isinstance(
Expand All @@ -451,27 +451,27 @@ async def to_have_text(
expected_text = to_expected_text_values(
expected,
normalize_white_space=True,
ignore_case=ignore_case,
ignoreCase=ignoreCase,
)
await self._expect_impl(
"to.have.text.array",
FrameExpectOptions(
expectedText=expected_text,
useInnerText=use_inner_text,
useInnerText=useInnerText,
timeout=timeout,
),
expected,
"Locator expected to have text",
)
else:
expected_text = to_expected_text_values(
[expected], normalize_white_space=True, ignore_case=ignore_case
[expected], normalize_white_space=True, ignoreCase=ignoreCase
)
await self._expect_impl(
"to.have.text",
FrameExpectOptions(
expectedText=expected_text,
useInnerText=use_inner_text,
useInnerText=useInnerText,
timeout=timeout,
),
expected,
Expand All @@ -487,12 +487,12 @@ async def not_to_have_text(
Pattern[str],
str,
],
use_inner_text: bool = None,
useInnerText: bool = None,
timeout: float = None,
ignore_case: bool = None,
ignoreCase: bool = None,
) -> None:
__tracebackhide__ = True
await self._not.to_have_text(expected, use_inner_text, timeout, ignore_case)
await self._not.to_have_text(expected, useInnerText, timeout, ignoreCase)

async def to_be_attached(
self,
Expand Down Expand Up @@ -754,14 +754,14 @@ def expected_regex(
pattern: Pattern[str],
match_substring: bool,
normalize_white_space: bool,
ignore_case: Optional[bool] = None,
ignoreCase: Optional[bool] = None,
) -> ExpectedTextValue:
expected = ExpectedTextValue(
regexSource=pattern.pattern,
regexFlags=escape_regex_flags(pattern),
matchSubstring=match_substring,
normalizeWhiteSpace=normalize_white_space,
ignoreCase=ignore_case,
ignoreCase=ignoreCase,
)
if expected["ignoreCase"] is None:
del expected["ignoreCase"]
Expand All @@ -774,7 +774,7 @@ def to_expected_text_values(
],
match_substring: bool = False,
normalize_white_space: bool = False,
ignore_case: Optional[bool] = None,
ignoreCase: Optional[bool] = None,
) -> Sequence[ExpectedTextValue]:
out: List[ExpectedTextValue] = []
assert isinstance(items, list)
Expand All @@ -784,15 +784,13 @@ def to_expected_text_values(
string=item,
matchSubstring=match_substring,
normalizeWhiteSpace=normalize_white_space,
ignoreCase=ignore_case,
ignoreCase=ignoreCase,
)
if o["ignoreCase"] is None:
del o["ignoreCase"]
out.append(o)
elif isinstance(item, Pattern):
out.append(
expected_regex(
item, match_substring, normalize_white_space, ignore_case
)
expected_regex(item, match_substring, normalize_white_space, ignoreCase)
)
return out
12 changes: 6 additions & 6 deletions playwright/_impl/_browser_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,24 +399,24 @@ async def route_from_har(
self,
har: Union[Path, str],
url: Union[Pattern[str], str] = None,
not_found: RouteFromHarNotFoundPolicy = None,
notFound: RouteFromHarNotFoundPolicy = None,
update: bool = None,
update_content: Literal["attach", "embed"] = None,
update_mode: HarMode = None,
updateContent: Literal["attach", "embed"] = None,
updateMode: HarMode = None,
) -> None:
if update:
await self._record_into_har(
har=har,
page=None,
url=url,
update_content=update_content,
update_mode=update_mode,
update_content=updateContent,
update_mode=updateMode,
)
return
router = await HarRouter.create(
local_utils=self._connection.local_utils,
file=str(har),
not_found_action=not_found or "abort",
not_found_action=notFound or "abort",
url_matcher=url,
)
await router.add_context_route(self)
Expand Down
16 changes: 8 additions & 8 deletions playwright/_impl/_browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,28 +183,28 @@ async def connect_over_cdp(

async def connect(
self,
ws_endpoint: str,
wsEndpoint: str,
timeout: float = None,
slow_mo: float = None,
slowMo: float = None,
headers: Dict[str, str] = None,
expose_network: str = None,
exposeNetwork: str = None,
) -> Browser:
if timeout is None:
timeout = 30000
if slow_mo is None:
slow_mo = 0
if slowMo is None:
slowMo = 0

headers = {**(headers if headers else {}), "x-playwright-browser": self.name}
local_utils = self._connection.local_utils
pipe_channel = (
await local_utils._channel.send_return_as_dict(
"connect",
{
"wsEndpoint": ws_endpoint,
"wsEndpoint": wsEndpoint,
"headers": headers,
"slowMo": slow_mo,
"slowMo": slowMo,
"timeout": timeout,
"exposeNetwork": expose_network,
"exposeNetwork": exposeNetwork,
},
)
)["pipe"]
Expand Down
30 changes: 15 additions & 15 deletions playwright/_impl/_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,20 @@ def _setup_navigation_waiter(self, wait_name: str, timeout: float = None) -> Wai
def expect_navigation(
self,
url: URLMatch = None,
wait_until: DocumentLoadState = None,
waitUntil: DocumentLoadState = None,
timeout: float = None,
) -> EventContextManagerImpl[Response]:
assert self._page
if not wait_until:
wait_until = "load"
if not waitUntil:
waitUntil = "load"

if timeout is None:
timeout = self._page._timeout_settings.navigation_timeout()
deadline = monotonic_time() + timeout
waiter = self._setup_navigation_waiter("expect_navigation", timeout)

to_url = f' to "{url}"' if url else ""
waiter.log(f"waiting for navigation{to_url} until '{wait_until}'")
waiter.log(f"waiting for navigation{to_url} until '{waitUntil}'")
matcher = (
URLMatcher(self._page._browser_context._options.get("baseURL"), url)
if url
Expand All @@ -212,10 +212,10 @@ async def continuation() -> Optional[Response]:
event = await waiter.result()
if "error" in event:
raise Error(event["error"])
if wait_until not in self._load_states:
if waitUntil not in self._load_states:
t = deadline - monotonic_time()
if t > 0:
await self._wait_for_load_state_impl(state=wait_until, timeout=t)
await self._wait_for_load_state_impl(state=waitUntil, timeout=t)
if "newDocument" in event and "request" in event["newDocument"]:
request = from_channel(event["newDocument"]["request"])
return await request.response()
Expand All @@ -226,16 +226,16 @@ async def continuation() -> Optional[Response]:
async def wait_for_url(
self,
url: URLMatch,
wait_until: DocumentLoadState = None,
waitUntil: DocumentLoadState = None,
timeout: float = None,
) -> None:
assert self._page
matcher = URLMatcher(self._page._browser_context._options.get("baseURL"), url)
if matcher.matches(self.url):
await self._wait_for_load_state_impl(state=wait_until, timeout=timeout)
await self._wait_for_load_state_impl(state=waitUntil, timeout=timeout)
return
async with self.expect_navigation(
url=url, wait_until=wait_until, timeout=timeout
url=url, waitUntil=waitUntil, timeout=timeout
):
pass

Expand Down Expand Up @@ -535,18 +535,18 @@ async def fill(
def locator(
self,
selector: str,
has_text: Union[str, Pattern[str]] = None,
has_not_text: Union[str, Pattern[str]] = None,
hasText: Union[str, Pattern[str]] = None,
hasNotText: Union[str, Pattern[str]] = None,
has: Locator = None,
has_not: Locator = None,
hasNot: Locator = None,
) -> Locator:
return Locator(
self,
selector,
has_text=has_text,
has_not_text=has_not_text,
has_text=hasText,
has_not_text=hasNotText,
has=has,
has_not=has_not,
has_not=hasNot,
)

def get_by_alt_text(
Expand Down
Loading

0 comments on commit 23a225e

Please sign in to comment.