@@ -15,7 +15,9 @@ def get_memory_info():
15
15
"""Get current and peak memory usage in bytes."""
16
16
process = psutil .Process (os .getpid ())
17
17
rss = process .memory_info ().rss
18
- peak_rss = resource .getrusage (resource .RUSAGE_SELF ).ru_maxrss * 1024 # Convert KB to bytes
18
+ peak_rss = (
19
+ resource .getrusage (resource .RUSAGE_SELF ).ru_maxrss * 1024
20
+ ) # Convert KB to bytes
19
21
return {
20
22
'rss' : rss ,
21
23
'peak_rss' : peak_rss ,
@@ -28,17 +30,17 @@ def create_test_file(path: Path, size_mb: float = 5.0):
28
30
line_size = 100 # bytes per line approximately
29
31
num_lines = int ((size_mb * 1024 * 1024 ) // line_size )
30
32
31
- print (f" \n Creating test file with { num_lines } lines..." )
33
+ print (f' \n Creating test file with { num_lines } lines...' )
32
34
with open (path , 'w' ) as f :
33
35
for i in range (num_lines ):
34
36
f .write (f'Line { i } : ' + 'x' * (line_size - 10 ) + '\n ' )
35
37
36
38
actual_size = os .path .getsize (path )
37
- print (f" File created, size: { actual_size / 1024 / 1024 :.2f} MB" )
39
+ print (f' File created, size: { actual_size / 1024 / 1024 :.2f} MB' )
38
40
return actual_size
39
41
40
42
41
- def set_memory_limit (file_size : int , multiplier : float = 1.5 ):
43
+ def set_memory_limit (file_size : int , multiplier : float = 2.0 ):
42
44
"""Set memory limit to multiplier * file_size."""
43
45
# Add base memory for pytest and other processes (100MB)
44
46
base_memory = 100 * 1024 * 1024 # 100MB
@@ -50,11 +52,13 @@ def set_memory_limit(file_size: int, multiplier: float = 1.5):
50
52
current_usage = psutil .Process ().memory_info ().rss
51
53
if memory_limit > current_usage :
52
54
resource .setrlimit (resource .RLIMIT_AS , (memory_limit , hard ))
53
- print (f" Memory limit set to { memory_limit / 1024 / 1024 :.2f} MB" )
55
+ print (f' Memory limit set to { memory_limit / 1024 / 1024 :.2f} MB' )
54
56
else :
55
- print (f"Warning: Current memory usage ({ current_usage / 1024 / 1024 :.2f} MB) higher than limit ({ memory_limit / 1024 / 1024 :.2f} MB)" )
57
+ print (
58
+ f'Warning: Current memory usage ({ current_usage / 1024 / 1024 :.2f} MB) higher than limit ({ memory_limit / 1024 / 1024 :.2f} MB)'
59
+ )
56
60
except Exception as e :
57
- print (f" Warning: Could not set memory limit: { str (e )} " )
61
+ print (f' Warning: Could not set memory limit: { str (e )} ' )
58
62
return memory_limit
59
63
60
64
@@ -82,6 +86,7 @@ def test_str_replace_peak_memory():
82
86
83
87
# Force Python to release file handles and clear buffers
84
88
import gc
89
+
85
90
gc .collect ()
86
91
87
92
# Get initial memory usage
@@ -93,7 +98,7 @@ def test_str_replace_peak_memory():
93
98
94
99
# Perform str_replace operation
95
100
try :
96
- result = file_editor (
101
+ _ = file_editor (
97
102
command = 'str_replace' ,
98
103
path = path ,
99
104
old_str = 'Line 5000' , # Replace a line in the middle
@@ -118,6 +123,7 @@ def test_insert_peak_memory():
118
123
119
124
# Force Python to release file handles and clear buffers
120
125
import gc
126
+
121
127
gc .collect ()
122
128
123
129
# Get initial memory usage
@@ -129,7 +135,7 @@ def test_insert_peak_memory():
129
135
130
136
# Perform insert operation
131
137
try :
132
- result = file_editor (
138
+ _ = file_editor (
133
139
command = 'insert' ,
134
140
path = path ,
135
141
insert_line = 5000 , # Insert in the middle
@@ -154,6 +160,7 @@ def test_view_peak_memory():
154
160
155
161
# Force Python to release file handles and clear buffers
156
162
import gc
163
+
157
164
gc .collect ()
158
165
159
166
# Get initial memory usage
@@ -165,7 +172,7 @@ def test_view_peak_memory():
165
172
166
173
# Test viewing specific lines
167
174
try :
168
- result = file_editor (
175
+ _ = file_editor (
169
176
command = 'view' ,
170
177
path = path ,
171
178
view_range = [5000 , 5100 ], # View 100 lines from middle
@@ -189,6 +196,7 @@ def test_view_full_file_peak_memory():
189
196
190
197
# Force Python to release file handles and clear buffers
191
198
import gc
199
+
192
200
gc .collect ()
193
201
194
202
# Get initial memory usage
@@ -200,7 +208,7 @@ def test_view_full_file_peak_memory():
200
208
201
209
# Test viewing entire file
202
210
try :
203
- result = file_editor (
211
+ _ = file_editor (
204
212
command = 'view' ,
205
213
path = path ,
206
214
enable_linting = False ,
@@ -212,4 +220,4 @@ def test_view_full_file_peak_memory():
212
220
pytest .fail ('Memory limit exceeded - peak memory usage too high' )
213
221
raise
214
222
215
- check_memory_usage (initial ['max' ], file_size , 'view_full' )
223
+ check_memory_usage (initial ['max' ], file_size , 'view_full' )
0 commit comments