OFPBadWord / private /tests /verify_setup.py
BladeSzaSza's picture
Organize project: Move development files to private/ folder
9fb298e
#!/usr/bin/env python
"""
Setup verification script for OFP Bad Word Sentinel
Run this to verify all components are installed correctly
"""
import sys
import importlib
def check_module(module_name, display_name=None):
"""Check if a module can be imported"""
display = display_name or module_name
try:
importlib.import_module(module_name)
print(f"βœ“ {display} is installed")
return True
except ImportError:
print(f"βœ— {display} is NOT installed")
return False
def check_project_files():
"""Check if project files exist"""
import os
files = [
'app.py',
'requirements.txt',
'README.md',
'config/config.yaml',
'config/wordlist.txt',
'src/__init__.py',
'src/models.py',
'src/ofp_client.py',
'src/profanity_detector.py',
'src/sentinel.py',
'tests/test_profanity.py',
'tests/test_ofp_client.py',
'tests/test_sentinel.py'
]
print("\nProject Files:")
all_exist = True
for file in files:
if os.path.exists(file):
print(f"βœ“ {file}")
else:
print(f"βœ— {file} MISSING")
all_exist = False
return all_exist
def test_profanity_detector():
"""Test profanity detector functionality"""
try:
from src.profanity_detector import ProfanityDetector
detector = ProfanityDetector()
# Test basic detection
assert detector.is_profane("This is shit"), "Failed to detect profanity"
assert not detector.is_profane("This is nice"), "False positive"
print("\nProfanity Detector:")
print("βœ“ Basic detection works")
print("βœ“ No false positives")
return True
except Exception as e:
print(f"\nβœ— Profanity detector test failed: {e}")
return False
def test_ofp_models():
"""Test OFP models"""
try:
from src.models import Envelope, DialogEvent, create_envelope
# Create test envelope
envelope = create_envelope(
conversation_id="test:123",
speaker_uri="tag:test,2025:sentinel",
events=[]
)
# Convert to JSON and back
json_str = envelope.to_json()
print("\nOFP Models:")
print("βœ“ Envelope creation works")
print("βœ“ JSON serialization works")
return True
except Exception as e:
print(f"\nβœ— OFP models test failed: {e}")
return False
def test_sentinel():
"""Test sentinel initialization"""
try:
from src.sentinel import BadWordSentinel
from src.profanity_detector import ProfanityDetector
detector = ProfanityDetector()
sentinel = BadWordSentinel(
speaker_uri="tag:test,2025:sentinel",
service_url="http://test.com",
profanity_detector=detector,
convener_uri="tag:test,2025:convener",
convener_url="http://test.com"
)
status = sentinel.get_status()
print("\nSentinel:")
print("βœ“ Sentinel initialization works")
print("βœ“ Status retrieval works")
return True
except Exception as e:
print(f"\nβœ— Sentinel test failed: {e}")
return False
def main():
"""Run all verification checks"""
print("=" * 60)
print("OFP Bad Word Sentinel - Setup Verification")
print("=" * 60)
print("\nRequired Dependencies:")
deps_ok = all([
check_module('gradio'),
check_module('better_profanity', 'better-profanity'),
check_module('apscheduler', 'APScheduler'),
check_module('requests'),
check_module('yaml', 'pyyaml')
])
files_ok = check_project_files()
detector_ok = test_profanity_detector()
models_ok = test_ofp_models()
sentinel_ok = test_sentinel()
print("\n" + "=" * 60)
if all([deps_ok, files_ok, detector_ok, models_ok, sentinel_ok]):
print("βœ“ ALL CHECKS PASSED")
print("\nYou're ready to run the sentinel!")
print("Run: python app.py")
sys.exit(0)
else:
print("βœ— SOME CHECKS FAILED")
print("\nPlease fix the issues above before running.")
print("Try: pip install -r requirements.txt")
sys.exit(1)
if __name__ == '__main__':
main()