Skip to content

Commit

Permalink
tox: update ruff, mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
bluetech committed Sep 2, 2024
1 parent a39b910 commit 30602a2
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 68 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ ignore = [
"PT023", # Use `@pytest.mark.django_db()` over `@pytest.mark.django_db`
]

[tool.ruff.isort]
[tool.ruff.lint.isort]
forced-separate = [
"tests",
"pytest_django",
Expand Down
70 changes: 24 additions & 46 deletions pytest_django/asserts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Dynamically load all Django assertion cases and expose them for importing.
"""

from __future__ import annotations

from functools import wraps
Expand Down Expand Up @@ -64,15 +65,13 @@ def assertRedirects(
target_status_code: int = ...,
msg_prefix: str = ...,
fetch_redirect_response: bool = ...,
) -> None:
...
) -> None: ...

def assertURLEqual(
url1: str,
url2: str,
msg_prefix: str = ...,
) -> None:
...
) -> None: ...

def assertContains(
response: HttpResponseBase,
Expand All @@ -81,65 +80,57 @@ def assertContains(
status_code: int = ...,
msg_prefix: str = ...,
html: bool = False,
) -> None:
...
) -> None: ...

def assertNotContains(
response: HttpResponseBase,
text: object,
status_code: int = ...,
msg_prefix: str = ...,
html: bool = False,
) -> None:
...
) -> None: ...

def assertFormError(
form: forms.BaseForm,
field: str | None,
errors: str | Sequence[str],
msg_prefix: str = ...,
) -> None:
...
) -> None: ...

def assertFormSetError(
formset: forms.BaseFormSet,
form_index: int | None,
field: str | None,
errors: str | Sequence[str],
msg_prefix: str = ...,
) -> None:
...
) -> None: ...

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

def assertTemplateNotUsed(
response: HttpResponseBase | str | None = ...,
template_name: str | None = ...,
msg_prefix: str = ...,
):
...
): ...

def assertRaisesMessage(
expected_exception: type[Exception],
expected_message: str,
*args,
**kwargs,
):
...
): ...

def assertWarnsMessage(
expected_warning: Warning,
expected_message: str,
*args,
**kwargs,
):
...
): ...

def assertFieldOutput(
fieldclass,
Expand All @@ -148,58 +139,50 @@ def assertFieldOutput(
field_args=...,
field_kwargs=...,
empty_value: str = ...,
) -> None:
...
) -> None: ...

def assertHTMLEqual(
html1: str,
html2: str,
msg: str | None = ...,
) -> None:
...
) -> None: ...

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

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

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

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

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

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

# Removed in Django 5.1: use assertQuerySetEqual.
def assertQuerysetEqual(
Expand All @@ -208,36 +191,31 @@ def assertQuerysetEqual(
transform=...,
ordered: bool = ...,
msg: str | None = ...,
) -> None:
...
) -> None: ...

def assertQuerySetEqual(
qs,
values,
transform=...,
ordered: bool = ...,
msg: str | None = ...,
) -> None:
...
) -> None: ...

def assertNumQueries(
num: int,
func=...,
*args,
using: str = ...,
**kwargs,
):
...
): ...

# Added in Django 5.0.
def assertMessages(
response: HttpResponseBase,
expected_messages: Sequence[Message],
*args,
ordered: bool = ...,
) -> None:
...
) -> None: ...

# Fallback in case Django adds new asserts.
def __getattr__(name: str) -> Callable[..., Any]:
...
def __getattr__(name: str) -> Callable[..., Any]: ...
1 change: 1 addition & 0 deletions pytest_django/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""All pytest-django fixtures"""

from __future__ import annotations

import os
Expand Down
1 change: 1 addition & 0 deletions pytest_django/lazy_django.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Helpers to load Django lazily when Django settings can't be configured.
"""

from __future__ import annotations

import os
Expand Down
1 change: 1 addition & 0 deletions pytest_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This plugin handles creating and destroying the test environment and
test database and provides some useful text fixtures.
"""

from __future__ import annotations

import contextlib
Expand Down
3 changes: 1 addition & 2 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ def create_test_module( # type: ignore[empty-body]
self,
test_code: str,
filename: str = ...,
) -> Path:
...
) -> Path: ...

def create_app_file(self, code: str, filename: str) -> Path: # type: ignore[empty-body]
...
1 change: 1 addition & 0 deletions tests/test_asserts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Tests the dynamic loading of all Django assertion cases.
"""

from __future__ import annotations

import inspect
Expand Down
1 change: 1 addition & 0 deletions tests/test_django_configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
If these tests fail you probably forgot to install django-configurations.
"""

import pytest


Expand Down
36 changes: 21 additions & 15 deletions tests/test_django_settings_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,32 +377,38 @@ def test_django_debug_mode_keep(
monkeypatch.delenv("DJANGO_SETTINGS_MODULE")
pytester.makeini(
"""
[pytest]
django_debug_mode = keep
"""
[pytest]
django_debug_mode = keep
"""
)
pytester.makeconftest(
"""
f"""
from django.conf import settings
def pytest_configure():
settings.configure(SECRET_KEY='set from pytest_configure',
DEBUG=%s,
DATABASES={'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:'}},
INSTALLED_APPS=['django.contrib.auth',
'django.contrib.contenttypes',])
"""
% settings_debug
settings.configure(
SECRET_KEY='set from pytest_configure',
DEBUG={settings_debug},
DATABASES={{
'default': {{
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}},
}},
INSTALLED_APPS=[
'django.contrib.auth',
'django.contrib.contenttypes',
],
)
"""
)

pytester.makepyfile(
f"""
from django.conf import settings
def test_debug_is_false():
assert settings.DEBUG is {settings_debug}
"""
"""
)

r = pytester.runpytest_subprocess()
Expand All @@ -414,7 +420,7 @@ def test_debug_is_false():
INSTALLED_APPS = [
'tpkg.app.apps.TestApp',
]
"""
"""
)
def test_django_setup_sequence(django_pytester) -> None:
django_pytester.create_app_file(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_for_invalid_template(client):
"""
)
def test_invalid_template_variable_behaves_normally_when_ignored(
django_pytester: DjangoPytester
django_pytester: DjangoPytester,
) -> None:
django_pytester.create_app_file(
"<div>{{ invalid_var }}</div>", "templates/invalid_template_base.html"
Expand Down
1 change: 1 addition & 0 deletions tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Not quite all fixtures are tested here, the db and transactional_db
fixtures are tested in test_database.
"""

import socket
from contextlib import contextmanager
from typing import Generator
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ commands =
[testenv:linting]
extras =
deps =
ruff==0.1.3
mypy==1.6.1
ruff==0.6.3
mypy==1.11.2
commands =
ruff check --statistics {posargs:pytest_django pytest_django_test tests}
ruff check {posargs:pytest_django pytest_django_test tests}
ruff format --quiet --diff {posargs:pytest_django pytest_django_test tests}
mypy {posargs:pytest_django pytest_django_test tests}

Expand Down

0 comments on commit 30602a2

Please sign in to comment.