Skip to content

Commit 8a499b2

Browse files
committed
Replace flake8, isort with ruff
1 parent 56c181e commit 8a499b2

25 files changed

+231
-183
lines changed

Makefile

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
.PHONY: docs test clean isort
1+
.PHONY: docs test clean fix
22

33
test:
44
tox -e py311-dj42-sqlite_file
55

66
docs:
77
tox -e docs
88

9-
# See setup.cfg for configuration.
10-
isort:
11-
isort pytest_django pytest_django_test tests
9+
fix:
10+
ruff check --fix pytest_django pytest_django_test tests
1211

1312
clean:
1413
rm -rf bin include/ lib/ man/ pytest_django.egg-info/ build/

docs/conf.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import datetime
12
import os
23
import sys
3-
import datetime
4+
45

56
# If extensions (or modules to document with autodoc) are in another directory,
67
# add these directories to sys.path here. If the directory is relative to the
@@ -27,7 +28,7 @@
2728

2829
# General information about the project.
2930
project = 'pytest-django'
30-
copyright = f'{datetime.date.today().year}, Andreas Pelme and contributors'
31+
copyright = f'{datetime.datetime.now(tz=datetime.timezone.utc).year}, Andreas Pelme and contributors'
3132

3233
exclude_patterns = ['_build']
3334

pyproject.toml

+39-8
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,46 @@ exclude_lines = [
5454
"if TYPE_CHECKING:",
5555
]
5656

