Skip to content

Commit

Permalink
Suppress mypy errors in field tracker tests
Browse files Browse the repository at this point in the history
I can't find a way to inform mypy of the actual types without
duplicating a lot of test code.
  • Loading branch information
mthuurne committed Apr 16, 2024
1 parent ce29741 commit 3701b6f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tests/test_fields/test_field_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def setUp(self) -> None:
self.tracker = self.instance.tracker

def test_descriptor(self) -> None:
self.assertTrue(isinstance(self.tracked_class.tracker, FieldTracker))
tracker = self.tracked_class.tracker # type: ignore[call-overload]
self.assertTrue(isinstance(tracker, FieldTracker))

def test_pre_save_changed(self) -> None:
self.assertChanged(name=None)
Expand Down Expand Up @@ -529,14 +530,14 @@ class FieldTrackerForeignKeyMixin(FieldTrackerMixin):

def setUp(self) -> None:
self.old_fk = self.fk_class.objects.create(number=8)
self.instance = self.tracked_class.objects.create(fk=self.old_fk)
self.instance = self.tracked_class.objects.create(fk=self.old_fk) # type: ignore[misc]

def test_default(self) -> None:
self.tracker = self.instance.tracker
self.assertChanged()
self.assertPrevious()
self.assertCurrent(id=self.instance.id, fk_id=self.old_fk.id)
self.instance.fk = self.fk_class.objects.create(number=8)
self.instance.fk = self.fk_class.objects.create(number=8) # type: ignore[assignment]
self.assertChanged(fk_id=self.old_fk.id)
self.assertPrevious(fk_id=self.old_fk.id)
self.assertCurrent(id=self.instance.id, fk_id=self.instance.fk_id)
Expand All @@ -546,7 +547,7 @@ def test_custom(self) -> None:
self.assertChanged()
self.assertPrevious()
self.assertCurrent(fk_id=self.old_fk.id)
self.instance.fk = self.fk_class.objects.create(number=8)
self.instance.fk = self.fk_class.objects.create(number=8) # type: ignore[assignment]
self.assertChanged(fk_id=self.old_fk.id)
self.assertPrevious(fk_id=self.old_fk.id)
self.assertCurrent(fk_id=self.instance.fk_id)
Expand All @@ -558,7 +559,7 @@ def test_custom_without_id(self) -> None:
self.assertChanged()
self.assertPrevious()
self.assertCurrent(fk=self.old_fk.id)
self.instance.fk = self.fk_class.objects.create(number=8)
self.instance.fk = self.fk_class.objects.create(number=8) # type: ignore[assignment]
self.assertChanged(fk=self.old_fk.id)
self.assertPrevious(fk=self.old_fk.id)
self.assertCurrent(fk=self.instance.fk_id)
Expand Down

0 comments on commit 3701b6f

Please sign in to comment.