File size: 2,358 Bytes
68f0a4a
 
 
 
48ed660
68f0a4a
 
 
 
 
 
 
 
 
 
 
 
48ed660
 
 
 
 
 
 
 
 
 
 
 
68f0a4a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48ed660
68f0a4a
 
 
48ed660
68f0a4a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from candidate_scanner import scan_unmasked_candidates
from test_cases.legal_regression_cases import (
    CANDIDATE_SCANNER_TEXT,
    EXPECTED_CANDIDATES,
    EXPECTED_CANDIDATE_TYPES,
    NEGATIVE_VALUES,
)


def test_candidate_scanner_finds_expected_reference_like_values():
    rows = scan_unmasked_candidates(CANDIDATE_SCANNER_TEXT, analyzer_results=[])
    found = {row["text"] for row in rows}

    missing = EXPECTED_CANDIDATES - found
    assert not missing, f"Expected candidates were not found: {sorted(missing)}"


def test_candidate_scanner_assigns_expected_reference_categories():
    rows = scan_unmasked_candidates(CANDIDATE_SCANNER_TEXT, analyzer_results=[])
    by_text = {row["text"]: row["entity_type"] for row in rows}

    mismatches = {
        value: {"expected": expected_type, "actual": by_text.get(value)}
        for value, expected_type in EXPECTED_CANDIDATE_TYPES.items()
        if by_text.get(value) != expected_type
    }
    assert not mismatches, f"Candidate type mismatches: {mismatches}"


def test_candidate_scanner_does_not_suggest_known_false_positives():
    rows = scan_unmasked_candidates(CANDIDATE_SCANNER_TEXT, analyzer_results=[])
    found = {row["text"] for row in rows}

    unexpected = NEGATIVE_VALUES & found
    assert not unexpected, f"False-positive values were suggested: {sorted(unexpected)}"


def test_candidate_scanner_preserves_context_by_returning_value_only():
    rows = scan_unmasked_candidates(CANDIDATE_SCANNER_TEXT, analyzer_results=[])
    found = {row["text"] for row in rows}

    assert "reparatienummer REP-2026-4410" not in found
    assert "intern incidentnummer INC-2026-0912" not in found
    assert "kenteken XX123X" not in found
    assert "KvK-nummer vennootschap: 76543210" not in found
    assert "REP-2026-4410" in found
    assert "INC-2026-0912" in found
    assert "XX123X" in found
    assert "76543210" in found


def test_candidate_scanner_respects_existing_analyzer_spans():
    start = CANDIDATE_SCANNER_TEXT.index("REP-2026-4410")
    end = start + len("REP-2026-4410")

    class ExistingResult:
        pass

    existing = ExistingResult()
    existing.start = start
    existing.end = end

    rows = scan_unmasked_candidates(CANDIDATE_SCANNER_TEXT, analyzer_results=[existing])
    found = {row["text"] for row in rows}

    assert "REP-2026-4410" not in found