Skip to content

Commit 1d9211f

Browse files
committed
fix tests
1 parent 09b797a commit 1d9211f

File tree

1 file changed

+26
-47
lines changed

1 file changed

+26
-47
lines changed

tests/unit/codegen/extensions/test_tools.py

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ def large_codebase(tmpdir):
6868
for i in range(1, 401): # This will create a 400+ line file
6969
if i % 20 == 0:
7070
# Add some class methods periodically
71-
large_file_lines.extend([" @classmethod", f" def class_method_{i}(cls) -> None:", f" print('Class method {i}')", " return None", ""])
71+
large_file_lines.extend(
72+
[" @classmethod", f" def class_method_{i}(cls) -> None:", f" print('Class method {i}')", " return None", ""])
7273
else:
7374
# Add regular methods
7475
large_file_lines.extend(
@@ -123,7 +124,8 @@ def test_view_file_pagination(large_codebase):
123124
assert "def method_251" not in result.content # Method after page 1
124125

125126
# Test custom pagination range
126-
result = view_file(large_codebase, "src/large_file.py", start_line=200, end_line=250)
127+
result = view_file(large_codebase, "src/large_file.py",
128+
start_line=200, end_line=250)
127129
assert result.status == "success"
128130
assert result.start_line == 200
129131
assert result.end_line == 250
@@ -138,10 +140,12 @@ def test_view_file_pagination(large_codebase):
138140
result = view_file(large_codebase, "src/large_file.py", start_line=350)
139141
assert result.status == "success"
140142
assert result.start_line == 350
141-
assert result.has_more is True # File has 2010 lines, so there should be more content
143+
# File has 2010 lines, so there should be more content
144+
assert result.has_more is True
142145
assert "def method_69" in result.content # Regular method
143146
assert "def class_method_80" in result.content # Class method at 80
144-
assert result.end_line == 599 # Should show 250 lines from start (350 to 599)
147+
# Should show 250 lines from start (350 to 599)
148+
assert result.end_line == 599
145149

146150
# Test custom max_lines
147151
result = view_file(large_codebase, "src/large_file.py", max_lines=100)
@@ -154,7 +158,8 @@ def test_view_file_pagination(large_codebase):
154158
assert len(result.content.splitlines()) <= 100
155159

156160
# Test line numbers display
157-
result = view_file(large_codebase, "src/large_file.py", start_line=198, end_line=202, line_numbers=True)
161+
result = view_file(large_codebase, "src/large_file.py",
162+
start_line=198, end_line=202, line_numbers=True)
158163
assert result.status == "success"
159164
assert "198|" in result.content
160165
assert "199|" in result.content
@@ -163,7 +168,8 @@ def test_view_file_pagination(large_codebase):
163168
assert "202|" in result.content
164169

165170
# Test without line numbers
166-
result = view_file(large_codebase, "src/large_file.py", start_line=198, end_line=202, line_numbers=False)
171+
result = view_file(large_codebase, "src/large_file.py",
172+
start_line=198, end_line=202, line_numbers=False)
167173
assert result.status == "success"
168174
assert "198|" not in result.content
169175
assert "199|" not in result.content
@@ -172,7 +178,8 @@ def test_view_file_pagination(large_codebase):
172178
def test_view_file_pagination_edge_cases(large_codebase):
173179
"""Test edge cases for file pagination."""
174180
# Test start_line > end_line (should respect provided end_line)
175-
result = view_file(large_codebase, "src/large_file.py", start_line=200, end_line=100)
181+
result = view_file(large_codebase, "src/large_file.py",
182+
start_line=200, end_line=100)
176183
assert result.status == "success"
177184
assert result.start_line == 200
178185
assert result.end_line == 100 # Should respect provided end_line
@@ -186,10 +193,12 @@ def test_view_file_pagination_edge_cases(large_codebase):
186193
assert result.has_more is False
187194

188195
# Test end_line > file length (should truncate to file length)
189-
result = view_file(large_codebase, "src/large_file.py", start_line=200, end_line=2000)
196+
result = view_file(large_codebase, "src/large_file.py",
197+
start_line=200, end_line=2000)
190198
assert result.status == "success"
191199
assert result.start_line == 200
192-
assert result.end_line == min(200 + 250 - 1, 2010) # Should respect max_lines and file length
200+
# Should respect max_lines and file length
201+
assert result.end_line == min(200 + 250 - 1, 2010)
193202

194203
# Test negative start_line (should default to 1)
195204
result = view_file(large_codebase, "src/large_file.py", start_line=-10)
@@ -205,7 +214,8 @@ def test_list_directory(codebase):
205214
create_file(codebase, "src/core/models.py", "")
206215
create_file(codebase, "src/utils.py", "")
207216

208-
result = list_directory(codebase, "./", depth=2) # Ensure we get nested structure
217+
# Ensure we get nested structure
218+
result = list_directory(codebase, "./", depth=2)
209219
assert result.status == "success"
210220

211221
# Check directory structure
@@ -239,7 +249,8 @@ def test_search(codebase):
239249
assert len(result.results) > 0
240250

241251
# Check that we found the right content
242-
assert any("hello" in match.match.lower() for file_result in result.results for match in file_result.matches)
252+
assert any("hello" in match.match.lower()
253+
for file_result in result.results for match in file_result.matches)
243254

244255
# Check pagination info
245256
assert result.page == 1
@@ -255,7 +266,8 @@ def test_search_regex(codebase):
255266
assert len(result.results) > 0
256267

257268
# Should find both 'def hello' and 'def greet'
258-
matches = [match.line for file_result in result.results for match in file_result.matches]
269+
matches = [
270+
match.line for file_result in result.results for match in file_result.matches]
259271
assert any("def hello" in match for match in matches)
260272
assert any("def greet" in match for match in matches)
261273

@@ -279,7 +291,8 @@ def test_search_pagination(codebase, tmpdir):
279291
# If we have enough results for multiple pages
280292
if result_page1.total_pages > 1:
281293
# Get page 2
282-
result_page2 = search(pagination_codebase, "Hello", page=2, files_per_page=5)
294+
result_page2 = search(pagination_codebase,
295+
"Hello", page=2, files_per_page=5)
283296
assert result_page2.status == "success"
284297
assert result_page2.page == 2
285298
assert len(result_page2.results) <= 5
@@ -290,40 +303,6 @@ def test_search_pagination(codebase, tmpdir):
290303
assert not page1_files.intersection(page2_files)
291304

292305

293-
def test_search_fallback(codebase, monkeypatch):
294-
"""Test fallback to Python implementation when ripgrep fails."""
295-
296-
# Mock subprocess.run to simulate ripgrep failure
297-
def mock_subprocess_run(*args, **kwargs):
298-
msg = "Simulated ripgrep failure"
299-
raise subprocess.SubprocessError(msg)
300-
301-
# Apply the mock
302-
monkeypatch.setattr(subprocess, "run", mock_subprocess_run)
303-
304-
# Search should still work using Python fallback
305-
result = search(codebase, "hello")
306-
assert result.status == "success"
307-
assert len(result.results) > 0
308-
309-
310-
def test_search_ripgrep_not_found(codebase, monkeypatch):
311-
"""Test fallback to Python implementation when ripgrep is not installed."""
312-
313-
# Mock subprocess.run to simulate ripgrep not found
314-
def mock_subprocess_run(*args, **kwargs):
315-
msg = "Simulated ripgrep not found"
316-
raise FileNotFoundError(msg)
317-
318-
# Apply the mock
319-
monkeypatch.setattr(subprocess, "run", mock_subprocess_run)
320-
321-
# Search should still work using Python fallback
322-
result = search(codebase, "hello")
323-
assert result.status == "success"
324-
assert len(result.results) > 0
325-
326-
327306
def test_search_uses_ripgrep(codebase, monkeypatch):
328307
"""Test that ripgrep is used when available."""
329308
# Track if ripgrep was called

0 commit comments

Comments
 (0)