-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_all.py
More file actions
68 lines (56 loc) · 1.98 KB
/
Copy pathtest_all.py
File metadata and controls
68 lines (56 loc) · 1.98 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
61
62
63
64
65
66
67
68
"""
Manual test script — run each section after committing changes.
Usage:
python test_all.py # run all tests
python test_all.py --unit # only unit tests
python test_all.py --live # live integration (requires opencode binary)
"""
import subprocess
import sys
def run(cmd: str, label: str) -> int:
print(f"\n{'=' * 60}")
print(f" {label}")
print(f"{'=' * 60}")
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
print(result.stdout)
if result.returncode != 0:
print(result.stderr)
print(f" FAILED (exit code {result.returncode})")
else:
print(" OK")
return result.returncode
def main() -> int:
tests = []
if "--unit" in sys.argv or not any(
a.startswith("--") for a in sys.argv[1:]
):
tests.append(("python -m pytest tests/ -v", "Unit tests (17 tests)"))
if "--live" in sys.argv or not any(
a.startswith("--") for a in sys.argv[1:]
):
tests.extend(
[
(
"python -c \"from opencode import opencode; r = opencode('say hi', keep=True); print('R1:', r); r2 = opencode('what did you say?', keep=True); print('R2:', r2); r3 = opencode('translate to russian', keep=False); print('R3:', r3)\"", # noqa: E501
"Keep mode (multi-turn)",
),
(
"python -c \"from opencode import opencode; r = opencode('create file _test_auto.txt with content AutoTest', auto_tools=True, keep=True); print('R:', r)\"", # noqa: E501
"Auto-tools (file creation)",
),
]
)
failed = 0
for cmd, label in tests:
rc = run(cmd, label)
if rc != 0:
failed += 1
print(f"\n{'=' * 60}")
if failed:
print(f" {failed} test(s) FAILED")
else:
print(" All tests passed!")
print(f"{'=' * 60}")
return failed
if __name__ == "__main__":
sys.exit(main())