-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtest_example.py
More file actions
61 lines (47 loc) · 1.58 KB
/
test_example.py
File metadata and controls
61 lines (47 loc) · 1.58 KB
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
#!/usr/bin/env python3
"""
Test for the direct_context example.
This example runs synchronously and tests the DirectContext API for:
- Adding files to an index
- Searching indexed files
- Using search_and_ask for Q&A
- Exporting and importing state
"""
import subprocess
import sys
from pathlib import Path
def main():
"""Run the direct_context example and verify it completes successfully."""
# Get the package directory and run from parent so module execution works
package_dir = Path(__file__).parent
context_dir = package_dir.parent
print("Running: python -m direct_context")
print(f"Working directory: {context_dir}")
result = subprocess.run(
[sys.executable, "-m", "direct_context"],
capture_output=True,
text=True,
timeout=120, # 2 minutes should be plenty
cwd=str(context_dir),
)
# Print output for debugging
if result.stdout:
print("=== stdout ===")
print(result.stdout)
if result.stderr:
print("=== stderr ===")
print(result.stderr)
# Verify success
if result.returncode != 0:
print(f"❌ Example failed with exit code {result.returncode}")
sys.exit(1)
# Verify expected output
if "=== Sample Complete ===" not in result.stdout:
print("❌ Example did not complete successfully (missing completion message)")
sys.exit(1)
if "Search results:" not in result.stdout:
print("❌ Example did not produce search results")
sys.exit(1)
print("✅ direct_context example passed")
if __name__ == "__main__":
main()