Skip to content

Commit

Permalink
test: adopt new defaults for PT001 and PT023 rules (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
paduszyk authored Aug 19, 2024
1 parent 99bcf11 commit fcb9353
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 84 deletions.
10 changes: 5 additions & 5 deletions tests/commands/test_dumpdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pathlib import Path


@pytest.mark.django_db()
@pytest.mark.django_db
def test_dumpdata_command_invokes_serializer(fixture_path: Path) -> None:
# Arrange.
DummyModel._default_manager.create()
Expand All @@ -33,7 +33,7 @@ def test_dumpdata_command_invokes_serializer(fixture_path: Path) -> None:
serializer_mock["serialize"].assert_called()


@pytest.mark.django_db()
@pytest.mark.django_db
def test_dumpdata_command_warns_if_output_is_not_provided() -> None:
# Arrange.
DummyModel._default_manager.create()
Expand All @@ -46,7 +46,7 @@ def test_dumpdata_command_warns_if_output_is_not_provided() -> None:
call_command("dumpdata", format="xlsx")


@pytest.mark.django_db()
@pytest.mark.django_db
def test_dumpdata_command_warns_if_there_is_nothing_to_serialize(
fixture_path: Path,
) -> None:
Expand All @@ -61,7 +61,7 @@ def test_dumpdata_command_warns_if_there_is_nothing_to_serialize(
call_command("dumpdata", format="xlsx", output=fixture_path)


@pytest.mark.django_db()
@pytest.mark.django_db
def test_dumpdata_command_saves_workbook_if_output_is_provided(
fixture_path: Path,
) -> None:
Expand All @@ -76,7 +76,7 @@ def test_dumpdata_command_saves_workbook_if_output_is_provided(
workbook_save_mock.assert_called_with(str(fixture_path))


@pytest.mark.django_db()
@pytest.mark.django_db
def test_dumpdata_command_does_not_save_workbook_if_output_is_not_provided() -> None:
# Arrange.
DummyModel._default_manager.create()
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/test_loaddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pathlib import Path


@pytest.mark.django_db()
@pytest.mark.django_db
def test_loaddata_command_invokes_deserializer(fixture_path: Path) -> None:
# Arrange.
wb = openpyxl.Workbook()
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _media_setup_and_cleanup() -> Generator[None, None, None]:
shutil.rmtree(settings.MEDIA_ROOT)


@pytest.fixture()
@pytest.fixture
def mock_file() -> Callable[[str], mock.Mock]:
def _mock_file(filename: str) -> mock.Mock:
file_mock = mock.MagicMock(spec=File)
Expand All @@ -39,7 +39,7 @@ def _mock_file(filename: str) -> mock.Mock:
return _mock_file


@pytest.fixture()
@pytest.fixture
def mock_image() -> Callable[[str], mock.Mock]:
def _mock_image(filename: str) -> mock.Mock:
image_file_mock = mock.MagicMock(spec=ImageFile)
Expand All @@ -50,6 +50,6 @@ def _mock_image(filename: str) -> mock.Mock:
return _mock_image


@pytest.fixture()
@pytest.fixture
def fixture_path(tmp_path: Path) -> Path:
return tmp_path / "fixture.xlsx"
2 changes: 1 addition & 1 deletion tests/core/test_deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_deserializer_reads_empty_cells_as_none(fixture_path: Path) -> None:
"None",
],
)
@pytest.mark.django_db()
@pytest.mark.django_db
def test_django_handles_empty_non_nullable_fields(
fixture_path: Path,
empty_value: str | None,
Expand Down
12 changes: 6 additions & 6 deletions tests/core/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pathlib import Path


@pytest.mark.django_db()
@pytest.mark.django_db
def test_serializer_saves_workbook_if_stream_is_valid(fixture_path: Path) -> None:
# Arrange.
obj = DummyModel._default_manager.create()
Expand All @@ -40,7 +40,7 @@ def test_serializer_raises_error_if_stream_is_invalid() -> None:
serialize("xlsx", [], stream=mock.ANY)


@pytest.mark.django_db()
@pytest.mark.django_db
def test_serializer_applies_shortened_sheet_name_if_model_label_is_too_long() -> None:
# Arrange.
obj = LabelLongerThan31CharactersModel._default_manager.create()
Expand All @@ -52,7 +52,7 @@ def test_serializer_applies_shortened_sheet_name_if_model_label_is_too_long() ->
assert "LabelLongerThan31CharactersMode" in wb


@pytest.mark.django_db()
@pytest.mark.django_db
def test_serializer_emits_runtime_warning_if_model_label_is_too_long() -> None:
# Arrange.
obj = LabelLongerThan31CharactersModel._default_manager.create()
Expand All @@ -72,7 +72,7 @@ def test_serializer_emits_runtime_warning_if_model_label_is_too_long() -> None:
assert "LabelLongerThan31CharactersMode" in wb


@pytest.mark.django_db()
@pytest.mark.django_db
def test_serializer_raises_error_if_conflicting_default_sheet_names_are_found() -> None:
# Arrange.
obj_a = LabelLongerThan31CharactersModelA._default_manager.create()
Expand All @@ -91,7 +91,7 @@ def test_serializer_raises_error_if_conflicting_default_sheet_names_are_found()
serialize("xlsx", [obj_a, obj_b])


@pytest.mark.django_db()
@pytest.mark.django_db
def test_serializer_applies_sheet_name_from_model_sheet_names_option() -> None:
# Arrange.
obj = DummyModel._default_manager.create()
Expand Down Expand Up @@ -218,7 +218,7 @@ def test_serializer_raises_error_if_sheet_name_from_model_sheet_names_option_con
)


@pytest.mark.django_db()
@pytest.mark.django_db
def test_serializer_removes_sheets_not_added_by_itself() -> None:
# Arrange.
obj_1 = DummyModel._default_manager.create()
Expand Down
12 changes: 6 additions & 6 deletions tests/fields/test_auto_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pathlib import Path


@pytest.mark.django_db()
@pytest.mark.django_db
def test_auto_field_is_deserialized(fixture_path: Path) -> None:
# Arrange.
wb = openpyxl.Workbook()
Expand All @@ -31,7 +31,7 @@ def test_auto_field_is_deserialized(fixture_path: Path) -> None:
assert obj.auto_field == 42


@pytest.mark.django_db()
@pytest.mark.django_db
def test_auto_field_is_serialized() -> None:
# Arrange.
obj = AutoFieldModel._default_manager.create()
Expand All @@ -44,7 +44,7 @@ def test_auto_field_is_serialized() -> None:
assert wb["tests.AutoFieldModel"]["A2"].value == obj.pk


@pytest.mark.django_db()
@pytest.mark.django_db
def test_big_auto_field_is_deserialized(fixture_path: Path) -> None:
# Arrange.
wb = openpyxl.Workbook()
Expand All @@ -61,7 +61,7 @@ def test_big_auto_field_is_deserialized(fixture_path: Path) -> None:
assert obj.big_auto_field == 42


@pytest.mark.django_db()
@pytest.mark.django_db
def test_big_auto_field_is_serialized() -> None:
# Arrange.
obj = BigAutoFieldModel._default_manager.create()
Expand All @@ -74,7 +74,7 @@ def test_big_auto_field_is_serialized() -> None:
assert wb["tests.BigAutoFieldModel"]["A2"].value == obj.pk


@pytest.mark.django_db()
@pytest.mark.django_db
def test_small_auto_field_is_deserialized(fixture_path: Path) -> None:
# Arrange.
wb = openpyxl.Workbook()
Expand All @@ -91,7 +91,7 @@ def test_small_auto_field_is_deserialized(fixture_path: Path) -> None:
assert obj.small_auto_field == 42


@pytest.mark.django_db()
@pytest.mark.django_db
def test_small_auto_field_is_serialized() -> None:
# Arrange.
obj = SmallAutoFieldModel._default_manager.create()
Expand Down
4 changes: 2 additions & 2 deletions tests/fields/test_boolean_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
True,
],
)
@pytest.mark.django_db()
@pytest.mark.django_db
def test_boolean_field_is_deserialized(fixture_path: Path, field_value: bool) -> None:
# Arrange.
wb = openpyxl.Workbook()
Expand All @@ -47,7 +47,7 @@ def test_boolean_field_is_deserialized(fixture_path: Path, field_value: bool) ->
True,
],
)
@pytest.mark.django_db()
@pytest.mark.django_db
def test_boolean_field_is_serialized(field_value: bool) -> None:
# Arrange.
obj = BooleanFieldModel._default_manager.create(pk=1, boolean_field=field_value)
Expand Down
12 changes: 6 additions & 6 deletions tests/fields/test_file_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from unittest import mock


