@@ -14,28 +14,34 @@ def test_config():
14
14
"""Create a mock TestConfig for testing."""
15
15
config = Mock (spec = TestConfig )
16
16
config .project_root_path = Path ("/project" )
17
+ config .test_framework = "pytest"
18
+ config .tests_project_rootdir = Path ("/project/tests" )
17
19
config .tests_root = Path ("/project/tests" )
18
20
return config
19
21
20
22
21
- @pytest .fixture
22
- def sample_invocation_id ():
23
- """Create a sample InvocationId for testing."""
24
- return InvocationId (
25
- test_module_path = "tests.test_module" ,
26
- test_class_name = "TestClass" ,
27
- test_function_name = "test_function" ,
28
- )
29
-
30
-
31
- @pytest .fixture
32
- def sample_invocation_id_no_class ():
33
- """Create a sample InvocationId without class for testing."""
34
- return InvocationId (
35
- test_module_path = "tests.test_module" ,
36
- test_class_name = None ,
37
- test_function_name = "test_function" ,
38
- )
23
+ # @pytest.fixture
24
+ # def sample_invocation_id():
25
+ # """Create a sample InvocationId for testing."""
26
+ # return InvocationId(
27
+ # test_module_path="test_module_path",
28
+ # test_class_name="test_class_name",
29
+ # test_function_name="test_function_name",
30
+ # function_getting_tested="function_getting_tested",
31
+ # iteration_id="0",
32
+ # )
33
+ #
34
+ #
35
+ # @pytest.fixture
36
+ # def sample_invocation_id_no_class():
37
+ # """Create a sample InvocationId without class for testing."""
38
+ # return InvocationId(
39
+ # test_module_path="test_module_path",
40
+ # test_class_name=None,
41
+ # test_function_name="test_function_name",
42
+ # function_getting_tested="function_getting_tested",
43
+ # iteration_id="0",
44
+ # )
39
45
40
46
41
47
class TestAddRuntimeCommentsToGeneratedTests :
@@ -60,6 +66,8 @@ def test_add_runtime_comments_simple_function(self, test_config):
60
66
test_module_path = "tests.test_module" ,
61
67
test_class_name = None ,
62
68
test_function_name = "test_function" ,
69
+ function_getting_tested = "some_function" ,
70
+ iteration_id = "0" ,
63
71
)
64
72
65
73
original_runtimes = {invocation_id : [1000000000 , 1200000000 ]} # 1s, 1.2s in nanoseconds
@@ -70,7 +78,7 @@ def test_add_runtime_comments_simple_function(self, test_config):
70
78
)
71
79
72
80
expected_source = '''def test_function():
73
- codeflash_output = some_function() # 1.00s -> 500.00ms (50 .00%)
81
+ codeflash_output = some_function() # 1.00s -> 500ms (100 .00%)
74
82
assert codeflash_output == expected
75
83
'''
76
84
@@ -99,6 +107,9 @@ def test_function(self):
99
107
test_module_path = "tests.test_module" ,
100
108
test_class_name = "TestClass" ,
101
109
test_function_name = "test_function" ,
110
+ function_getting_tested = "some_function" ,
111
+ iteration_id = "0" ,
112
+
102
113
)
103
114
104
115
original_runtimes = {invocation_id : [2000000000 ]} # 2s in nanoseconds
@@ -110,7 +121,7 @@ def test_function(self):
110
121
111
122
expected_source = '''class TestClass:
112
123
def test_function(self):
113
- codeflash_output = some_function() # 2.00s -> 1.00s (50 .00%)
124
+ codeflash_output = some_function() # 2.00s -> 1.00s (100 .00%)
114
125
assert codeflash_output == expected
115
126
'''
116
127
@@ -141,6 +152,8 @@ def test_add_runtime_comments_multiple_assignments(self, test_config):
141
152
test_module_path = "tests.test_module" ,
142
153
test_class_name = None ,
143
154
test_function_name = "test_function" ,
155
+ function_getting_tested = "some_function" ,
156
+ iteration_id = "0" ,
144
157
)
145
158
146
159
original_runtimes = {invocation_id : [1500000000 ]} # 1.5s in nanoseconds
@@ -152,9 +165,9 @@ def test_add_runtime_comments_multiple_assignments(self, test_config):
152
165
153
166
expected_source = '''def test_function():
154
167
setup_data = prepare_test()
155
- codeflash_output = some_function() # 1.50s -> 750.00ms (50 .00%)
168
+ codeflash_output = some_function() # 1.50s -> 750ms (100 .00%)
156
169
assert codeflash_output == expected
157
- codeflash_output = another_function() # 1.50s -> 750.00ms (50 .00%)
170
+ codeflash_output = another_function() # 1.50s -> 750ms (100 .00%)
158
171
assert codeflash_output == expected2
159
172
'''
160
173
@@ -183,6 +196,8 @@ def test_add_runtime_comments_no_matching_runtimes(self, test_config):
183
196
test_module_path = "tests.other_module" ,
184
197
test_class_name = None ,
185
198
test_function_name = "other_function" ,
199
+ function_getting_tested = "some_other_function" ,
200
+ iteration_id = "0" ,
186
201
)
187
202
188
203
original_runtimes = {invocation_id : [1000000000 ]}
@@ -217,6 +232,8 @@ def test_add_runtime_comments_no_codeflash_output(self, test_config):
217
232
test_module_path = "tests.test_module" ,
218
233
test_class_name = None ,
219
234
test_function_name = "test_function" ,
235
+ function_getting_tested = "some_function" ,
236
+ iteration_id = "0" ,
220
237
)
221
238
222
239
original_runtimes = {invocation_id : [1000000000 ]}
@@ -264,12 +281,16 @@ def test_add_runtime_comments_multiple_tests(self, test_config):
264
281
test_module_path = "tests.test_module1" ,
265
282
test_class_name = None ,
266
283
test_function_name = "test_function1" ,
284
+ function_getting_tested = "some_function" ,
285
+ iteration_id = "0" ,
267
286
)
268
287
269
288
invocation_id2 = InvocationId (
270
289
test_module_path = "tests.test_module2" ,
271
290
test_class_name = None ,
272
291
test_function_name = "test_function2" ,
292
+ function_getting_tested = "another_function" ,
293
+ iteration_id = "0" ,
273
294
)
274
295
275
296
original_runtimes = {
@@ -286,12 +307,12 @@ def test_add_runtime_comments_multiple_tests(self, test_config):
286
307
)
287
308
288
309
expected_source1 = '''def test_function1():
289
- codeflash_output = some_function() # 1.00s -> 500.00ms (50 .00%)
310
+ codeflash_output = some_function() # 1.00s -> 500ms (100 .00%)
290
311
assert codeflash_output == expected
291
312
'''
292
313
293
314
expected_source2 = '''def test_function2():
294
- codeflash_output = another_function() # 2.00s -> 800.00ms (60 .00%)
315
+ codeflash_output = another_function() # 2.00s -> 800ms (150 .00%)
295
316
assert codeflash_output == expected
296
317
'''
297
318
@@ -320,6 +341,8 @@ def test_add_runtime_comments_performance_regression(self, test_config):
320
341
test_module_path = "tests.test_module" ,
321
342
test_class_name = None ,
322
343
test_function_name = "test_function" ,
344
+ function_getting_tested = "some_function" ,
345
+ iteration_id = "0" ,
323
346
)
324
347
325
348
original_runtimes = {invocation_id : [1000000000 ]} # 1s
@@ -330,7 +353,7 @@ def test_add_runtime_comments_performance_regression(self, test_config):
330
353
)
331
354
332
355
expected_source = '''def test_function():
333
- codeflash_output = some_function() # 1.00s -> 1.50s (-50.00 %)
356
+ codeflash_output = some_function() # 1.00s -> 1.50s (-33.33 %)
334
357
assert codeflash_output == expected
335
358
'''
336
359
0 commit comments