Skip to content

Commit be16d13

Browse files
committed
add
1 parent 9cba73f commit be16d13

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

commit0/cli.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,10 @@ def test(
221221
timeout: int = typer.Option(1800, help="Timeout for tests in seconds"),
222222
num_cpus: int = typer.Option(1, help="Number of CPUs to use"),
223223
reference: Annotated[
224-
bool, typer.Option("--reference", help="Test the reference commit.")
224+
bool, typer.Option("--reference", help="Test the reference commit")
225+
] = False,
226+
coverage: Annotated[
227+
bool, typer.Option("--coverage", help="Whether to get coverage information")
225228
] = False,
226229
rebuild: bool = typer.Option(
227230
False, "--rebuild", help="Whether to rebuild an image"
@@ -266,6 +269,7 @@ def test(
266269
repo_or_repo_path,
267270
branch, # type: ignore
268271
test_ids,
272+
coverage,
269273
backend,
270274
timeout,
271275
num_cpus,
@@ -286,6 +290,9 @@ def evaluate(
286290
reference: Annotated[
287291
bool, typer.Option("--reference", help="Evaluate the reference commit.")
288292
] = False,
293+
coverage: Annotated[
294+
bool, typer.Option("--coverage", help="Whether to get coverage information")
295+
] = False,
289296
commit0_dot_file_path: str = typer.Option(
290297
".commit0.yaml",
291298
help="Path to the commit0 dot file, where the setup config is stored",
@@ -309,6 +316,7 @@ def evaluate(
309316
commit0_config["repo_split"],
310317
commit0_config["base_dir"],
311318
branch,
319+
coverage,
312320
backend,
313321
timeout,
314322
num_cpus,

commit0/harness/evaluate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def main(
2424
repo_split: str,
2525
base_dir: str,
2626
branch: Union[str, None],
27+
coverage: bool,
2728
backend: str,
2829
timeout: int,
2930
num_cpus: int,
@@ -58,6 +59,7 @@ def main(
5859
repo,
5960
branch,
6061
test_dir,
62+
coverage,
6163
backend,
6264
timeout,
6365
num_cpus,

commit0/harness/get_pytest_ids.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
import tarfile
1+
import bz2
22
from typing import List
33

44

55
def main(repo: str, verbose: int) -> List[str]:
66
repo = repo.lower()
77
repo = repo.replace(".", "-")
8-
out = ""
9-
with tarfile.open(f"commit0/data/test_ids/{repo}.tar.bz2", "r:bz2") as tar:
10-
for member in tar.getmembers():
11-
if member.isfile():
12-
file = tar.extractfile(member)
13-
if file:
14-
content = file.read().decode("utf-8")
15-
out += content
16-
if verbose:
17-
print(content)
8+
with bz2.open(f"commit0/data/test_ids/{repo}.bz2", 'rt') as f:
9+
out = f.read()
1810
out = out.split("\n")
1911
return out
2012

commit0/harness/run_pytest_ids.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def main(
3434
repo_or_repo_dir: str,
3535
branch: str,
3636
test_ids: str,
37+
coverage: bool,
3738
backend: str,
3839
timeout: int,
3940
num_cpus: int,
@@ -113,7 +114,11 @@ def main(
113114
patch_file.write_text(patch)
114115

115116
# make eval file
116-
eval_script = spec.eval_script.format(test_ids=test_ids)
117+
if coverage:
118+
coverage_text = f" --cov={example['src_dir']} --cov-branch --cov-report json"
119+
else:
120+
coverage_text = ""
121+
eval_script = spec.eval_script.format(test_ids=test_ids, coverage=coverage_text)
117122
eval_file = Path(log_dir / "eval.sh")
118123
eval_file.write_text(eval_script)
119124

@@ -134,10 +139,11 @@ def main(
134139
)
135140
files_to_collect = [
136141
"report.json",
137-
"coverage.json",
138142
"pytest_exit_code.txt",
139143
"test_output.txt",
140144
]
145+
if coverage:
146+
files_to_collect.append("coverage.json")
141147

142148
try:
143149
with execution_context(

commit0/harness/spec.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def make_repo_script_list(instance: RepoInstance, repo_directory: str) -> list[s
146146
)
147147
setup_commands.append(install)
148148
setup_commands.append(
149-
"uv pip install pytest pytest-cov coverage pytest-json-report"
149+
"uv pip install -U pytest pytest-cov coverage pytest-json-report"
150150
)
151151
setup_commands.append(f"git reset --hard {base_commit}")
152152
return setup_commands
@@ -160,10 +160,8 @@ def make_eval_script_list(instance: RepoInstance, repo_directory: str) -> list[s
160160
f"git reset --hard {instance['base_commit']}",
161161
"git apply --allow-empty -v /patch.diff",
162162
"git status",
163-
f"{instance['test']['test_cmd']} --json-report --json-report-file=report.json --continue-on-collection-errors --cov=. --cov-branch --cov-report json {{test_ids}} > test_output.txt 2>&1",
163+
f"{instance['test']['test_cmd']} --json-report --json-report-file=report.json --continue-on-collection-errors{{coverage}} {{test_ids}} > test_output.txt 2>&1",
164164
"echo $? > pytest_exit_code.txt",
165-
f"git reset --hard {instance['base_commit']}",
166-
"git status",
167165
]
168166
return eval_script_list
169167

0 commit comments

Comments
 (0)