-
Notifications
You must be signed in to change notification settings - Fork 726
Expand file tree
/
Copy pathtest_pil_clear.py
More file actions
55 lines (42 loc) · 1.51 KB
/
test_pil_clear.py
File metadata and controls
55 lines (42 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from __future__ import annotations
from typing import TYPE_CHECKING
import qrcode
if TYPE_CHECKING:
from pathlib import Path
def test_qrcode_clear_resets_size(tmp_path: Path):
"""
Test that QRCode.clear() properly resets the QRCode object.
Regression test for:
QRCode class not resizing down between runs
https://github.com/lincolnloop/python-qrcode/issues/392
"""
test1_path = tmp_path / "test1.png"
test2_path = tmp_path / "test2.png"
test3_path = tmp_path / "test3.png"
# Create a QR code instance
qr = qrcode.QRCode(version=None)
# Generate first QR code
qr.add_data("https://example.com/")
qr.make(fit=True)
img1 = qr.make_image()
img1.save(test1_path)
# Clear and generate second QR code with different data
qr.clear()
qr.add_data("https://example.net/some/other/path")
qr.make(fit=True)
img2 = qr.make_image()
img2.save(test2_path)
# Clear and generate third QR code with same data as first
qr.clear()
qr.add_data("https://example.com/")
qr.make(fit=True)
img3 = qr.make_image()
img3.save(test3_path)
# Compare the images. Image 1 and 3 must be binary identical.
with test1_path.open("rb") as file1, test3_path.open("rb") as file3:
file1_data = file1.read()
file3_data = file3.read()
# Check that the first and third QR codes are identical
assert file1_data == file3_data, (
"First and third QR codes should be identical after clearing"
)