diff options
| author | cirakg <cirakg@cirakg.xyz> | 2026-10-20 06:56:58 +0200 |
|---|---|---|
| committer | cirakg <cirakg@cirakg.xyz> | 2026-10-20 06:56:58 +0200 |
| commit | f455246fde086dda0cb61b92c84a5146a831a2bf (patch) | |
| tree | 09b5e97ee5f84e495bbd0646e1ad0e3e2fbfb9af /tools/tests/test_barcode_tools.py | |
| parent | 2df98d1ba129f95a10c6b81665671d3b12560c79 (diff) | |
test(codes): compare QR with segno, decode QR dumps and the QR screenshot
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/tests/test_barcode_tools.py')
| -rw-r--r-- | tools/tests/test_barcode_tools.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tools/tests/test_barcode_tools.py b/tools/tests/test_barcode_tools.py index 7be1f18..0ee3cc4 100644 --- a/tools/tests/test_barcode_tools.py +++ b/tools/tests/test_barcode_tools.py @@ -8,6 +8,7 @@ from pathlib import Path import barcode_ref as ref import check_codes import gen_code_vectors +import gen_qr_tables ROOT = Path(__file__).resolve().parents[2] @@ -63,3 +64,24 @@ def test_check_codes_reads_dump_lines(tmp_path: Path) -> None: empty = tmp_path / "empty.log" empty.write_text("nothing\n", encoding="utf-8") assert check_codes.main([str(empty)]) == 2 + + +def test_committed_qr_tables_match_segno() -> None: + committed = (ROOT / "source" / "codes" / "QrTables.mc").read_text(encoding="utf-8") + assert committed == gen_qr_tables.render(gen_qr_tables.table()) + rows = gen_qr_tables.table() + assert rows[0] == [7, 1, 19, 0, 0] # version 1-L: 7 EC codewords, one block of 19 + assert len(gen_qr_tables.alignment()) == 40 and gen_qr_tables.alignment()[0] == [] + + +def test_segno_padding_quirk_detection() -> None: + # Byte mode always ends on a codeword boundary after the terminator, so + # segno would add a zero byte unless the symbol is exactly full. + assert gen_code_vectors.segno_pads_extra_byte("hello", 0, 1) + assert not gen_code_vectors.segno_pads_extra_byte("01234567", 1, 1) + + +def test_rendered_qr_matrix_decodes() -> None: + _, _, hexbits = gen_code_vectors.qr_reference("HELLO WORLD", 1, 1, 2) + image = ref.render_matrix(bytes.fromhex(hexbits), 21, 2, quiet=4) + assert ref.decode(image, ref.QR) == ["HELLO WORLD"] |
