-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtets_script.py
More file actions
158 lines (133 loc) · 4.23 KB
/
tets_script.py
File metadata and controls
158 lines (133 loc) · 4.23 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
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
#!/usr/bin/env python3
# this is a script made for testing weather all the functions are working correctly or not
# you might see a sharp spike while executing this wcript expecially the function for indexing code base uses lot of cpu
import os
import sys
import traceback
from tools import (
initialize_vectorstore,
change_directory,
read_file,
search_code,
list_directory,
run_command,
add_to_vectorstore,
search_vectorstore,
index_codebase
)
def safe_test(func_name, func, *args, **kwargs):
print(f"\n{'-'*20}")
print(f"Testing {func_name}")
print(f"{'-'*10}")
try:
result = func(*args, **kwargs)
print(f" The Function{func_name} is working correctly")
print(f"Result: {result}")
return True
except Exception as e:
print(f"ERROR detected in {func_name}: {str(e)}")
print(f"traceback: {traceback.format_exc()}")
return False
def main():
print("starting testing of all tools.py functions")
# Store original directory
original_dir = os.getcwd()
# Test results
test_results = {}
# 1. Test initialize_vectorstore (simple function)
test_results['initialize_vectorstore'] = safe_test(
'initialize_vectorstore',
initialize_vectorstore
)
# 2. Test list_directory with current directory
test_results['list_directory'] = safe_test(
'list_directory',
list_directory
)
# 3. Test change_directory (test with current directory)
test_results['change_directory'] = safe_test(
'change_directory',
change_directory,
"."
)
# 4. Test read_file with this script
test_results['read_file'] = safe_test(
'read_file',
read_file,
__file__
)
# 5. Test search_code (safe grep command)
test_results['search_code'] = safe_test(
'search_code',
search_code,
"def",
"."
)
# 6. Test run_command (safe command)
test_results['run_command'] = safe_test(
'run_command',
run_command,
"echo 'Hello World'"
)
# the main file used for indexing codebases
print(f"\n{'-'*20}")
print("Testing add_to_vectorstore (potentially problematic)")
print(f"{'-'*10}")
# Create a simple test file first
test_file_path = "test_content.txt"
try:
with open(test_file_path, 'w') as f:
f.write("lorem ipsum dolor sit amet, consectetur adipiscing elit.")
test_results['add_to_vectorstore'] = safe_test(
'add_to_vectorstore',
add_to_vectorstore,
test_file_path
)
# Clean up test file
if os.path.exists(test_file_path):
os.remove(test_file_path)
except Exception as e:
print(f" Could not create test file for add_to_vectorstore: {e}")
test_results['add_to_vectorstore'] = False
if test_results.get('add_to_vectorstore', False):
test_results['search_vectorstore'] = safe_test(
'search_vectorstore',
search_vectorstore,
"test file"
)
else:
print(f"\n{'-'*20}")
print("Skipping search_vectorstore (add_to_vectorstore failed)")
print(f"{'-'*10}")
test_results['search_vectorstore'] = False
# 9. Test index_codebase (might be problematic too)
# We'll test it with a small directory to avoid processing too much
test_results['index_codebase'] = safe_test(
'index_codebase',
index_codebase,
"." # Current directory
)
# Summary
print(f"\n{'='*60}")
print("summary of test results")
print(f"{'='*60}")
passed = 0
failed = 0
for func_name, result in test_results.items():
status = "PASS" if result else "FAIL"
print(f"{func_name:<25}: {status}")
if result:
passed += 1
else:
failed += 1
print(f"\nTotal functions tested: {len(test_results)}")
print(f"Passed: {passed}")
print(f"Failed: {failed}")
if failed > 0:
print(f"\n {failed} function(s) have issues that need to be fixed.")
sys.exit(1)
else:
print(f"\n All functions are working correctly you can proceed further !")
sys.exit(0)
if __name__ == "__main__":
main()