Skip to content

Commit 131e35c

Browse files
committed
More test coverage
1 parent 366cf63 commit 131e35c

File tree

4 files changed

+115
-2
lines changed

4 files changed

+115
-2
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ jobs:
4242
long_test_linux:
4343
runs-on: ubuntu-latest
4444
steps:
45+
- name: Install packages
46+
run: |
47+
sudo apt-get update
48+
sudo apt-get install -y linux-tools-common linux-tools-generic
4549
- uses: actions/checkout@v4
4650
- uses: actions/setup-python@v5
4751
with:

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/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+
import textwrap
4+
5+
6+
from bench_runner import gh
7+
from bench_runner.scripts import notify
8+
9+
10+
DATA_PATH = Path(__file__).parent / "data"
11+
12+
13+
def test_notify(monkeypatch, capsys):
14+
message_sent = [None]
15+
16+
def send_notification(message):
17+
message_sent[0] = message
18+
19+
monkeypatch.setattr(gh, "send_notification", send_notification)
20+
monkeypatch.setenv("GITHUB_ACTOR", "test_actor")
21+
monkeypatch.setenv("GITHUB_REPOSITORY", "test_repo")
22+
23+
with contextlib.chdir(DATA_PATH):
24+
notify._main(
25+
fork="test_fork",
26+
ref="test_ref",
27+
head="test_head",
28+
date="2023-10-01",
29+
version="3.10.4",
30+
flags=["JIT", "TAILCALL"],
31+
)
32+
33+
captured = capsys.readouterr()
34+
assert (
35+
captured.out.strip()
36+
== "::notice ::@test_actor: [test_fork/test_ref](https://github.com/test_repo-public/tree/main/results/bm-20231001-3.10.4-test_he-JIT,TAILCALL)"
37+
)
38+
39+
expected = textwrap.dedent(
40+
"""
41+
🤖 This is the friendly benchmarking bot with some new results!
42+
43+
@test_actor: [test_fork/test_ref](https://github.com/test_repo-public/tree/main/results/bm-20231001-3.10.4-test_he-JIT,TAILCALL)
44+
"""
45+
).strip()
46+
47+
assert message_sent[0].strip() == expected

tests/test_workflow.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,65 @@ def test_check_install_fail(tmpdir):
298298
"--check",
299299
]
300300
)
301+
302+
303+
@pytest.mark.long_running
304+
@pytest.mark.skipif(not sys.platform.startswith("linux"), reason="Linux only")
305+
def test_linux_perf(tmpdir):
306+
"""
307+
Tests the whole workflow from a clean benchmarking repo.
308+
"""
309+
repo = tmpdir / "repo"
310+
venv_dir = repo / "outer_venv"
311+
bench_runner_checkout = DATA_PATH.parents[1]
312+
if sys.platform.startswith("win"):
313+
binary = venv_dir / "Scripts" / "python.exe"
314+
else:
315+
binary = venv_dir / "bin" / "python"
316+
profiling_dir = Path(repo / "profiling" / "results")
317+
318+
repo.mkdir()
319+
Path(profiling_dir).mkdir(parents=True)
320+
321+
with contextlib.chdir(repo):
322+
subprocess.check_call([sys.executable, "-m", "venv", str(venv_dir)])
323+
subprocess.check_call(
324+
[
325+
str(binary),
326+
"-m",
327+
"pip",
328+
"install",
329+
"--upgrade",
330+
"pip",
331+
]
332+
)
333+
subprocess.check_call(
334+
[str(binary), "-m", "pip", "install", f"{bench_runner_checkout}[test]"]
335+
)
336+
subprocess.check_call([str(binary), "-m", "bench_runner", "install"])
337+
with open("requirements.txt", "w") as fd:
338+
fd.write(f"{str(bench_runner_checkout)}\n")
339+
subprocess.check_call(
340+
[
341+
str(binary),
342+
"workflow_bootstrap.py",
343+
"python",
344+
"main",
345+
"linux-x86_64-linux",
346+
"deltablue",
347+
",,,",
348+
"--_fast",
349+
"--perf",
350+
]
351+
)
352+
353+
csv_file = profiling_dir / "deltablue.perf.csv"
354+
assert csv_file.is_file()
355+
356+
with open(csv_file, "r") as fd:
357+
lines = iter(fd.readlines())
358+
first_line = next(lines)
359+
assert first_line.strip() == "self,pid,command,shared_obj,symbol"
360+
for line in fd.readlines():
361+
assert line.strip().endswith("_PyEval_EvalFrameDefault")
362+
break

0 commit comments

Comments
 (0)