Skip to content

Commit 5b32857

Browse files
committed
Add regression test for mask evaluation on complete symbol
Verifies that best_mask_pattern() evaluates the complete QR code including format info, version info, and the dark module, per ISO 18004 §7.8.3.1.
1 parent 07ecc85 commit 5b32857

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

qrcode/tests/test_qrcode.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ def test_make_image_with_wrong_pattern():
106106
qrcode.QRCode(mask_pattern=42)
107107

108108

109+
def test_best_mask_pattern_includes_format_info():
110+
"""Mask evaluation should use the complete symbol per ISO 18004 §7.8.3.1."""
111+
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H)
112+
qr.add_data("hello")
113+
qr.best_fit()
114+
qr.data_cache = qrcode.util.create_data(
115+
qr.version, qr.error_correction, qr.data_list
116+
)
117+
# The old code zeroed out format info, version info, and the dark module
118+
# during mask evaluation, which violated the spec and selected mask 5 for
119+
# this input. With the complete symbol evaluated, the correct mask is 6.
120+
assert qr.best_mask_pattern() == 6
121+
122+
109123
def test_mask_pattern_setter():
110124
qr = qrcode.QRCode()
111125

0 commit comments

Comments
 (0)