Skip to content

Commit

Permalink
Replace flake8, isort with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
bluetech committed Oct 30, 2023
1 parent 56c181e commit 8a499b2
Show file tree
Hide file tree
Showing 25 changed files with 231 additions and 183 deletions.
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
.PHONY: docs test clean isort
.PHONY: docs test clean fix

test:
tox -e py311-dj42-sqlite_file

docs:
tox -e docs

# See setup.cfg for configuration.
isort:
isort pytest_django pytest_django_test tests
fix:
ruff check --fix pytest_django pytest_django_test tests

clean:
rm -rf bin include/ lib/ man/ pytest_django.egg-info/ build/
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import os
import sys
import datetime


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

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

exclude_patterns = ['_build']

Expand Down
47 changes: 39 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,46 @@ exclude_lines = [
"if TYPE_CHECKING:",
]

[tool.isort]
forced_separate = [
[tool.ruff]
target-version = "py38"
line-length = 99
extend-exclude = [
"pytest_django/_version.py",
]

[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear
"BLE", # flake8-blind-except
"DTZ", # flake8-datetimez
"FA", # flake8-future-annotations
"G", # flake8-logging-format
"I", # isort
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"PYI", # flake8-pyi
"RUF", # Ruff-specific rules
"SLOT", # flake8-slots
"T10", # flake8-debugger
"UP", # pyupgrade
"YTT", # flake8-2020
]
ignore = [
"PLR0913", # Too many arguments in function definition
"PLR2004", # Magic value used in comparison, consider replacing 3 with a constant variable
"PT001", # Use `@pytest.fixture()` over `@pytest.fixture`
"PT004", # Fixture `fixture_with_db` does not return anything, add leading underscore
"PT023", # Use `@pytest.mark.django_db()` over `@pytest.mark.django_db`
]

[tool.ruff.isort]
forced-separate = [
"tests",
"pytest_django",
"pytest_django_test",
]
combine_as_imports = true
include_trailing_comma = true
line_length = 79
multi_line_output = 5
lines_after_imports = 2
extend_skip = ["pytest_django/_version.py"]
combine-as-imports = true
split-on-trailing-comma = false
lines-after-imports = 2
56 changes: 27 additions & 29 deletions pytest_django/asserts.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"""
Dynamically load all Django assertion cases and expose them for importing.
"""
from __future__ import annotations

from functools import wraps
from typing import (
TYPE_CHECKING, Any, Callable, Optional, Sequence, Set, Type, Union,
)
from typing import TYPE_CHECKING, Any, Callable, Sequence

from django.test import (
LiveServerTestCase, SimpleTestCase, TestCase, TransactionTestCase,
)
from django.test import LiveServerTestCase, SimpleTestCase, TestCase, TransactionTestCase


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


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

for assert_func in assertions_names:
globals()[assert_func] = _wrapper(assert_func)
__all__.append(assert_func)
__all__.append(assert_func) # noqa: PYI056


if TYPE_CHECKING:
Expand All @@ -61,7 +59,7 @@ def assertURLEqual(
def assertContains(
response: HttpResponseBase,
text: object,
count: Optional[int] = ...,
count: int | None = ...,
status_code: int = ...,
msg_prefix: str = ...,
html: bool = False,
Expand All @@ -80,39 +78,39 @@ def assertNotContains(
def assertFormError(
response: HttpResponseBase,
form: str,
field: Optional[str],
errors: Union[str, Sequence[str]],
field: str | None,
errors: str | Sequence[str],
msg_prefix: str = ...,
) -> None:
...

def assertFormsetError(
response: HttpResponseBase,
formset: str,
form_index: Optional[int],
field: Optional[str],
errors: Union[str, Sequence[str]],
form_index: int | None,
field: str | None,
errors: str | Sequence[str],
msg_prefix: str = ...,
) -> None:
...

def assertTemplateUsed(
response: Optional[Union[HttpResponseBase, str]] = ...,
template_name: Optional[str] = ...,
response: HttpResponseBase | str | None = ...,
template_name: str | None = ...,
msg_prefix: str = ...,
count: Optional[int] = ...,
count: int | None = ...,
):
...

def assertTemplateNotUsed(
response: Optional[Union[HttpResponseBase, str]] = ...,
template_name: Optional[str] = ...,
response: HttpResponseBase | str | None = ...,
template_name: str | None = ...,
msg_prefix: str = ...,
):
...

def assertRaisesMessage(
expected_exception: Type[Exception],
expected_exception: type[Exception],
expected_message: str,
*args,
**kwargs
Expand Down Expand Up @@ -140,50 +138,50 @@ def assertFieldOutput(
def assertHTMLEqual(
html1: str,
html2: str,
msg: Optional[str] = ...,
msg: str | None = ...,
) -> None:
...

def assertHTMLNotEqual(
html1: str,
html2: str,
msg: Optional[str] = ...,
msg: str | None = ...,
) -> None:
...

def assertInHTML(
needle: str,
haystack: str,
count: Optional[int] = ...,
count: int | None = ...,
msg_prefix: str = ...,
) -> None:
...

def assertJSONEqual(
raw: str,
expected_data: Any,
msg: Optional[str] = ...,
msg: str | None = ...,
) -> None:
...

def assertJSONNotEqual(
raw: str,
expected_data: Any,
msg: Optional[str] = ...,
msg: str | None = ...,
) -> None:
...

def assertXMLEqual(
xml1: str,
xml2: str,
msg: Optional[str] = ...,
msg: str | None = ...,
) -> None:
...

def assertXMLNotEqual(
xml1: str,
xml2: str,
msg: Optional[str] = ...,
msg: str | None = ...,
) -> None:
...

Expand All @@ -193,7 +191,7 @@ def assertQuerysetEqual(
values,
transform=...,
ordered: bool = ...,
msg: Optional[str] = ...,
msg: str | None = ...,
) -> None:
...

Expand All @@ -202,7 +200,7 @@ def assertQuerySetEqual(
values,
transform=...,
ordered: bool = ...,
msg: Optional[str] = ...,
msg: str | None = ...,
) -> None:
...

Expand Down

0 comments on commit 8a499b2

Please sign in to comment.