Repository navigation
Expand file tree
/
Copy pathtest_repomap.py
More file actions
217 lines (172 loc) · 6.89 KB
/
Copy pathtest_repomap.py
File metadata and controls
217 lines (172 loc) · 6.89 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import os
import unittest
from aider.dump import dump # noqa: F401
from aider.io import InputOutput
from aider.models import Model
from aider.repomap import RepoMap
from aider.utils import IgnorantTemporaryDirectory
class TestRepoMap(unittest.TestCase):
def setUp(self):
self.GPT35 = Model("gpt-3.5-turbo")
def test_get_repo_map(self):
# Create a temporary directory with sample files for testing
test_files = [
"test_file1.py",
"test_file2.py",
"test_file3.md",
"test_file4.json",
]
with IgnorantTemporaryDirectory() as temp_dir:
for file in test_files:
with open(os.path.join(temp_dir, file), "w") as f:
f.write("")
io = InputOutput()
repo_map = RepoMap(main_model=self.GPT35, root=temp_dir, io=io)
other_files = [os.path.join(temp_dir, file) for file in test_files]
result = repo_map.get_repo_map([], other_files)
# Check if the result contains the expected tags map
self.assertIn("test_file1.py", result)
self.assertIn("test_file2.py", result)
self.assertIn("test_file3.md", result)
self.assertIn("test_file4.json", result)
# close the open cache files, so Windows won't error
del repo_map
def test_get_repo_map_with_identifiers(self):
# Create a temporary directory with a sample Python file containing identifiers
test_file1 = "test_file_with_identifiers.py"
file_content1 = """\
class MyClass:
def my_method(self, arg1, arg2):
return arg1 + arg2
def my_function(arg1, arg2):
return arg1 * arg2
"""
test_file2 = "test_file_import.py"
file_content2 = """\
from test_file_with_identifiers import MyClass
obj = MyClass()
print(obj.my_method(1, 2))
print(my_function(3, 4))
"""
test_file3 = "test_file_pass.py"
file_content3 = "pass"
with IgnorantTemporaryDirectory() as temp_dir:
with open(os.path.join(temp_dir, test_file1), "w") as f:
f.write(file_content1)
with open(os.path.join(temp_dir, test_file2), "w") as f:
f.write(file_content2)
with open(os.path.join(temp_dir, test_file3), "w") as f:
f.write(file_content3)
io = InputOutput()
repo_map = RepoMap(main_model=self.GPT35, root=temp_dir, io=io)
other_files = [
os.path.join(temp_dir, test_file1),
os.path.join(temp_dir, test_file2),
os.path.join(temp_dir, test_file3),
]
result = repo_map.get_repo_map([], other_files)
# Check if the result contains the expected tags map with identifiers
self.assertIn("test_file_with_identifiers.py", result)
self.assertIn("MyClass", result)
self.assertIn("my_method", result)
self.assertIn("my_function", result)
self.assertIn("test_file_pass.py", result)
# close the open cache files, so Windows won't error
del repo_map
def test_get_repo_map_all_files(self):
test_files = [
"test_file0.py",
"test_file1.txt",
"test_file2.md",
"test_file3.json",
"test_file4.html",
"test_file5.css",
"test_file6.js",
]
with IgnorantTemporaryDirectory() as temp_dir:
for file in test_files:
with open(os.path.join(temp_dir, file), "w") as f:
f.write("")
repo_map = RepoMap(main_model=self.GPT35, root=temp_dir, io=InputOutput())
other_files = [os.path.join(temp_dir, file) for file in test_files]
result = repo_map.get_repo_map([], other_files)
dump(other_files)
dump(repr(result))
# Check if the result contains each specific file in the expected tags map without ctags
for file in test_files:
self.assertIn(file, result)
# close the open cache files, so Windows won't error
del repo_map
def test_get_repo_map_excludes_added_files(self):
# Create a temporary directory with sample files for testing
test_files = [
"test_file1.py",
"test_file2.py",
"test_file3.md",
"test_file4.json",
]
with IgnorantTemporaryDirectory() as temp_dir:
for file in test_files:
with open(os.path.join(temp_dir, file), "w") as f:
f.write("def foo(): pass\n")
io = InputOutput()
repo_map = RepoMap(main_model=self.GPT35, root=temp_dir, io=io)
test_files = [os.path.join(temp_dir, file) for file in test_files]
result = repo_map.get_repo_map(test_files[:2], test_files[2:])
dump(result)
# Check if the result contains the expected tags map
self.assertNotIn("test_file1.py", result)
self.assertNotIn("test_file2.py", result)
self.assertIn("test_file3.md", result)
self.assertIn("test_file4.json", result)
# close the open cache files, so Windows won't error
del repo_map
class TestRepoMapTypescript(unittest.TestCase):
def setUp(self):
self.GPT35 = Model("gpt-3.5-turbo")
def test_get_repo_map_typescript(self):
# Create a temporary directory with a sample TypeScript
63D4
file
test_file_ts = "test_file.ts"
file_content_ts = """\
interface IMyInterface {
someMethod(): void;
}
type ExampleType = {
key: string;
value: number;
};
enum Status {
New,
InProgress,
Completed,
}
export class MyClass {
constructor(public value: number) {}
add(input: number): number {
return this.value + input;
return this.value + input;
}
}
export function myFunction(input: number): number {
return input * 2;
}
"""
with IgnorantTemporaryDirectory() as temp_dir:
with open(os.path.join(temp_dir, test_file_ts), "w") as f:
f.write(file_content_ts)
io = InputOutput()
repo_map = RepoMap(main_model=self.GPT35, root=temp_dir, io=io)
other_files = [os.path.join(temp_dir, test_file_ts)]
result = repo_map.get_repo_map([], other_files)
# Check if the result contains the expected tags map with TypeScript identifiers
self.assertIn("test_file.ts", result)
self.assertIn("IMyInterface", result)
self.assertIn("ExampleType", result)
self.assertIn("Status", result)
self.assertIn("MyClass", result)
self.assertIn("add", result)
self.assertIn("myFunction", result)
# close the open cache files, so Windows won't error
del repo_map
if __name__ == "__main__":
unittest.main()