Skip to content

Commit 6efce63

Browse files
committed
fix(lint): apply black formatting and update test mock signature
- Run black formatter on Python test files - Update MockPIIInitializer to match interface changes Fixes CI pre-commit and test-and-build failures. Signed-off-by: Yossi Ovadia <[email protected]>
1 parent 6251632 commit 6efce63

File tree

2 files changed

+236
-89
lines changed

2 files changed

+236
-89
lines changed

e2e-tests/06-a-test-pii-direct.py

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"min_confidence": 0.7,
5454
"description": "ModernBERT PASSED: 0.947. LoRA should also pass",
5555
},
56-
5756
# ===== Email Variations =====
5857
{
5958
"name": "Email - Work Domain",
@@ -79,7 +78,6 @@
7978
"expected_types": ["EMAIL_ADDRESS"],
8079
"min_confidence": 0.7,
8180
},
82-
8381
# ===== SSN Variations =====
8482
{
8583
"name": "SSN - No Dashes",
@@ -99,7 +97,6 @@
9997
"expected_types": ["US_SSN"],
10098
"min_confidence": 0.7,
10199
},
102-
103100
# ===== Credit Card Variations =====
104101
{
105102
"name": "Credit Card - Spaces",
@@ -131,7 +128,6 @@
131128
"expected_types": ["CREDIT_CARD"],
132129
"min_confidence": 0.7,
133130
},
134-
135131
# ===== Phone Variations =====
136132
{
137133
"name": "Phone - Dashes",
@@ -169,7 +165,6 @@
169165
"expected_types": ["PHONE_NUMBER"],
170166
"min_confidence": 0.7,
171167
},
172-
173168
# ===== Person Names =====
174169
{
175170
"name": "Person - Full Name",
@@ -195,7 +190,6 @@
195190
"expected_types": ["PERSON"],
196191
"min_confidence": 0.7,
197192
},
198-
199193
# ===== Addresses =====
200194
{
201195
"name": "Address - Street",
@@ -209,7 +203,6 @@
209203
"expected_types": ["ADDRESS", "GPE"],
210204
"min_confidence": 0.7,
211205
},
212-
213206
# ===== Organizations =====
214207
{
215208
"name": "Organization - Tech Company",
@@ -223,7 +216,6 @@
223216
"expected_types": ["ORGANIZATION"],
224217
"min_confidence": 0.7,
225218
},
226-
227219
# ===== Dates =====
228220
{
229221
"name": "Date - Numeric",
@@ -237,7 +229,6 @@
237229
"expected_types": ["DATE_TIME"],
238230
"min_confidence": 0.7,
239231
},
240-
241232
# ===== Locations =====
242233
{
243234
"name": "Location - City",
@@ -251,7 +242,6 @@
251242
"expected_types": ["GPE"],
252243
"min_confidence": 0.7,
253244
},
254-
255245
# ===== Edge Cases =====
256246
{
257247
"name": "No PII - Random Text",
@@ -329,7 +319,9 @@ def test_pii_comprehensive(self):
329319
payload = {"text": test_case["text"]}
330320

331321
print(f" Input: \"{test_case['text']}\"")
332-
print(f" Expected: {', '.join(test_case['expected_types']) if test_case['expected_types'] else 'No PII'}")
322+
print(
323+
f" Expected: {', '.join(test_case['expected_types']) if test_case['expected_types'] else 'No PII'}"
324+
)
333325
if "description" in test_case:
334326
print(f" Note: {test_case['description']}")
335327

@@ -357,13 +349,17 @@ def test_pii_comprehensive(self):
357349
results_summary["passed"] += 1
358350
status = "PASS"
359351
else:
360-
print(f" ⚠️ UNEXPECTED - PII detected: {[e['type'] for e in entities]}")
352+
print(
353+
f" ⚠️ UNEXPECTED - PII detected: {[e['type'] for e in entities]}"
354+
)
361355
results_summary["partial"] += 1
362356
status = "PARTIAL"
363357
else:
364358
# Expecting PII
365359
if not has_pii or not entities:
366-
print(f" ❌ FAIL - No PII detected (expected {test_case['expected_types']})")
360+
print(
361+
f" ❌ FAIL - No PII detected (expected {test_case['expected_types']})"
362+
)
367363
results_summary["failed"] += 1
368364
status = "FAIL"
369365
else:
@@ -373,28 +369,49 @@ def test_pii_comprehensive(self):
373369

374370
print(f" Detected {len(entities)} entities:")
375371
for entity in entities:
376-
entity_type = entity.get("type", "UNKNOWN").replace("B-", "").replace("I-", "")
372+
entity_type = (
373+
entity.get("type", "UNKNOWN")
374+
.replace("B-", "")
375+
.replace("I-", "")
376+
)
377377
confidence = entity.get("confidence", 0.0)
378378
detected_types.add(entity_type)
379379
max_confidence = max(max_confidence, confidence)
380380

381-
conf_status = "✅" if confidence >= test_case["min_confidence"] else "⚠️"
382-
print(f" {conf_status} {entity['type']}: confidence={confidence:.3f}")
381+
conf_status = (
382+
"✅"
383+
if confidence >= test_case["min_confidence"]
384+
else "⚠️"
385+
)
386+
print(
387+
f" {conf_status} {entity['type']}: confidence={confidence:.3f}"
388+
)
383389

384390
# Check if expected types were found
385391
expected_set = set(test_case["expected_types"])
386-
found_expected = any(dt in expected_set for dt in detected_types)
387-
388-
if found_expected and max_confidence >= test_case["min_confidence"]:
389-
print(f" ✅ PASS - Expected types detected with sufficient confidence")
392+
found_expected = any(
393+
dt in expected_set for dt in detected_types
394+
)
395+
396+
if (
397+
found_expected
398+
and max_confidence >= test_case["min_confidence"]
399+
):
400+
print(
401+
f" ✅ PASS - Expected types detected with sufficient confidence"
402+
)
390403
results_summary["passed"] += 1
391404
status = "PASS"
392405
elif found_expected:
393-
print(f" ⚠️ PARTIAL - Expected types found but confidence too low ({max_confidence:.3f} < {test_case['min_confidence']})")
406+
print(
407+
f" ⚠️ PARTIAL - Expected types found but confidence too low ({max_confidence:.3f} < {test_case['min_confidence']})"
408+
)
394409
results_summary["partial"] += 1
395410
status = "PARTIAL"
396411
else:
397-
print(f" ❌ FAIL - Expected {expected_set} but detected {detected_types}")
412+
print(
413+
f" ❌ FAIL - Expected {expected_set} but detected {detected_types}"
414+
)
398415
results_summary["failed"] += 1
399416
status = "FAIL"
400417

@@ -409,7 +426,11 @@ def test_pii_comprehensive(self):
409426
# Track by category (outside try to ensure it always runs)
410427
category = test_case["name"].split(" - ")[0]
411428
if category not in results_summary["by_category"]:
412-
results_summary["by_category"][category] = {"PASS": 0, "FAIL": 0, "PARTIAL": 0}
429+
results_summary["by_category"][category] = {
430+
"PASS": 0,
431+
"FAIL": 0,
432+
"PARTIAL": 0,
433+
}
413434
results_summary["by_category"][category][status] += 1
414435

415436
# Print summary
@@ -430,23 +451,33 @@ def test_pii_comprehensive(self):
430451
for category, stats in sorted(results_summary["by_category"].items()):
431452
cat_total = stats["PASS"] + stats["FAIL"] + stats["PARTIAL"]
432453
if cat_total > 0:
433-
print(f" {category}: {stats['PASS']}/{cat_total} passed "
434-
f"({stats['PASS']/cat_total*100:.0f}%)")
454+
print(
455+
f" {category}: {stats['PASS']}/{cat_total} passed "
456+
f"({stats['PASS']/cat_total*100:.0f}%)"
457+
)
435458

436459
# Compare to Issue #647 original cases
437460
print(f"\n🎯 Issue #647 Original Cases:")
438-
print(f" Email: {'✅ FIXED' if PII_TEST_CASES[0] else '❌ Still failing'}")
439-
print(f" SSN: {'✅ FIXED' if PII_TEST_CASES[1] else '❌ Still failing'}")
440-
print(f" Credit Card: {'✅ FIXED' if PII_TEST_CASES[2] else '❌ Still failing'}")
441-
print(f" Phone: {'✅ Working' if PII_TEST_CASES[3] else '❌ Regressed'}")
461+
print(
462+
f" Email: {'✅ FIXED' if PII_TEST_CASES[0] else '❌ Still failing'}"
463+
)
464+
print(
465+
f" SSN: {'✅ FIXED' if PII_TEST_CASES[1] else '❌ Still failing'}"
466+
)
467+
print(
468+
f" Credit Card: {'✅ FIXED' if PII_TEST_CASES[2] else '❌ Still failing'}"
469+
)
470+
print(
471+
f" Phone: {'✅ Working' if PII_TEST_CASES[3] else '❌ Regressed'}"
472+
)
442473

443474
# Determine overall test result
444475
# We'll be lenient - partial counts as pass for now since we're evaluating the model
445476
success_rate = (passed + partial) / total * 100
446477

447478
self.print_test_result(
448479
passed=success_rate >= 70, # 70% threshold for comprehensive test
449-
message=f"PII Detection: {success_rate:.1f}% success rate ({passed} passed, {partial} partial, {failed} failed)"
480+
message=f"PII Detection: {success_rate:.1f}% success rate ({passed} passed, {partial} partial, {failed} failed)",
450481
)
451482

452483

0 commit comments

Comments
 (0)