@@ -102,7 +102,7 @@ def missing_coverage_prompt(self, segment: CodeSegment,
102
102
103
103
104
104
class Gpt4PrompterV2 (Prompter ):
105
- """Prompter for GPT-4 ."""
105
+ """Prompter for GPT."""
106
106
107
107
def __init__ (self , * args , ** kwargs ):
108
108
Prompter .__init__ (self , * args , ** kwargs )
@@ -188,7 +188,7 @@ def get_functions(self) -> T.List[T.Callable]:
188
188
189
189
190
190
class Gpt4PrompterV2Ablated (Prompter ):
191
- """Prompter for GPT-4 that does not use coverage information ."""
191
+ """Fully ablated GPT prompter ."""
192
192
193
193
def __init__ (self , * args , ** kwargs ):
194
194
Prompter .__init__ (self , * args , ** kwargs )
@@ -218,23 +218,58 @@ def initial_prompt(self, segment: CodeSegment) -> T.List[dict]:
218
218
""" )
219
219
]
220
220
221
+
221
222
def error_prompt (self , segment : CodeSegment , error : str ) -> T .List [dict ] | None :
222
223
return None
223
- # return [_message(f"""\
224
- #Executing the test yields an error, shown below.
225
- #Modify the test to correct it; respond only with the complete Python code in backticks.
226
- #
227
- #{error}""")
228
- # ]
224
+
225
+
226
+ def missing_coverage_prompt (self , segment : CodeSegment ,
227
+ missing_lines : set , missing_branches : set ) -> T .List [dict ] | None :
228
+ return None
229
+
230
+
231
+ class Gpt4PrompterV2OnlyError (Prompter ):
232
+ """Partially ablated GPT prompter that attempts error correction."""
233
+
234
+ def __init__ (self , * args , ** kwargs ):
235
+ Prompter .__init__ (self , * args , ** kwargs )
236
+
237
+ def initial_prompt (self , segment : CodeSegment ) -> T .List [dict ]:
238
+ args = self .args
239
+ module_name = get_module_name (segment .path , args .package_dir )
240
+ filename = segment .path .relative_to (args .package_dir .parent )
241
+
242
+ return [
243
+ _message (f"""
244
+ You are an expert Python test-driven developer.
245
+ The code below, extracted from { filename } , does not achieve full coverage.
246
+ Create new pytest test functions that execute all lines and branches, always making
247
+ sure that each test is correct and indeed improves coverage.
248
+ Always send entire Python test scripts when proposing a new test or correcting one you
249
+ previously proposed.
250
+ Be sure to include assertions in the test that verify any applicable postconditions.
251
+ Please also make VERY SURE to clean up after the test, so as to avoid state pollution;
252
+ use 'monkeypatch' or 'pytest-mock' if appropriate.
253
+ Write as little top-level code as possible, and in particular do not include any top-level code
254
+ calling into pytest.main or the test itself.
255
+ Respond ONLY with the Python code enclosed in backticks, without any explanation.
256
+ ```python
257
+ { segment .get_excerpt (tag_lines = False , include_imports = False )}
258
+ ```
259
+ """ )
260
+ ]
261
+
262
+ def error_prompt (self , segment : CodeSegment , error : str ) -> T .List [dict ] | None :
263
+ return [_message (f"""\
264
+ Executing the test yields an error, shown below.
265
+ Modify the test to correct it; respond only with the complete Python code in backticks.
266
+
267
+ { error } """ )
268
+ ]
229
269
230
270
def missing_coverage_prompt (self , segment : CodeSegment ,
231
271
missing_lines : set , missing_branches : set ) -> T .List [dict ] | None :
232
272
return None
233
- # return [_message(f"""\
234
- #The tests still lack coverage.
235
- #Modify to correct that; respond only with the complete Python code in backticks.
236
- #""")
237
- # ]
238
273
239
274
240
275
class ClaudePrompter (Prompter ):
@@ -313,6 +348,8 @@ def missing_coverage_prompt(self, segment: CodeSegment,
313
348
"gpt" : Gpt4PrompterV1 ,
314
349
"gpt-v1" : Gpt4PrompterV1 ,
315
350
"gpt-v2" : Gpt4PrompterV2 ,
351
+ "gpt-v2-fully-ablated" : Gpt4PrompterV2Ablated ,
316
352
"gpt-v2-ablated" : Gpt4PrompterV2Ablated ,
353
+ "gpt-v2-only-error" : Gpt4PrompterV2OnlyError ,
317
354
"claude" : ClaudePrompter
318
355
}
0 commit comments