Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
last-partizan committed Aug 13, 2024
1 parent a550bbd commit f7299d4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 1 addition & 2 deletions modeltranslation/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ def class_getitem(cls: type, key: str | type | TypeVar):
return cls

for cls in classes:
if not hasattr(cls, "__class_getitem__"):
cls.__class_getitem__ = classmethod(class_getitem) # type: ignore[attr-defined]
cls.__class_getitem__ = classmethod(class_getitem) # type: ignore[attr-defined]
2 changes: 2 additions & 0 deletions modeltranslation/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import warnings

import django_stubs_ext
from modeltranslation._typing import monkeypatch

warnings.simplefilter("always", DeprecationWarning)
django_stubs_ext.monkeypatch()
monkeypatch()


def _get_database_config():
Expand Down
4 changes: 3 additions & 1 deletion modeltranslation/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2912,11 +2912,13 @@ class ProxyTestModelAdmin(admin.TranslationAdmin):
assert tuple(ma.get_form(request, self.test_obj).base_fields.keys()) == tuple(fields)

def test_class_attribute_access_raises_type_error(self):
# Test for django-cms compatibility
# https://github.com/django-cms/django-cms/issues/7948
class TestModelAdmin(admin.TranslationAdmin[models.TestModel]):
allow_children = True

with pytest.raises(KeyError):
TestModelAdmin["allow_children"] # type: ignore
TestModelAdmin["allow_children"]


class ThirdPartyAppIntegrationTest(ModeltranslationTestBase):
Expand Down

0 comments on commit f7299d4

Please sign in to comment.