Skip to content

Commit 5acdb47

Browse files
authored
Merge pull request #419 from mdboom/more-test-coverage
More test coverage
2 parents 7106cd8 + 5a0bc11 commit 5acdb47

File tree

5 files changed

+132
-2
lines changed

5 files changed

+132
-2
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ flags = ["TAILCALL"]
8383
runners = ["linux_clang", "darwin", "windows_clang"]
8484
```
8585

86+
### Long-running tests
87+
88+
`bench-runner` has some new long-running end-to-end integration tests. To avoid running them, use:
89+
90+
```
91+
python -m pytest -m "not long_running"
92+
```
93+
8694
## v1.8.0
8795

8896
### bench_runner.toml change

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ markers = [
5252
[tool.coverage.paths]
5353
source = [
5454
"bench_runner",
55-
"/tmp/pytest-of-*/pytest-*/test_whole_workflow*/repo/outer_venv/lib/python*/site-packages/bench_runner",
56-
"/tmp/pytest-of-*/pytest-*/test_whole_workflow*/repo/venv/lib/python*/site-packages/bench_runner",
55+
"/tmp/pytest-of-*/pytest-*/*/repo/outer_venv/lib/python*/site-packages/bench_runner",
56+
"/tmp/pytest-of-*/pytest-*/*/repo/venv/lib/python*/site-packages/bench_runner",
5757
]

tests/data/loops.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tests/test_notify.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import contextlib
2+
from pathlib import Path
3+
4+
5+
from bench_runner import gh
6+
from bench_runner.scripts import notify
7+
8+
9+
DATA_PATH = Path(__file__).parent / "data"
10+
11+
12+
def test_notify(monkeypatch, capsys):
13+
message_sent = [None]
14+
15+
def send_notification(message):
16+
message_sent[0] = message
17+
18+
monkeypatch.setattr(gh, "send_notification", send_notification)
19+
monkeypatch.setenv("GITHUB_ACTOR", "test_actor")
20+
monkeypatch.setenv("GITHUB_REPOSITORY", "test_repo")
21+
22+
with contextlib.chdir(DATA_PATH):
23+
notify._main(
24+
fork="test_fork",
25+
ref="test_ref",
26+
head="test_head",
27+
date="2023-10-01",
28+
version="3.10.4",
29+
flags=["JIT", "TAILCALL"],
30+
)
31+
32+
captured = capsys.readouterr()
33+
assert captured.out.strip() == (
34+
"::notice ::@test_actor: "
35+
"[test_fork/test_ref]"
36+
"(https://github.com/test_repo-public/tree/main/results/"
37+
"bm-20231001-3.10.4-test_he-JIT,TAILCALL)"
38+
)
39+
40+
expected = (
41+
"@test_actor: "
42+
"[test_fork/test_ref]"
43+
"(https://github.com/test_repo-public/tree/main/results/"
44+
"bm-20231001-3.10.4-test_he-JIT,TAILCALL)"
45+
)
46+
47+
assert expected in message_sent[0].strip()

tests/test_workflow.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,21 @@ def test_whole_workflow(tmpdir):
239239
"--check",
240240
]
241241
)
242+
# Now edit one of the generated files to make the check fail
243+
with open("workflow_bootstrap.py", "a") as fd:
244+
fd.write("# EXTRA CONTENT\n\n")
245+
246+
with pytest.raises(subprocess.CalledProcessError):
247+
subprocess.check_call(
248+
[
249+
str(binary),
250+
"-m",
251+
"bench_runner",
252+
"install",
253+
"--check",
254+
]
255+
)
256+
242257
with open("requirements.txt", "w") as fd:
243258
fd.write(f"{str(bench_runner_checkout)}\n")
244259
subprocess.check_call(
@@ -253,3 +268,62 @@ def test_whole_workflow(tmpdir):
253268
"--_fast",
254269
]
255270
)
271+
272+
273+
@pytest.mark.long_running
274+
@pytest.mark.skipif(not sys.platform.startswith("linux"), reason="Linux only")
275+
def test_pystats(tmpdir):
276+
"""
277+
Tests the whole workflow from a clean benchmarking repo.
278+
"""
279+
tmpdir = Path(tmpdir)
280+
repo = tmpdir / "repo"
281+
venv_dir = repo / "outer_venv"
282+
bench_runner_checkout = DATA_PATH.parents[1]
283+
if sys.platform.startswith("win"):
284+
binary = venv_dir / "Scripts" / "python.exe"
285+
else:
286+
binary = venv_dir / "bin" / "python"
287+
profiling_dir = Path(repo / "profiling" / "results")
288+
289+
repo.mkdir()
290+
profiling_dir.mkdir(parents=True)
291+
292+
shutil.copyfile(DATA_PATH / "loops.json", repo / "loops.json")
293+
294+
with contextlib.chdir(repo):
295+
subprocess.check_call([sys.executable, "-m", "venv", str(venv_dir)])
296+
subprocess.check_call(
297+
[
298+
str(binary),
299+
"-m",
300+
"pip",
301+
"install",
302+
"--upgrade",
303+
"pip",
304+
]
305+
)
306+
subprocess.check_call(
307+
[str(binary), "-m", "pip", "install", f"{bench_runner_checkout}[test]"]
308+
)
309+
subprocess.check_call([str(binary), "-m", "bench_runner", "install"])
310+
with open("requirements.txt", "w") as fd:
311+
fd.write(f"{str(bench_runner_checkout)}\n")
312+
subprocess.check_call(
313+
[
314+
str(binary),
315+
"workflow_bootstrap.py",
316+
"python",
317+
"main",
318+
"linux-x86_64-linux",
319+
"deltablue",
320+
",,,",
321+
"--_fast",
322+
"--pystats",
323+
]
324+
)
325+
326+
deltablue_output = list((repo / "results").glob("**/*-pystats-deltablue.*"))
327+
assert len(deltablue_output) == 2
328+
all_output = list((repo / "results").glob("**/*-pystats.*"))
329+
assert len(all_output) == 2

0 commit comments

Comments
 (0)