summaryrefslogtreecommitdiff
path: root/tools/tests/test_barcode_tools.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/tests/test_barcode_tools.py')
-rw-r--r--tools/tests/test_barcode_tools.py26
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