57-
[tool.isort]
58-
forced_separate = [
57+
[tool.ruff]
58+
target-version = "py38"
59+
line-length = 99
60+
extend-exclude = [
61+
"pytest_django/_version.py",
62+
]
63+
64+
[tool.ruff.lint]
65+
extend-select = [
66+
"B", # flake8-bugbear
67+
"BLE", # flake8-blind-except
68+
"DTZ", # flake8-datetimez
69+
"FA", # flake8-future-annotations
70+
"G", # flake8-logging-format
71+
"I", # isort
72+
"PGH", # pygrep-hooks
73+
"PIE", # flake8-pie
74+
"PL", # pylint
75+
"PT", # flake8-pytest-style
76+
"PYI", # flake8-pyi
77+
"RUF", # Ruff-specific rules
78+
"SLOT", # flake8-slots
79+
"T10", # flake8-debugger
80+
"UP", # pyupgrade
81+
"YTT", # flake8-2020
82+
]
83+
ignore = [
84+
"PLR0913", # Too many arguments in function definition
85+
"PLR2004", # Magic value used in comparison, consider replacing 3 with a constant variable
86+
"PT001", # Use `@pytest.fixture()` over `@pytest.fixture`
87+
"PT004", # Fixture `fixture_with_db` does not return anything, add leading underscore
88+
"PT023", # Use `@pytest.mark.django_db()` over `@pytest.mark.django_db`
89+
]
90+
91+
[tool.ruff.isort]
92+
forced-separate = [
5993
"tests",
6094
"pytest_django",
6195
"pytest_django_test",
6296
]
63-
combine_as_imports = true
64-
include_trailing_comma = true
65-
line_length = 79
66-
multi_line_output = 5
67-
lines_after_imports = 2
68-
extend_skip = ["pytest_django/_version.py"]
97+
combine-as-imports = true
98+
split-on-trailing-comma = false
99+
lines-after-imports = 2

pytest_django/asserts.py

+27-29
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
"""
22
Dynamically load all Django assertion cases and expose them for importing.
33
"""
4+
from __future__ import annotations
5+
46
from functools import wraps
5-
from typing import (
6-
TYPE_CHECKING, Any, Callable, Optional, Sequence, Set, Type, Union,
7-
)
7+
from typing import TYPE_CHECKING, Any, Callable, Sequence
88

9-
from django.test import (
10-
LiveServerTestCase, SimpleTestCase, TestCase, TransactionTestCase,
11-
)
9+
from django.test import LiveServerTestCase, SimpleTestCase, TestCase, TransactionTestCase
1210

1311

1412
test_case = TestCase("run")
@@ -25,7 +23,7 @@ def assertion_func(*args, **kwargs):
2523

2624

2725
__all__ = []
28-
assertions_names: Set[str] = set()
26+
assertions_names: set[str] = set()
2927
assertions_names.update(
3028
{attr for attr in vars(TestCase) if attr.startswith("assert")},
3129
{attr for attr in vars(SimpleTestCase) if attr.startswith("assert")},
@@ -35,7 +33,7 @@ def assertion_func(*args, **kwargs):
3533

3634
for assert_func in assertions_names:
3735
globals()[assert_func] = _wrapper(assert_func)
38-
__all__.append(assert_func)
36+
__all__.append(assert_func) # noqa: PYI056
3937

4038

4139
if TYPE_CHECKING:
@@ -61,7 +59,7 @@ def assertURLEqual(
6159
def assertContains(
6260
response: HttpResponseBase,
6361
text: object,
64-
count: Optional[int] = ...,
62+
count: int | None = ...,
6563
status_code: int = ...,
6664
msg_prefix: str = ...,
6765
html: bool = False,
@@ -80,39 +78,39 @@ def assertNotContains(
8078
def assertFormError(
8179
response: HttpResponseBase,
8280
form: str,
83-
field: Optional[str],
84-
errors: Union[str, Sequence[str]],
81+
field: str | None,
82+
errors: str | Sequence[str],
8583
msg_prefix: str = ...,
8684
) -> None:
8785
...
8886

8987
def assertFormsetError(
9088
response: HttpResponseBase,
9189
formset: str,
92-
form_index: Optional[int],
93-
field: Optional[str],
94-
errors: Union[str, Sequence[str]],
90+
form_index: int | None,
91+
field: str | None,
92+
errors: str | Sequence[str],
9593
msg_prefix: str = ...,
9694
) -> None:
9795
...
9896

9997
def assertTemplateUsed(
100-
response: Optional[Union[HttpResponseBase, str]] = ...,
101-
template_name: Optional[str] = ...,
98+
response: HttpResponseBase | str | None = ...,
99+
template_name: str | None = ...,
102100
msg_prefix: str = ...,
103-
count: Optional[int] = ...,
101+
count: int | None = ...,
104102
):
105103
...
106104

107105
def assertTemplateNotUsed(
108-
response: Optional[Union[HttpResponseBase, str]] = ...,
109-
template_name: Optional[str] = ...,
106+
response: HttpResponseBase | str | None = ...,
107+
template_name: str | None = ...,
110108
msg_prefix: str = ...,
111109
):
112110
...
113111

114112
def assertRaisesMessage(
115-
expected_exception: Type[Exception],
113+
expected_exception: type[Exception],
116114
expected_message: str,
117115
*args,
118116
**kwargs
@@ -140,50 +138,50 @@ def assertFieldOutput(
140138
def assertHTMLEqual(
141139
html1: str,
142140
html2: str,
143-
msg: Optional[str] = ...,
141+
msg: str | None = ...,
144142
) -> None:
145143
...
146144

147145
def assertHTMLNotEqual(
148146
html1: str,
149147
html2: str,
150-
msg: Optional[str] = ...,
148+
msg: str | None = ...,
151149
) -> None:
152150
...
153151

154152
def assertInHTML(
155153
needle: str,
156154
haystack: str,
157-
count: Optional[int] = ...,
155+
count: int | None = ...,
158156
msg_prefix: str = ...,
159157
) -> None:
160158
...
161159

162160
def assertJSONEqual(
163161
raw: str,
164162
expected_data: Any,
165-
msg: Optional[str] = ...,
163+
msg: str | None = ...,
166164
) -> None:
167165
...
168166

169167
def assertJSONNotEqual(
170168
raw: str,
171169
expected_data: Any,
172-
msg: Optional[str] = ...,
170+
msg: str | None = ...,
173171
) -> None:
174172
...
175173

176174
def assertXMLEqual(
177175
xml1: str,
178176
xml2: str,
179-
msg: Optional[str] = ...,
177+
msg: str | None = ...,
180178
) -> None:
181179
...
182180

183181
def assertXMLNotEqual(
184182
xml1: str,
185183
xml2: str,
186-
msg: Optional[str] = ...,
184+
msg: str | None = ...,
187185
) -> None:
188186
...
189187

@@ -193,7 +191,7 @@ def assertQuerysetEqual(
193191
values,
194192
transform=...,
195193
ordered: bool = ...,
196-
msg: Optional[str] = ...,
194+
msg: str | None = ...,
197195
) -> None:
198196
...
199197

@@ -202,7 +200,7 @@ def assertQuerySetEqual(
202200
values,
203201
transform=...,
204202
ordered: bool = ...,
205-
msg: Optional[str] = ...,
203+
msg: str | None = ...,
206204
) -> None:
207205
...
208206

0 commit comments

Comments
 (0)