@pytest.mark.django_db()
@pytest.mark.django_db
def test_file_field_is_deserialized(
fixture_path: Path,
mock_file: Callable[[str], mock.Mock],
Expand All @@ -37,7 +37,7 @@ def test_file_field_is_deserialized(
assert obj.file_field == mock_file("file.txt")


@pytest.mark.django_db()
@pytest.mark.django_db
def test_file_field_is_serialized(mock_file: Callable[[str], mock.Mock]) -> None:
# Arrange.
obj = FileFieldModel._default_manager.create(pk=1, file_field=mock_file("file.txt"))
Expand All @@ -52,7 +52,7 @@ def test_file_field_is_serialized(mock_file: Callable[[str], mock.Mock]) -> None
assert wb["tests.FileFieldModel"]["B2"].value == "file.txt"


@pytest.mark.django_db()
@pytest.mark.django_db
def test_image_field_is_deserialized(
fixture_path: Path,
mock_image: Callable[[str], mock.Mock],
Expand All @@ -74,7 +74,7 @@ def test_image_field_is_deserialized(
assert obj.image_field == mock_image("image.png")


@pytest.mark.django_db()
@pytest.mark.django_db
def test_image_field_is_serialized(mock_image: Callable[[str], mock.Mock]) -> None:
# Arrange.
obj = ImageFieldModel._default_manager.create(
Expand All @@ -92,7 +92,7 @@ def test_image_field_is_serialized(mock_image: Callable[[str], mock.Mock]) -> No
assert wb["tests.ImageFieldModel"]["B2"].value == "image.png"


@pytest.mark.django_db()
@pytest.mark.django_db
def test_file_path_field_is_deserialized(fixture_path: Path) -> None:
# Arrange.
wb = openpyxl.Workbook()
Expand All @@ -111,7 +111,7 @@ def test_file_path_field_is_deserialized(fixture_path: Path) -> None:
assert obj.file_path_field == "file.txt"


@pytest.mark.django_db()
@pytest.mark.django_db
def test_file_path_field_is_serialized() -> None:
# Arrange.
obj = FilePathFieldModel._default_manager.create(pk=1, file_path_field="file.txt")
Expand Down
Loading

0 comments on commit fcb9353

Please sign in to comment.