Skip to content

Commit 5884ec1

Browse files
authored
devops: separated linting into own job (#48)
1 parent a0e1cd1 commit 5884ec1

17 files changed

+92
-85
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@ on:
55
pull_request:
66
branches: [ master ]
77
jobs:
8+
infra:
9+
name: Lint
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: microsoft/playwright-github-action@v1
14+
- name: Set up Python
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: 3.8
18+
- name: Install dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install -r local-requirements.txt
22+
pip install .
23+
- name: Lint
24+
run: |
25+
black --check .
26+
mypy .
27+
flake8 playwright tests
828
build:
929
timeout-minutes: 30
1030
strategy:
@@ -40,16 +60,17 @@ jobs:
4060
python -m pip install --upgrade pip
4161
pip install -r local-requirements.txt
4262
pip install .
43-
- name: Lint
44-
run: |
45-
black --check .
46-
mypy .
47-
flake8 playwright tests
4863
- name: Build driver
4964
run: python build_driver.py
5065
env:
5166
PKG_CACHE_PATH: ${{ steps.node-pkg-cache.outputs.dir }}
5267
- name: Build package
5368
run: python build_package.py
5469
- name: Test
70+
if: ${{ matrix.os == 'windows-latest' }}
71+
# pytest-xdist does not exit on Windows
72+
# https://github.com/pytest-dev/pytest-xdist/issues/60
5573
run: pytest -vv --browser=${{ matrix.browser }}
74+
- name: Test
75+
if: ${{ matrix.os != 'windows-latest' }}
76+
run: pytest -vv --browser=${{ matrix.browser }} -n auto

client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from playwright import browser_types
1818

1919

20-
async def run():
20+
async def run() -> None:
2121
print("Launching browser...")
2222
browser = await browser_types["webkit"].launch(headless=False)
2323
print("Contexts in browser: %d" % len(browser.contexts))
@@ -59,6 +59,7 @@ async def run():
5959

6060
print("\nQuerying body...")
6161
body1 = await page1.querySelector("body")
62+
assert body1
6263
print("Body text %s" % await body1.textContent())
6364

6465
print("Closing page1...")

playwright/browser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
from types import SimpleNamespace
2121
from typing import Dict, List, Union
2222

23-
if sys.version_info >= (3, 8):
23+
if sys.version_info >= (3, 8): # pragma: no cover
2424
from typing import Literal
25-
else:
25+
else: # pragma: no cover
2626
from typing_extensions import Literal
2727

2828

playwright/browser_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from types import SimpleNamespace
3535
from typing import Any, Callable, Dict, List, Optional, Union, TYPE_CHECKING
3636

37-
if TYPE_CHECKING:
37+
if TYPE_CHECKING: # pragma: no cover
3838
from playwright.browser import Browser
3939

4040

@@ -189,7 +189,7 @@ async def waitForEvent(
189189
self, self._timeout_settings, event, predicate=predicate, timeout=timeout
190190
)
191191

192-
def _on_close(self):
192+
def _on_close(self) -> None:
193193
if self._browser:
194194
self._browser._contexts.remove(self)
195195

playwright/connection.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ async def send(self, method: str, params: dict = None) -> Any:
3232
params = dict()
3333
return await self._scope.send_message_to_server(self._guid, method, params)
3434

35-
def _on_message(self, method: str, params: Dict):
36-
self.emit(method, params)
37-
3835

3936
class ChannelOwner(BaseEventEmitter):
4037
def __init__(
41-
self, scope: "ConnectionScope", guid: str, initializer: Dict, is_scope=False
38+
self,
39+
scope: "ConnectionScope",
40+
guid: str,
41+
initializer: Dict,
42+
is_scope: bool = False,
4243
) -> None:
4344
super().__init__()
4445
self._guid = guid
@@ -64,7 +65,7 @@ def create_child(self, guid: str) -> "ConnectionScope":
6465
self._children.append(scope)
6566
return scope
6667

67-
def dispose(self):
68+
def dispose(self) -> None:
6869
# Take care of hierarchy.
6970
for child in self._children:
7071
child.dispose()
@@ -98,7 +99,7 @@ def create_remote_object(self, type: str, guid: str, initializer: Dict) -> Any:
9899

99100

100101
class ProtocolCallback:
101-
def __init__(self, loop: asyncio.AbstractEventLoop):
102+
def __init__(self, loop: asyncio.AbstractEventLoop) -> None:
102103
self.stack_trace = "".join(traceback.format_stack()[-10:])
103104
self.future = loop.create_future()
104105

@@ -145,7 +146,7 @@ async def _send_message_to_server(
145146
self._callbacks[id] = callback
146147
return await callback.future
147148

148-
def _dispatch(self, msg: ParsedMessagePayload):
149+
def _dispatch(self, msg: ParsedMessagePayload) -> None:
149150

150151
id = msg.get("id")
151152
if id:

playwright/console_message.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,10 @@ def type(self) -> str:
3333
def text(self) -> str:
3434
return self._initializer["text"]
3535

36-
@property
37-
def defaultValue(self) -> str:
38-
return self._initializer["defaultValue"]
39-
4036
@property
4137
def args(self) -> List[JSHandle]:
4238
return list(map(from_channel, self._initializer["args"]))
4339

4440
@property
4541
def location(self) -> ConsoleMessageLocation:
4642
return self._initializer["location"]
47-
48-
async def accept(self, prompt_text: str = None) -> None:
49-
await self._channel.send("accept", dict(promptText=prompt_text))
50-
51-
async def dismiss(self) -> None:
52-
await self._channel.send("dismiss")

playwright/element_handle.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
cast,
3838
)
3939

40-
if sys.version_info >= (3, 8):
40+
if sys.version_info >= (3, 8): # pragma: no cover
4141
from typing import Literal
42-
else:
42+
else: # pragma: no cover
4343
from typing_extensions import Literal
4444

45-
if TYPE_CHECKING:
45+
if TYPE_CHECKING: # pragma: no cover
4646
from playwright.frame import Frame
4747

4848

playwright/file_chooser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from typing import List, Union, TYPE_CHECKING
1818

19-
if TYPE_CHECKING:
19+
if TYPE_CHECKING: # pragma: no cover
2020
from playwright.page import Page
2121
from playwright.element_handle import ElementHandle
2222

playwright/frame.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
from playwright.serializers import normalize_file_payloads
3939
from typing import Any, Awaitable, Dict, List, Optional, Union, TYPE_CHECKING, cast
4040

41-
if sys.version_info >= (3, 8):
41+
if sys.version_info >= (3, 8): # pragma: no cover
4242
from typing import Literal
43-
else:
43+
else: # pragma: no cover
4444
from typing_extensions import Literal
4545

46-
if TYPE_CHECKING:
46+
if TYPE_CHECKING: # pragma: no cover
4747
from playwright.page import Page
4848

4949

playwright/helper.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import fnmatch
1717
import re
1818
import traceback
19+
from types import TracebackType
1920

2021
from typing import (
2122
Any,
@@ -31,13 +32,13 @@
3132

3233
import sys
3334

34-
if sys.version_info >= (3, 8):
35+
if sys.version_info >= (3, 8): # pragma: no cover
3536
from typing import Literal, TypedDict
36-
else:
37+
else: # pragma: no cover
3738
from typing_extensions import Literal, TypedDict
3839

3940

40-
if TYPE_CHECKING:
41+
if TYPE_CHECKING: # pragma: no cover
4142
from playwright.network import Route, Request
4243

4344
Cookie = List[Dict[str, Union[str, int, bool]]]
@@ -98,7 +99,7 @@ class ParsedMessagePayload(TypedDict, total=False):
9899

99100

100101
class URLMatcher:
101-
def __init__(self, match: URLMatch):
102+
def __init__(self, match: URLMatch) -> None:
102103
self._callback: Optional[Callable[[str], bool]] = None
103104
self._regex_obj: Optional[Pattern] = None
104105
if isinstance(match, str):
@@ -124,7 +125,7 @@ def __init__(self, parent: Optional["TimeoutSettings"]) -> None:
124125
self._timeout = 30000
125126
self._navigation_timeout = 30000
126127

127-
def set_timeout(self, timeout: int):
128+
def set_timeout(self, timeout: int) -> None:
128129
self._timeout = timeout
129130

130131
def timeout(self) -> int:
@@ -134,7 +135,7 @@ def timeout(self) -> int:
134135
return self._parent.timeout()
135136
return 30000
136137

137-
def set_navigation_timeout(self, navigation_timeout: int):
138+
def set_navigation_timeout(self, navigation_timeout: int) -> None:
138139
self._navigation_timeout = navigation_timeout
139140

140141
def navigation_timeout(self) -> int:
@@ -155,7 +156,7 @@ class TimeoutError(Error):
155156
pass
156157

157158

158-
def serialize_error(ex: Exception, tb) -> ErrorPayload:
159+
def serialize_error(ex: Exception, tb: Optional[TracebackType]) -> ErrorPayload:
159160
return dict(message=str(ex), stack="".join(traceback.format_tb(tb)))
160161

161162

@@ -193,7 +194,7 @@ def __init__(
193194
self.future = future
194195
self.timeout_future = timeout_future
195196

196-
def reject(self, is_crash: bool, target: str):
197+
def reject(self, is_crash: bool, target: str) -> None:
197198
self.timeout_future.cancel()
198199
if self.event == "close" and not is_crash:
199200
return

0 commit comments

Comments
 (0)