""" Basic functionality tests for AI Personas system Run with: pytest tests/test_basic_functionality.py or: python tests/test_basic_functionality.py """ import sys from pathlib import Path # Add src to path sys.path.insert(0, str(Path(__file__).parent.parent)) from src.personas.database import PersonaDatabase from src.context.database import ContextDatabase def test_personas_load(): """Test that personas load correctly""" db = PersonaDatabase() personas = db.get_all_personas() assert len(personas) == 6, f"Expected 6 personas, got {len(personas)}" # Check specific personas exist expected_ids = [ "sarah_chen", "marcus_thompson", "elena_rodriguez", "james_obrien", "priya_patel", "david_kim", ] for persona_id in expected_ids: persona = db.get_persona(persona_id) assert persona is not None, f"Persona {persona_id} not found" assert persona.name, f"Persona {persona_id} has no name" assert persona.role, f"Persona {persona_id} has no role" print("✓ All 6 personas loaded successfully") def test_persona_attributes(): """Test that personas have required attributes""" db = PersonaDatabase() sarah = db.get_persona("sarah_chen") assert sarah is not None assert sarah.persona_id == "sarah_chen" assert sarah.name == "Sarah Chen" assert sarah.demographics.age > 0 assert len(sarah.psychographics.core_values) > 0 assert len(sarah.behavioral_profile.typical_concerns) > 0 assert sarah.background_story print("✓ Persona attributes validated") def test_contexts_load(): """Test that contexts load correctly""" db = ContextDatabase() contexts = db.get_all_contexts() # At least one context should exist assert len(contexts) >= 1, "No contexts found" # Check downtown_district exists downtown = db.get_context("downtown_district") assert downtown is not None, "downtown_district context not found" assert downtown.built_environment.name assert downtown.social_context.median_income > 0 print(f"✓ {len(contexts)} context(s) loaded successfully") def test_persona_search(): """Test persona search functionality""" db = PersonaDatabase() # Search by keyword results = db.search_personas("planner") assert len(results) > 0, "Search for 'planner' found no results" # Search by role results = db.get_personas_by_role("developer") assert len(results) > 0, "No developers found" print("✓ Persona search working") def test_persona_filtering(): """Test persona filtering by criteria""" db = PersonaDatabase() # Filter by age young = db.get_personas_by_criteria(max_age=35) assert len(young) > 0, "No young personas found" # Filter by environmental concern environmentalists = db.get_personas_by_criteria(min_environmental_concern=8) assert len(environmentalists) > 0, "No environmentally concerned personas found" print("✓ Persona filtering working") def test_context_summary(): """Test that context summaries generate""" db = ContextDatabase() context = db.get_default_context() if context: summary = context.get_context_summary() assert len(summary) > 100, "Context summary too short" assert "LOCATION" in summary print("✓ Context summary generation working") else: print("⚠ No contexts available to test summary") def test_persona_summary(): """Test that persona summaries generate""" db = PersonaDatabase() sarah = db.get_persona("sarah_chen") summary = sarah.get_context_summary() assert len(summary) > 100, "Persona summary too short" assert "Sarah Chen" in summary assert "Urban Planner" in summary print("✓ Persona summary generation working") def run_all_tests(): """Run all tests""" print("\n" + "=" * 70) print("Running Basic Functionality Tests") print("=" * 70 + "\n") tests = [ test_personas_load, test_persona_attributes, test_contexts_load, test_persona_search, test_persona_filtering, test_context_summary, test_persona_summary, ] failed = 0 for test in tests: try: test() except AssertionError as e: print(f"✗ {test.__name__} FAILED: {e}") failed += 1 except Exception as e: print(f"✗ {test.__name__} ERROR: {e}") failed += 1 print("\n" + "=" * 70) if failed == 0: print("✓ All tests passed!") else: print(f"✗ {failed} test(s) failed") print("=" * 70 + "\n") return failed == 0 if __name__ == "__main__": success = run_all_tests() sys.exit(0 if success else 1)