mirror of
https://github.com/Hopiu/django-modeltranslation.git
synced 2026-05-26 21:14:01 +00:00
chore(tests): Type-check tests
This commit is contained in:
parent
5a3cd77ddb
commit
6768a26a9d
5 changed files with 31 additions and 8 deletions
|
|
@ -1,9 +1,13 @@
|
|||
# mypy: disable-error-code="django-manager-missing"
|
||||
from __future__ import annotations
|
||||
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.core import validators
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy
|
||||
|
||||
from modeltranslation.manager import MultilingualManager
|
||||
from typing import Any
|
||||
|
||||
|
||||
class TestModel(models.Model):
|
||||
|
|
@ -124,8 +128,10 @@ class ManyToManyFieldModel(models.Model):
|
|||
self_call_1 = models.ManyToManyField("self")
|
||||
# test multiple self m2m
|
||||
self_call_2 = models.ManyToManyField("self")
|
||||
through_model = models.ManyToManyField(TestModel, through="CustomThroughModel")
|
||||
trans_through_model = models.ManyToManyField(
|
||||
through_model = models.ManyToManyField[TestModel, "CustomThroughModel"](
|
||||
TestModel, through="CustomThroughModel"
|
||||
)
|
||||
trans_through_model = models.ManyToManyField[TestModel, Any](
|
||||
TestModel, related_name="m2m_trans_through_model_ref", through="RegisteredThroughModel"
|
||||
)
|
||||
untrans = models.ManyToManyField(
|
||||
|
|
@ -414,7 +420,7 @@ class CustomManagerBaseModel(models.Model):
|
|||
class CustomManagerChildTestModel(CustomManagerBaseModel):
|
||||
title = models.CharField(gettext_lazy("title"), max_length=255)
|
||||
|
||||
objects = CustomManager2()
|
||||
objects = CustomManager2() # type: ignore[misc]
|
||||
|
||||
|
||||
class PlainChildTestModel(CustomManagerBaseModel):
|
||||
|
|
@ -505,7 +511,7 @@ class CustomManagerY(models.Manager):
|
|||
|
||||
class AbstractModelY(models.Model):
|
||||
title = models.CharField(max_length=255)
|
||||
xs = models.ManyToManyField("ModelX", through="ModelXY")
|
||||
xs = models.ManyToManyField[ModelX, ModelXY]("ModelX", through="ModelXY")
|
||||
objects = CustomManagerY()
|
||||
|
||||
class Meta:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
import os
|
||||
import warnings
|
||||
|
||||
import django_stubs_ext
|
||||
|
||||
warnings.simplefilter("always", DeprecationWarning)
|
||||
django_stubs_ext.monkeypatch()
|
||||
|
||||
|
||||
def _get_database_config():
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ from django.db.models.functions import Cast, Concat
|
|||
from django.test import TestCase, TransactionTestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.utils.translation import get_language, override, trans_real
|
||||
from parameterized import parameterized
|
||||
from parameterized import parameterized # type: ignore[import-untyped]
|
||||
|
||||
from modeltranslation import admin, translator
|
||||
from modeltranslation import settings as mt_settings
|
||||
|
|
|
|||
|
|
@ -241,13 +241,13 @@ class FieldInheritanceCTranslationOptions(FieldInheritanceBTranslationOptions):
|
|||
|
||||
|
||||
class FieldInheritanceDTranslationOptions(FieldInheritanceBTranslationOptions):
|
||||
fields = ("titled",)
|
||||
fields = ["titled"]
|
||||
|
||||
|
||||
class FieldInheritanceETranslationOptions(
|
||||
FieldInheritanceCTranslationOptions, FieldInheritanceDTranslationOptions
|
||||
):
|
||||
fields = ("titlee",)
|
||||
fields = ["titlee"]
|
||||
|
||||
|
||||
# ######### Integration testing
|
||||
|
|
|
|||
|
|
@ -40,6 +40,15 @@ ignore = [
|
|||
"E501", # line length is handled by formatter
|
||||
]
|
||||
|
||||
[tool.ruff.lint.pyflakes]
|
||||
extend-generics = [
|
||||
"django.db.models.ForeignKey",
|
||||
"django.db.models.OneToOneField",
|
||||
"django.db.models.ManyToManyField",
|
||||
"django.db.models.Manager",
|
||||
"django.db.models.manager.RelatedManager",
|
||||
]
|
||||
|
||||
[tool.mypy]
|
||||
python_version = "3.8"
|
||||
incremental = true
|
||||
|
|
@ -48,9 +57,11 @@ warn_redundant_casts = true
|
|||
warn_unused_configs = true
|
||||
show_error_context = true
|
||||
exclude = [
|
||||
'tests/'
|
||||
'tests/migrations/',
|
||||
'tests/urls.py',
|
||||
]
|
||||
disable_error_code = ["method-assign"]
|
||||
plugins = ["mypy_django_plugin.main"]
|
||||
|
||||
[[tool.mypy.overrides]]
|
||||
module = ["modeltranslation.fields"]
|
||||
|
|
@ -67,3 +78,6 @@ disable_error_code = ["override", "attr-defined"]
|
|||
[[tool.mypy.overrides]]
|
||||
module = ["modeltranslation.manager"]
|
||||
disable_error_code = ["override", "attr-defined", "return-value", "misc"]
|
||||
|
||||
[tool.django-stubs]
|
||||
django_settings_module = "modeltranslation.tests.settings"
|
||||
|
|
|
|||
Loading…
Reference in a new issue