Skip to content

Commit

Permalink
Ignore deliberate type errors
Browse files Browse the repository at this point in the history
These tests deliberately pass the wrong type so that the error handling
can be tested, so there's no need to track these errors in the type
ratchet.
  • Loading branch information
meshy committed May 9, 2024
1 parent e506947 commit 50482ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 1 addition & 4 deletions mypy-ratchet.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{
"tests/django_integrity/test_conversion.py": {
"Argument \"model\" to \"Unique\" has incompatible type \"Unique\"; expected \"type[Model]\" [arg-type]": 1,
"Argument 1 to \"refine_integrity_error\" has incompatible type \"dict[ForeignKey, type[SimpleError]]\"; expected \"Mapping[_Rule, Exception]\" [arg-type]": 3,
"Argument 1 to \"refine_integrity_error\" has incompatible type \"dict[Named, type[SimpleError]]\"; expected \"Mapping[_Rule, Exception]\" [arg-type]": 2,
"Argument 1 to \"refine_integrity_error\" has incompatible type \"dict[NotNull, type[SimpleError]]\"; expected \"Mapping[_Rule, Exception]\" [arg-type]": 3,
"Argument 1 to \"refine_integrity_error\" has incompatible type \"dict[PrimaryKey, type[SimpleError]]\"; expected \"Mapping[_Rule, Exception]\" [arg-type]": 2,
"Argument 1 to \"refine_integrity_error\" has incompatible type \"dict[Unique, type[SimpleError]]\"; expected \"Mapping[_Rule, Exception]\" [arg-type]": 3,
"Incompatible type for \"unique_field\" of \"AlternativeUniqueModel\" (got \"None\", expected \"float | int | str | Combinable\") [misc]": 1,
"Incompatible type for \"unique_field\" of \"UniqueModel\" (got \"None\", expected \"float | int | str | Combinable\") [misc]": 2
"Argument 1 to \"refine_integrity_error\" has incompatible type \"dict[Unique, type[SimpleError]]\"; expected \"Mapping[_Rule, Exception]\" [arg-type]": 3
}
}
9 changes: 6 additions & 3 deletions tests/django_integrity/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ def test_error_refined(self) -> None:
# The original error should be transformed into our expected error.
with pytest.raises(SimpleError):
with conversion.refine_integrity_error(rules):
test_models.UniqueModel.objects.create(unique_field=None)
# We ignore the type error because it's picking up on the error we're testing.
test_models.UniqueModel.objects.create(unique_field=None) # type: ignore[misc]

def test_model_mismatch(self) -> None:
# Same field, but different model.
Expand All @@ -186,7 +187,8 @@ def test_model_mismatch(self) -> None:

with pytest.raises(django_db.IntegrityError):
with conversion.refine_integrity_error(rules):
test_models.UniqueModel.objects.create(unique_field=None)
# We ignore the type error because it's picking up on the error we're testing.
test_models.UniqueModel.objects.create(unique_field=None) # type: ignore[misc]

def test_field_mismatch(self) -> None:
# Same model, but different field.
Expand All @@ -200,7 +202,8 @@ def test_field_mismatch(self) -> None:
with pytest.raises(django_db.IntegrityError):
with conversion.refine_integrity_error(rules):
test_models.AlternativeUniqueModel.objects.create(
unique_field=None,
# We ignore the type error because it's picking up on the error we're testing.
unique_field=None, # type: ignore[misc]
unique_field_2=42,
)

Expand Down

0 comments on commit 50482ae

Please sign in to comment.