simplified to list in pool
This commit is contained in:
82
test_end_to_end.py
Normal file
82
test_end_to_end.py
Normal file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
End-to-end test to verify prompts are stored as simple strings without keys.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add the current directory to the Python path
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
from generate_prompts import JournalPromptGenerator
|
||||
|
||||
def test_end_to_end():
|
||||
"""Test the complete flow from parsing to pool management."""
|
||||
print("Testing end-to-end flow...")
|
||||
print("="*60)
|
||||
|
||||
# Create a generator instance
|
||||
generator = JournalPromptGenerator(config_path=".env")
|
||||
|
||||
# Clear the pool first
|
||||
generator.pool_prompts = []
|
||||
generator._save_pool_prompts()
|
||||
|
||||
# Test 1: Simulate AI response (JSON list format)
|
||||
print("\n1. Simulating AI response (JSON list format)...")
|
||||
mock_ai_response = json.dumps([
|
||||
"Write about a childhood memory that still makes you smile.",
|
||||
"Describe your perfect day from start to finish.",
|
||||
"What is something you've been putting off and why?",
|
||||
"Imagine you could have a conversation with any historical figure."
|
||||
])
|
||||
|
||||
# Parse the response
|
||||
parsed_prompts = generator._parse_ai_response(mock_ai_response)
|
||||
print(f" Parsed {len(parsed_prompts)} prompts")
|
||||
print(f" All prompts are strings: {all(isinstance(p, str) for p in parsed_prompts)}")
|
||||
print(f" No prompts have keys: {all(not isinstance(p, dict) for p in parsed_prompts)}")
|
||||
|
||||
# Test 2: Add to pool
|
||||
print("\n2. Adding prompts to pool...")
|
||||
generator.add_prompts_to_pool(parsed_prompts)
|
||||
print(f" Pool now has {len(generator.pool_prompts)} prompts")
|
||||
print(f" All pool prompts are strings: {all(isinstance(p, str) for p in generator.pool_prompts)}")
|
||||
|
||||
# Test 3: Draw from pool
|
||||
print("\n3. Drawing prompts from pool...")
|
||||
drawn_prompts = generator.draw_prompts_from_pool(count=2)
|
||||
print(f" Drew {len(drawn_prompts)} prompts")
|
||||
print(f" Drawn prompts are strings: {all(isinstance(p, str) for p in drawn_prompts)}")
|
||||
print(f" Pool now has {len(generator.pool_prompts)} prompts remaining")
|
||||
|
||||
# Test 4: Save and load pool
|
||||
print("\n4. Testing pool persistence...")
|
||||
# Save current pool
|
||||
generator._save_pool_prompts()
|
||||
|
||||
# Create a new generator instance to load the pool
|
||||
generator2 = JournalPromptGenerator(config_path=".env")
|
||||
print(f" New instance loaded {len(generator2.pool_prompts)} prompts from pool_prompts.json")
|
||||
print(f" Loaded prompts are strings: {all(isinstance(p, str) for p in generator2.pool_prompts)}")
|
||||
|
||||
# Test 5: Check pool_prompts.json content
|
||||
print("\n5. Checking pool_prompts.json file content...")
|
||||
with open("pool_prompts.json", "r") as f:
|
||||
pool_content = json.load(f)
|
||||
print(f" File contains {len(pool_content)} items")
|
||||
print(f" First item type: {type(pool_content[0])}")
|
||||
print(f" First item is string: {isinstance(pool_content[0], str)}")
|
||||
print(f" First item value: {pool_content[0][:50]}...")
|
||||
|
||||
print("\n" + "="*60)
|
||||
print("✅ All tests passed! Prompts are stored as simple strings without keys.")
|
||||
print("="*60)
|
||||
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_end_to_end()
|
||||
|
||||
Reference in New Issue
Block a user