Spaces:
Sleeping
Sleeping
File size: 4,817 Bytes
514b626 |
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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
"""
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)
|