Skip to content

Commit 84b31ec

Browse files
committed
Refactor temporary file handling in tests and simplify deprecation test structure
1 parent 2096319 commit 84b31ec

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

qrcode/tests/conftest.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def dummy_image() -> tempfile.NamedTemporaryFile:
1919
dummy_image = Image.new("RGBA", (1, 1), (255, 0, 0, 255))
2020

2121
# Save the image to a temporary file
22-
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as temp_file:
22+
with tempfile.NamedTemporaryFile(suffix=".png", delete=True) as temp_file:
2323
dummy_image.save(temp_file.name)
24-
25-
return temp_file
24+
yield temp_file

qrcode/tests/test_deprecation.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def test_moduledrawer_import() -> None:
2727
DeprecationWarning,
2828
match="Importing 'SquareModuleDrawer' directly from this module is deprecated.",
2929
):
30-
from qrcode.image.styles.moduledrawers import SquareModuleDrawer
30+
from qrcode.image.styles.moduledrawers import (
31+
SquareModuleDrawer,
32+
)
3133

3234

3335
@pytest.mark.skipif(PIL_AVAILABLE, reason="PIL is installed")
@@ -94,21 +96,16 @@ def test_styledpilimage_embeded_parameters(dummy_image: NamedTemporaryFile) -> N
9496
"qrcode_modules": 1,
9597
}
9698

97-
try:
98-
# Test with embeded_image_path parameter
99-
with pytest.warns(
100-
DeprecationWarning, match="The 'embeded_\\*' parameters are deprecated."
101-
):
102-
StyledPilImage(embeded_image_path=dummy_image.name, **styled_kwargs)
103-
104-
# Test with embeded_image parameter
105-
embedded_img = Image.open(dummy_image.name)
99+
# Test with embeded_image_path parameter
100+
with pytest.warns(
101+
DeprecationWarning, match="The 'embeded_\\*' parameters are deprecated."
102+
):
103+
StyledPilImage(embeded_image_path=dummy_image.name, **styled_kwargs)
106104

107-
with pytest.warns(
108-
DeprecationWarning, match="The 'embeded_\\*' parameters are deprecated."
109-
):
110-
StyledPilImage(embeded_image=embedded_img, **styled_kwargs)
105+
# Test with embeded_image parameter
106+
embedded_img = Image.open(dummy_image.name)
111107

112-
# Make sure the temporary image is always deleted after the testrun.
113-
finally:
114-
Path(dummy_image.name).unlink(missing_ok=True)
108+
with pytest.warns(
109+
DeprecationWarning, match="The 'embeded_\\*' parameters are deprecated."
110+
):
111+
StyledPilImage(embeded_image=embedded_img, **styled_kwargs)

0 commit comments

Comments
 (0)