diff options
| author | cirakg <cirakg@cirakg.xyz> | 2026-10-20 11:24:58 +0200 |
|---|---|---|
| committer | cirakg <cirakg@cirakg.xyz> | 2026-10-20 11:24:58 +0200 |
| commit | 1251aab9f8f9f38aa5bdefd4fed1f58236166cf8 (patch) | |
| tree | d9824a2430cff9f6659a5b14b6e437d6b1568b87 /tools/tests/test_barcode_tools.py | |
| parent | d94eb32c80d2dbf00a45d7e69804f8247240a769 (diff) | |
test(codes): compare Data Matrix and PDF417 with references and decode them, also from screenshots
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 | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/tools/tests/test_barcode_tools.py b/tools/tests/test_barcode_tools.py index 0ee3cc4..5a2e999 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_pdf417_tables import gen_qr_tables ROOT = Path(__file__).resolve().parents[2] @@ -83,5 +84,28 @@ def test_segno_padding_quirk_detection() -> None: 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) + image = ref.render_matrix(bytes.fromhex(hexbits), (21, 21), 2, quiet=4) assert ref.decode(image, ref.QR) == ["HELLO WORLD"] + + +def test_committed_pdf417_tables_match_pdf417gen(tmp_path: Path) -> None: + gen_pdf417_tables.main(["--out-dir", str(tmp_path)]) + for path in tmp_path.iterdir(): + assert path.read_text(encoding="utf-8") == (ROOT / "resources" / "pdf417" / path.name).read_text( + encoding="utf-8" + ) + codes = gen_pdf417_tables.tables() + assert len(codes["codes0"]["v"]) == 929 # type: ignore[index] + + +def test_ppf_padding_quirk_detection() -> None: + # (149 * pos) % 253 == 124 at pos 124 * 149^-1 mod 253; a 10x10 symbol + # (3 data codewords) has no pad at such a position. + assert not gen_code_vectors.ppf_pad_differs("a", 10) + assert any(gen_code_vectors.ppf_pad_differs("x" * n, 88) for n in (480, 500, 520)) + + +def test_pdf417_reference_rows() -> None: + reference = gen_code_vectors.pdf417_reference("Hello, World!", 3, 2) + assert reference is not None and reference[0] == 7 and reference[1] == 17 * (3 + 4) + 1 + assert gen_code_vectors.pdf417_reference("ab", 30, 0) is None # one row: below the minimum of 3 |
