@@ -41,6 +41,35 @@ def __init__(self, args, agent_completion: AgentCompletionABC = None):
4141 self .ai_caller = AICaller (model = args .model , api_base = args .api_base , max_tokens = 8192 )
4242 self .agent_completion = DefaultAgentCompletion (caller = self .ai_caller )
4343
44+ # To run only a single test file, we need to modify the test command
45+ test_command = args .test_command
46+ new_command_line = None
47+ if hasattr (args , "run_each_test_separately" ) and args .run_each_test_separately :
48+ test_file_relative_path = os .path .relpath (
49+ args .test_file_output_path , args .project_root
50+ )
51+ if "pytest" in test_command :
52+ try :
53+ ind1 = test_command .index ("pytest" )
54+ ind2 = test_command [ind1 :].index ("--" )
55+ new_command_line = f"{ test_command [:ind1 ]} pytest { test_file_relative_path } { test_command [ind1 + ind2 :]} "
56+ except ValueError :
57+ print (
58+ f"Failed to adapt test command for running a single test: { test_command } "
59+ )
60+ else :
61+ new_command_line , _ , _ , _ = self .agent_completion .adapt_test_command_for_a_single_test_via_ai (
62+ test_file_relative_path = test_file_relative_path ,
63+ test_command = test_command ,
64+ project_root_dir = self .args .test_command_dir ,
65+ )
66+ if new_command_line :
67+ args .test_command_original = test_command
68+ args .test_command = new_command_line
69+ print (
70+ f"Converting test command: `{ test_command } `\n to run only a single test: `{ new_command_line } `"
71+ )
72+
4473 self .test_gen = UnitTestGenerator (
4574 source_file_path = args .source_file_path ,
4675 test_file_path = args .test_file_output_path ,
@@ -75,38 +104,6 @@ def __init__(self, args, agent_completion: AgentCompletionABC = None):
75104 agent_completion = self .agent_completion ,
76105 )
77106
78- # To run only a single test file, we need to modify the test command
79- self .parse_command_to_run_only_a_single_test (args )
80-
81- def parse_command_to_run_only_a_single_test (self , args ):
82- test_command = args .test_command
83- new_command_line = None
84- if hasattr (args , "run_each_test_separately" ) and args .run_each_test_separately :
85- test_file_relative_path = os .path .relpath (
86- args .test_file_output_path , args .project_root
87- )
88- if "pytest" in test_command :
89- try :
90- ind1 = test_command .index ("pytest" )
91- ind2 = test_command [ind1 :].index ("--" )
92- new_command_line = f"{ test_command [:ind1 ]} pytest { test_file_relative_path } { test_command [ind1 + ind2 :]} "
93- except ValueError :
94- print (
95- f"Failed to adapt test command for running a single test: { test_command } "
96- )
97- else :
98- new_command_line = self .agent_completion .adapt_test_command_for_a_single_test_via_ai (
99- test_file_relative_path = test_file_relative_path ,
100- test_command = test_command ,
101- project_root_dir = self .args .test_command_dir ,
102- )
103- if new_command_line :
104- args .test_command_original = test_command
105- args .test_command = new_command_line
106- print (
107- f"Converting test command: `{ test_command } `\n to run only a single test: `{ new_command_line } `"
108- )
109-
110107 def _validate_paths (self ):
111108 """
112109 Validate the paths provided in the arguments.
0 commit comments