From 5a1c153084516a70be34bda2b2f380f133a26e34 Mon Sep 17 00:00:00 2001 From: greyllmmoder Date: Thu, 9 Apr 2026 13:15:51 +0530 Subject: [PATCH] =?UTF-8?q?test:=20ECI=20roundtrip=20coverage=20=E2=80=94?= =?UTF-8?q?=20FLG(n)=20sequence=20and=20charset=20encoding=20(Item=204)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add 5 pytest functions to test_core.py verifying that ECI FLG(n) tokens are correctly prepended and that AztecCode encodes non-Latin payloads without error. - encoding_to_eci contains expected ECI values for utf-8, iso8859-1/8, shift_jis - find_optimal_sequence(utf-8) produces [Shift.PUNCT, Misc.FLG, 2, 26, ...] - find_optimal_sequence(iso8859-1) produces [Shift.PUNCT, Misc.FLG, 1, 1, ...] - AztecCode encodes UTF-8 euro sign and Hebrew iso8859-8 payload without error - All 99 tests pass, coverage 90% --- tests/test_core.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/test_core.py b/tests/test_core.py index 5658cc8..ff1b3cf 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -216,3 +216,51 @@ def test_barcode_readability_eci(self): if __name__ == '__main__': unittest.main(verbosity=2) + + +# --------------------------------------------------------------------------- +# ECI roundtrip tests (pytest-style) +# Verify that ECI FLG(n) tokens are correctly prepended to the sequence and +# that AztecCode encodes non-Latin payloads without error. +# --------------------------------------------------------------------------- + +def test_eci_dict_contains_standard_charsets() -> None: + """encoding_to_eci maps well-known charsets to their ISO 24778 ECI values.""" + assert encoding_to_eci["utf-8"] == 26 + assert encoding_to_eci["iso8859-1"] == 1 + assert encoding_to_eci["iso8859-8"] == 10 + assert encoding_to_eci["shift_jis"] == 20 + + +def test_eci_sequence_starts_with_flg_punct_for_utf8() -> None: + """find_optimal_sequence with utf-8 encoding prepends FLG(2) + ECI value 26.""" + seq = find_optimal_sequence("hello", encoding="utf-8") + assert seq[0] is Shift.PUNCT, "First element must be Shift.PUNCT for FLG preamble" + assert seq[1] is Misc.FLG, "Second element must be Misc.FLG" + assert seq[2] == 2, "FLG count must be 2 (len of '26')" + assert seq[3] == 26, "ECI value for utf-8 must be 26" + + +def test_eci_sequence_single_digit_eci_value() -> None: + """iso8859-1 (ECI=1) produces a single-digit FLG count of 1.""" + seq = find_optimal_sequence("hello", encoding="iso8859-1") + assert seq[0] is Shift.PUNCT + assert seq[1] is Misc.FLG + assert seq[2] == 1, "FLG count must be 1 for single-digit ECI value" + assert seq[3] == 1, "ECI value for iso8859-1 must be 1" + + +def test_aztec_code_utf8_non_ascii_encodes_without_error() -> None: + """AztecCode encodes a UTF-8 payload containing non-ASCII characters.""" + payload = "The price is \u20ac4" # € is U+20AC, not in iso8859-1 + code = AztecCode(payload, encoding="utf-8") + assert code is not None + assert code.size >= 15 + + +def test_aztec_code_iso8859_8_encodes_without_error() -> None: + """AztecCode encodes a Hebrew payload via iso8859-8 ECI.""" + payload = "\u05d0\u05d1\u05d2" # alef, bet, gimel (Unicode Hebrew, iso8859-8 encodable) + code = AztecCode(payload, encoding="iso8859-8") + assert code is not None + assert code.size >= 15