Spaces:
Running
on
Zero
Running
on
Zero
File size: 4,317 Bytes
43bfad5 |
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
#!/usr/bin/env python3
"""
Demonstration script showing how to run a single test example.
This script shows how to use the run_cli_redact function directly
to test a specific CLI example.
"""
import os
import shutil
import sys
import tempfile
# Add the parent directory to the path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from test import run_cli_redact
def demo_pdf_redaction():
"""Demonstrate how to run a single PDF redaction test."""
print("=== Demo: PDF Redaction with Default Settings ===")
# Set up paths
script_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)), "cli_redact.py"
)
input_file = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"example_data",
"example_of_emails_sent_to_a_professor_before_applying.pdf",
)
output_dir = tempfile.mkdtemp(prefix="demo_output_")
print(f"Script: {script_path}")
print(f"Input: {input_file}")
print(f"Output: {output_dir}")
# Check if files exist
if not os.path.isfile(script_path):
print(f"❌ Script not found: {script_path}")
return False
if not os.path.isfile(input_file):
print(f"❌ Input file not found: {input_file}")
print(
"Make sure you have the example data files in the example_data/ directory"
)
return False
try:
# Run the test
print("\nRunning PDF redaction with default settings...")
result = run_cli_redact(
script_path=script_path, input_file=input_file, output_dir=output_dir
)
if result:
print("✅ Test completed successfully!")
print(f"Check the output directory for results: {output_dir}")
else:
print("❌ Test failed!")
return result
finally:
# Clean up
if os.path.exists(output_dir):
shutil.rmtree(output_dir)
print(f"Cleaned up: {output_dir}")
def demo_csv_anonymisation():
"""Demonstrate how to run a CSV anonymisation test."""
print("\n=== Demo: CSV Anonymisation ===")
# Set up paths
script_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)), "cli_redact.py"
)
input_file = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"example_data",
"combined_case_notes.csv",
)
output_dir = tempfile.mkdtemp(prefix="demo_output_")
print(f"Script: {script_path}")
print(f"Input: {input_file}")
print(f"Output: {output_dir}")
# Check if files exist
if not os.path.isfile(script_path):
print(f"❌ Script not found: {script_path}")
return False
if not os.path.isfile(input_file):
print(f"❌ Input file not found: {input_file}")
print(
"Make sure you have the example data files in the example_data/ directory"
)
return False
try:
# Run the test
print("\nRunning CSV anonymisation...")
result = run_cli_redact(
script_path=script_path,
input_file=input_file,
output_dir=output_dir,
text_columns=["Case Note", "Client"],
anon_strategy="replace_redacted",
)
if result:
print("✅ Test completed successfully!")
print(f"Check the output directory for results: {output_dir}")
else:
print("❌ Test failed!")
return result
finally:
# Clean up
if os.path.exists(output_dir):
shutil.rmtree(output_dir)
print(f"Cleaned up: {output_dir}")
if __name__ == "__main__":
print("CLI Redaction Test Demo")
print("=" * 50)
print("This script demonstrates how to run individual tests.")
print("=" * 50)
# Run the demos
success1 = demo_pdf_redaction()
success2 = demo_csv_anonymisation()
print("\n" + "=" * 50)
print("Demo Summary")
print("=" * 50)
print(f"PDF Redaction: {'✅ PASSED' if success1 else '❌ FAILED'}")
print(f"CSV Anonymisation: {'✅ PASSED' if success2 else '❌ FAILED'}")
overall_success = success1 and success2
print(f"\nOverall: {'✅ PASSED' if overall_success else '❌ FAILED'}")
sys.exit(0 if overall_success else 1)
|