refactor(anaf): remove dead code in sanitize_cui, fix empty test
Remove unreachable OCR-skip fallback (raw_bare can't be all-digits if strip_ro_prefix changed it via OCR fix). Add real test for the checksum result==10→0 branch using CUI 14186770. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -43,7 +43,6 @@ def validate_cui_checksum(bare_cui: str) -> bool:
|
||||
digits = [int(d) for d in bare_cui]
|
||||
check_digit = digits[-1]
|
||||
body = digits[:-1]
|
||||
# Pad left with zeros to 9 positions
|
||||
padded = [0] * (9 - len(body)) + body
|
||||
total = sum(d * k for d, k in zip(padded, _CUI_KEY))
|
||||
result = (total * 10) % 11
|
||||
@@ -66,11 +65,6 @@ def sanitize_cui(raw_cf: str) -> tuple[str, str | None]:
|
||||
if validate_cui(bare) and validate_cui_checksum(bare):
|
||||
return bare, None
|
||||
|
||||
# Try without OCR fix (raw, just stripped)
|
||||
raw_bare = re.sub(r'^RO\s*', '', raw_cf.strip().upper())
|
||||
if raw_bare != bare and validate_cui(raw_bare) and validate_cui_checksum(raw_bare):
|
||||
return raw_bare, None
|
||||
|
||||
# Sanitized version passes format but not checksum
|
||||
if validate_cui(bare):
|
||||
return bare, f"CUI {bare} nu trece verificarea cifrei de control"
|
||||
|
||||
@@ -148,15 +148,14 @@ class TestValidateCuiChecksum:
|
||||
assert validate_cui_checksum("1") is False
|
||||
|
||||
def test_checksum_result_10_becomes_0(self):
|
||||
"""When (sum*10)%11 == 10, check digit should be 0."""
|
||||
# Build a CUI where the algorithm yields 10
|
||||
# Body 12345678 → pad to 9: 012345678
|
||||
# 0*7+1*5+2*3+3*2+4*1+5*7+6*5+7*3+8*2 = 0+5+6+6+4+35+30+21+16 = 123
|
||||
# 123*10=1230, 1230%11 = 111*11=1221, remainder=9 → check=9 → not 10
|
||||
# Let's just verify a known CUI ending in 0 works
|
||||
# CUI 46628322 from data: check=2, not 0. Skip this specific edge case test
|
||||
# and just verify the code path exists
|
||||
pass
|
||||
"""When (sum*10)%11 == 10, check digit should be 0.
|
||||
|
||||
CUI 14186770: body=1418677, padded=001418677,
|
||||
sum=0+0+3+8+1+42+35+21+14=124, 1240%11=10 → check=0.
|
||||
"""
|
||||
assert validate_cui_checksum("14186770") is True
|
||||
# Wrong check digit for same body
|
||||
assert validate_cui_checksum("14186771") is False
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
|
||||
Reference in New Issue
Block a user