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.5 KiB
Python
56 lines
1.5 KiB
Python
import pytest
|
|
|
|
from presidio_analyzer.predefined_recognizers import ZaLicensePlateRecognizer
|
|
from tests import assert_result
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def recognizer():
|
|
return ZaLicensePlateRecognizer()
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def entities():
|
|
return ["ZA_LICENSE_PLATE"]
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"text, expected_len, expected_positions",
|
|
[
|
|
("KD93GKGP", 1, ((0, 8),)),
|
|
("PMG017GP", 1, ((0, 8),)),
|
|
("BJ47HRZN", 1, ((0, 8),)),
|
|
("DK 28 LF GP", 1, ((0, 11),)),
|
|
("CC 75 CX ZN", 1, ((0, 11),)),
|
|
("GET 103 WP", 1, ((0, 10),)),
|
|
("015 SBZ EC", 1, ((0, 10),)),
|
|
("Licence plate MT77GJGP registered.", 1, ((14, 22),)),
|
|
("YES", 0, ()),
|
|
("1234567890", 0, ()),
|
|
("hello world", 0, ()),
|
|
],
|
|
)
|
|
def test_analyze_valid_and_invalid_za_license_plates(
|
|
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(
|
|
"plate, expected",
|
|
[
|
|
("KD93GKGP", True),
|
|
("DK28LFGP", True),
|
|
("CC75CXZN", True),
|
|
("GET103WP", True),
|
|
("015SBZEC", True),
|
|
("YES", False),
|
|
("1234GP", False),
|
|
],
|
|
)
|
|
def test_validate_result(plate, expected, recognizer):
|
|
assert recognizer.validate_result(plate) is expected
|