mirror of
https://github.com/data-privacy-stack/presidio.git
synced 2026-07-23 11:20:55 -05:00
* feat(analyzer): add nine South African predefined recognizers Extend ZA coverage beyond ZA_ID_NUMBER with passport, tax, VAT, CIPC registration, eNaTIS driver's licence and traffic register numbers, licence plates, and mobile/telephone numbers split by line type. All recognizers are disabled by default in default_recognizers.yaml. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(analyzer): update year validation logic in South African recognizers Refactor the year validation logic in the ZaCompanyRegistrationRecognizer and ZaDriverLicenseRecognizer to ensure the current year is accurately checked without allowing for the next year. Remove unnecessary dependency on ZaIdNumberRecognizer in ZaDriverLicenseRecognizer to streamline the code. Update the validate_result method in ZaLicensePlateRecognizer to return a boolean type for consistency. * fix(analyzer): address Copilot review feedback for ZA recognizers Correct 08x NSN fallback classification, tighten driver licence validation, and replace the unstable passport docstring reference. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(analyzer): align ZA driver licence docs and address Copilot round 3 Update driver licence length documentation to 10-14 characters to match validation constraints, and use PhoneNumberMatcher.number directly instead of re-parsing matched substrings. Co-authored-by: Cursor <cursoragent@cursor.com> * Update CHANGELOG.md * Update CHANGELOG.md --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Sharon Hart <sharonh.dev@gmail.com>
56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
import pytest
|
|
|
|
from presidio_analyzer.predefined_recognizers import ZaTrafficRegisterNumberRecognizer
|
|
from tests import assert_result
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def recognizer():
|
|
return ZaTrafficRegisterNumberRecognizer()
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def entities():
|
|
return ["ZA_TRAFFIC_REGISTER_NUMBER"]
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"text, expected_len, expected_positions",
|
|
[
|
|
(
|
|
"Traffic register number 1234567890123 is on file.",
|
|
1,
|
|
((24, 37),),
|
|
),
|
|
(
|
|
"eNaTIS TRN 6001015000076 recorded.",
|
|
1,
|
|
((11, 24),),
|
|
),
|
|
("8001015009087", 0, ()),
|
|
("123456789012", 0, ()),
|
|
("12345678901234", 0, ()),
|
|
],
|
|
)
|
|
def test_analyze_valid_and_invalid_za_traffic_register_numbers(
|
|
text, expected_len, expected_positions, recognizer, entities, max_score
|
|
):
|
|
results = recognizer.analyze(text, entities)
|
|
assert len(results) == expected_len
|
|
for res, (st_pos, fn_pos) in zip(results, expected_positions):
|
|
assert_result(res, entities[0], st_pos, fn_pos, max_score)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"trn, expected",
|
|
[
|
|
("1234567890123", True),
|
|
("6001015000076", True),
|
|
("8001015009087", False),
|
|
("123456789012", False),
|
|
("12345678901234", False),
|
|
],
|
|
)
|
|
def test_validate_result(trn, expected, recognizer):
|
|
assert recognizer.validate_result(trn) is expected
|