Skip to content

Commit c25728f

Browse files
authored
Add more linting (#48)
1 parent d4d5b9d commit c25728f

File tree

6 files changed

+25
-48
lines changed

6 files changed

+25
-48
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ repos:
3535
- id: black
3636

3737
- repo: https://github.com/charliermarsh/ruff-pre-commit
38-
rev: v0.0.206
38+
rev: v0.0.237
3939
hooks:
4040
- id: ruff
4141
args: ["--fix"]

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# -- Project information -----------------------------------------------------
1919

2020
project = "pytest-jupyter"
21-
copyright = "2020, Project Jupyter"
21+
copyright = "2020, Project Jupyter" # noqa
2222
author = "Project Jupyter"
2323

2424

pyproject.toml

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ test = "mypy --install-types --non-interactive {args:.}"
9797
dependencies = [
9898
"black[jupyter]==22.12.0",
9999
"mdformat>0.7",
100-
"ruff==0.0.206",
100+
"ruff==0.0.237",
101101
]
102102
detached = true
103103
[tool.hatch.envs.lint.scripts]
@@ -165,38 +165,19 @@ target-version = ["py38"]
165165
target-version = "py38"
166166
line-length = 100
167167
select = [
168-
"A", "B", "C", "E", "EM", "F", "FBT", "I", "N", "Q", "RUF", "S", "T",
169-
"UP", "W", "YTT",
168+
"A", "B", "C", "DTZ", "E", "EM", "F", "FBT", "I", "ICN", "ISC", "N",
169+
"PLC", "PLE", "PLR", "PLW", "Q", "RUF", "S", "SIM", "T", "TID", "UP",
170+
"W", "YTT",
170171
]
171172
ignore = [
172-
# Allow non-abstract empty methods in abstract base classes
173-
"B027",
174-
# Ignore McCabe complexity
175-
"C901",
176-
# Allow boolean positional values in function calls, like `dict.get(... True)`
177-
"FBT003",
178-
# Use of `assert` detected
179-
"S101",
180-
# Line too long
181-
"E501",
182-
# Relative imports are banned
183-
"I252",
184-
# Boolean ... in function definition
185-
"FBT001",
186-
"FBT002",
187-
# Module level import not at top of file
188-
"E402",
189-
# A001/A002/A003 .. is shadowing a python builtin
190-
"A001",
191-
"A002",
192-
"A003",
193-
# Possible hardcoded password
194-
"S105",
195-
"S106",
196-
# Q000 Single quotes found but double quotes preferred
197-
"Q000",
198-
# N806 Variable `B` in function should be lowercase
199-
"N806",
173+
# Q000 Single quotes found but double quotes preferred
174+
"Q000",
175+
# FBT001 Boolean positional arg in function definition
176+
"FBT001", "FBT002", "FBT003",
177+
# E501 Line too long (158 > 100 characters)
178+
"E501",
179+
# SIM105 Use `contextlib.suppress(...)`
180+
"SIM105",
200181
]
201182
unfixable = [
202183
# Don't touch print statements
@@ -213,7 +194,8 @@ unfixable = [
213194
# T201 `print` found
214195
# B007 Loop control variable `i` not used within the loop body.
215196
# N802 Function name `assertIn` should be lowercase
216-
"tests/*" = ["B011", "F841", "C408", "E402", "T201", "B007", "N802"]
197+
# S101 Use of `assert` detected
198+
"tests/*" = ["B011", "F841", "C408", "E402", "T201", "B007", "N802", "S101"]
217199

218200
[tool.interrogate]
219201
ignore-init-module=true

pytest_jupyter/jupyter_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ async def inner(kernel_name=NATIVE_KERNEL_NAME, **kwargs):
5353

5454
for km in kms:
5555
jp_asyncio_loop.run_until_complete(km.shutdown_kernel(now=True))
56-
assert km.context.closed
56+
if not km.context.closed:
57+
raise AssertionError

pytest_jupyter/jupyter_server.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from tornado.websocket import WebSocketHandler
3232
from traitlets.config import Config
3333

34-
is_v2 = version_info[0] == 2
34+
is_v2 = version_info[0] == 2 # noqa
3535

3636
except ImportError:
3737
Authorizer = object # type:ignore
@@ -405,10 +405,7 @@ def send_request(jp_fetch, jp_ws_fetch):
405405
"""Send to Jupyter Server and return response code."""
406406

407407
async def _(url, **fetch_kwargs):
408-
if url.endswith("channels") or "/websocket/" in url:
409-
fetch = jp_ws_fetch
410-
else:
411-
fetch = jp_fetch
408+
fetch = jp_ws_fetch if url.endswith("channels") or "/websocket/" in url else jp_fetch
412409

413410
try:
414411
r = await fetch(url, **fetch_kwargs, allow_nonstandard_methods=True)
@@ -494,10 +491,7 @@ def normalize_url(self, path):
494491
def is_authorized(self, handler, user, action, resource):
495492
"""Test if a request is authorized."""
496493
# Parse Request
497-
if isinstance(handler, WebSocketHandler):
498-
method = "WEBSOCKET"
499-
else:
500-
method = handler.request.method
494+
method = "WEBSOCKET" if isinstance(handler, WebSocketHandler) else handler.request.method
501495
url = self.normalize_url(handler.request.path)
502496

503497
# Map request parts to expected action and resource.
@@ -506,8 +500,8 @@ def is_authorized(self, handler, user, action, resource):
506500

507501
# Assert that authorization layer returns the
508502
# correct action + resource.
509-
assert action == expected_action
510-
assert resource == expected_resource
503+
if action != expected_action or resource != expected_resource:
504+
raise AssertionError
511505

512506
# Now, actually apply the authorization layer.
513507
return all(

tests/test_jupyter_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ def test_skip(jp_serverapp):
2020

2121
async def test_get_api_spec(jp_fetch):
2222
response = await jp_fetch("api", "spec.yaml", method="GET")
23-
assert response.code == 200
23+
assert response.code == 200 # noqa
2424

2525

2626
async def test_send_request(send_request):
2727
code = await send_request("api/spec.yaml", method="GET")
28-
assert code == 200
28+
assert code == 200 # noqa
2929

3030

3131
async def test_connection(jp_fetch, jp_ws_fetch, jp_http_port, jp_auth_header):

0 commit comments

Comments
 (0)