Skip to content

Commit

Permalink
fix test command (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
qododavid authored Feb 21, 2025
1 parent b7067ee commit 73f2305
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 33 deletions.
61 changes: 29 additions & 32 deletions cover_agent/CoverAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@ def __init__(self, args, agent_completion: AgentCompletionABC = None):
self.ai_caller = AICaller(model=args.model, api_base=args.api_base, max_tokens=8192)
self.agent_completion = DefaultAgentCompletion(caller=self.ai_caller)

# To run only a single test file, we need to modify the test command
test_command = args.test_command
new_command_line = None
if hasattr(args, "run_each_test_separately") and args.run_each_test_separately:
test_file_relative_path = os.path.relpath(
args.test_file_output_path, args.project_root
)
if "pytest" in test_command:
try:
ind1 = test_command.index("pytest")
ind2 = test_command[ind1:].index("--")
new_command_line = f"{test_command[:ind1]}pytest {test_file_relative_path} {test_command[ind1 + ind2:]}"
except ValueError:
print(
f"Failed to adapt test command for running a single test: {test_command}"
)
else:
new_command_line, _, _, _ = self.agent_completion.adapt_test_command_for_a_single_test_via_ai(
test_file_relative_path=test_file_relative_path,
test_command=test_command,
project_root_dir=self.args.test_command_dir,
)
if new_command_line:
args.test_command_original = test_command
args.test_command = new_command_line
print(
f"Converting test command: `{test_command}`\n to run only a single test: `{new_command_line}`"
)

self.test_gen = UnitTestGenerator(
source_file_path=args.source_file_path,
test_file_path=args.test_file_output_path,
Expand Down Expand Up @@ -75,38 +104,6 @@ def __init__(self, args, agent_completion: AgentCompletionABC = None):
agent_completion=self.agent_completion,
)

# To run only a single test file, we need to modify the test command
self.parse_command_to_run_only_a_single_test(args)

def parse_command_to_run_only_a_single_test(self, args):
test_command = args.test_command
new_command_line = None
if hasattr(args, "run_each_test_separately") and args.run_each_test_separately:
test_file_relative_path = os.path.relpath(
args.test_file_output_path, args.project_root
)
if "pytest" in test_command:
try:
ind1 = test_command.index("pytest")
ind2 = test_command[ind1:].index("--")
new_command_line = f"{test_command[:ind1]}pytest {test_file_relative_path} {test_command[ind1 + ind2:]}"
except ValueError:
print(
f"Failed to adapt test command for running a single test: {test_command}"
)
else:
new_command_line = self.agent_completion.adapt_test_command_for_a_single_test_via_ai(
test_file_relative_path=test_file_relative_path,
test_command=test_command,
project_root_dir=self.args.test_command_dir,
)
if new_command_line:
args.test_command_original = test_command
args.test_command = new_command_line
print(
f"Converting test command: `{test_command}`\n to run only a single test: `{new_command_line}`"
)

def _validate_paths(self):
"""
Validate the paths provided in the arguments.
Expand Down
2 changes: 1 addition & 1 deletion cover_agent/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.2
0.3.3

0 comments on commit 73f2305

Please sign in to comment.