Files
presidio/presidio-analyzer/tests/test_za_company_registration_recognizer.py
Thato Mokoena f0dbdce29e feat(analyzer): add nine South African predefined recognizers (#2069)
* 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>
2026-07-23 12:36:59 +03:00

54 lines
1.6 KiB
Python

import pytest
from presidio_analyzer.predefined_recognizers import ZaCompanyRegistrationRecognizer
from tests import assert_result
@pytest.fixture(scope="module")
def recognizer():
return ZaCompanyRegistrationRecognizer()
@pytest.fixture(scope="module")
def entities():
return ["ZA_COMPANY_REGISTRATION"]
@pytest.mark.parametrize(
"text, expected_len, expected_positions",
[
("2009/199240/23", 1, ((0, 14),)),
("2014/256030/07", 1, ((0, 14),)),
("CIPC registration 2020/804826/07", 1, ((18, 32),)),
("CK2001/123456", 1, ((0, 13),)),
("Close corporation CK1998/654321 registered.", 1, ((18, 31),)),
("99/199240/23", 0, ()),
("2009/19924/23", 0, ()),
("2009/199240/234", 0, ()),
("hello world", 0, ()),
],
)
def test_analyze_valid_and_invalid_za_company_registrations(
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(
"registration_number, expected",
[
("2009/199240/23", True),
("2014/256030/07", True),
("CK2001/123456", True),
("K2010/654321", True),
("99/199240/23", False),
("2009/19924/23", False),
("AB2001/123456", False),
],
)
def test_validate_result(registration_number, expected, recognizer):
assert recognizer.validate_result(registration_number) is expected