53b38ea15c
Refactor/split investment and client * refactor: clean up tests * Renamed tests/qcqa to tests/qa_qc for consistency * comment out faulty test - see docstring note at top * split to client/investment * add __init__.py to investment and client to avoid mypy confusion * fix imports * update imports for consistency across investment module * move back to one config * try changing import to relative * add init.py to src * try relative import * try one more sys.path.append * fix path for client main * fix imports in file_processing * make prompts common * move keywords out to `src` * move smart_chunking_funcs to `src` * fix mypy error * start moving to explicit imports * remove old keywords and fix imports for keywords and prompts * change all imports to full paths * fix unit tests * add readme for new way of running things * isort after all that import work * remove unused sys.path.append from some tests Approved-by: Katon Minhas
74 lines
2.3 KiB
Python
74 lines
2.3 KiB
Python
import pytest
|
|
|
|
from src.qa_qc.qa_qc_utils import tin_check
|
|
|
|
|
|
def test_valid_tin_format():
|
|
"""Test that a correctly formatted TIN returns True"""
|
|
tin = "12-3456789"
|
|
result, is_valid = tin_check(tin)
|
|
assert result == tin
|
|
assert is_valid is True
|
|
|
|
def test_invalid_tin_format():
|
|
"""Test various invalid TIN formats"""
|
|
invalid_tins = [
|
|
"123-456789", # Too many digits before hyphen
|
|
"12-456789", # Too few digits after hyphen
|
|
"12-45678901", # Too many digits after hyphen
|
|
"12_3456789", # Wrong separator
|
|
"ab-3456789", # Letters instead of numbers
|
|
"12-abcdefg", # Letters instead of numbers
|
|
"123456789", # No hyphen
|
|
"-12345678", # Hyphen at start
|
|
"12-34567-", # Hyphen at end
|
|
]
|
|
|
|
for tin in invalid_tins:
|
|
result, is_valid = tin_check(tin)
|
|
assert result == tin
|
|
assert is_valid is False
|
|
|
|
def test_non_string_inputs():
|
|
"""Test handling of non-string inputs"""
|
|
test_cases = [
|
|
(123456789, "123456789", False),
|
|
(12.3456789, "12.3456789", False),
|
|
(None, 'None', False),
|
|
([12, 3456789], "[12, 3456789]", False),
|
|
({"tin":"12-3456789"}, "{'tin': '12-3456789'}", False),
|
|
]
|
|
|
|
for input_val, expected_str, expected_valid in test_cases:
|
|
result, is_valid = tin_check(input_val)
|
|
assert result == expected_str
|
|
assert is_valid is expected_valid
|
|
|
|
def test_edge_cases():
|
|
"""Test edge cases with valid-looking but incorrect formats"""
|
|
test_cases = [
|
|
"12 3456789", #Space instead of dash
|
|
"1 2-3456789", # Space at beginning
|
|
"12-345 6789", # Space in middle
|
|
]
|
|
|
|
for tin in test_cases:
|
|
result, is_valid = tin_check(tin)
|
|
assert result == tin
|
|
assert is_valid is False
|
|
|
|
def test_multiple_tins_in_string():
|
|
"""Test strings containing multiple TIN-like patterns"""
|
|
test_cases = [
|
|
"12-3456789 34-5678901", # Two TINs with space
|
|
"12-345678912-3456789", # Two TINs without space
|
|
"Some text 12-3456789", # TIN with preceding text
|
|
"12-3456789 some text", # TIN with following text
|
|
]
|
|
|
|
for tin in test_cases:
|
|
result, is_valid = tin_check(tin)
|
|
assert result == tin
|
|
assert is_valid is False
|
|
|