Skip to content

Commit 6d51172

Browse files
authored
🔧 MAINT: Split test_cli using @pytest.mark.parameterize (#56)
1 parent 33e989c commit 6d51172

File tree

1 file changed

+36
-22
lines changed

1 file changed

+36
-22
lines changed

tests/test_cli.py

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,60 @@
11
from pathlib import Path
22
from subprocess import run
33

4+
from pytest import mark
45

5-
def test_cli(tmpdir, file_regression):
6+
7+
@mark.parametrize(
8+
"cmd,basename",
9+
[
10+
# CLI with URL
11+
(
12+
"github-activity {url} -s 2019-09-01 -u 2019-11-01 -o {path_output}",
13+
"cli_w_url",
14+
),
15+
# CLI with parts
16+
(
17+
"github-activity {org}/{repo} -s 2019-09-01 -u 2019-11-01 -o {path_output}",
18+
"cli_w_parts",
19+
),
20+
# CLI with default branch
21+
(
22+
"github-activity {org}/{repo} -s 2019-09-01 -u 2019-11-01 -o {path_output} -b master",
23+
"cli_def_branch",
24+
),
25+
# CLI with no target
26+
(
27+
"github-activity -s 2019-09-01 -u 2019-11-01 -o {path_output}",
28+
"cli_no_target",
29+
),
30+
],
31+
)
32+
def test_cli(tmpdir, file_regression, cmd, basename):
633
"""The output of all file_regressions should be the same, testing diff opts."""
734
path_tmp = Path(tmpdir)
835
path_output = path_tmp.joinpath("out.md")
936

1037
url = "https://github.com/executablebooks/github-activity"
1138
org, repo = ("executablebooks", "github-activity")
1239

13-
# CLI with URL
14-
cmd = f"github-activity {url} -s 2019-09-01 -u 2019-11-01 -o {path_output}"
15-
run(cmd.split(), check=True)
40+
command = cmd.format(path_output=path_output, url=url, org=org, repo=repo)
41+
run(command.split(), check=True)
1642
md = path_output.read_text()
17-
file_regression.check(md, basename="cli_w_url", extension=".md")
43+
file_regression.check(md, basename=basename, extension=".md")
1844

19-
# CLI with parts
20-
cmd = f"github-activity {org}/{repo} -s 2019-09-01 -u 2019-11-01 -o {path_output}"
21-
run(cmd.split(), check=True)
22-
md = path_output.read_text()
23-
file_regression.check(md, basename="cli_w_parts", extension=".md")
2445

25-
# CLI with default branch
26-
cmd = f"github-activity {org}/{repo} -s 2019-09-01 -u 2019-11-01 -o {path_output} -b master"
27-
run(cmd.split(), check=True)
28-
md = path_output.read_text()
29-
file_regression.check(md, basename="cli_def_branch", extension=".md")
46+
def test_cli_nonexistent_branch(tmpdir):
47+
path_tmp = Path(tmpdir)
48+
path_output = path_tmp.joinpath("out.md")
49+
50+
org, repo = ("executablebooks", "github-activity")
3051

31-
# CLI with non-existent branch
3252
cmd = f"github-activity {org}/{repo} -s 2019-09-01 -u 2019-11-01 -o {path_output} -b foo"
3353
run(cmd.split(), check=True)
3454
md = path_output.read_text()
3555
assert "Contributors to this release" in md
3656
assert "Merged PRs" not in md
3757

38-
# CLI with no target
39-
cmd = f"github-activity -s 2019-09-01 -u 2019-11-01 -o {path_output}"
40-
run(cmd.split(), check=True)
41-
md = path_output.read_text()
42-
file_regression.check(md, basename="cli_no_target", extension=".md")
43-
4458

4559
def test_pr_split(tmpdir, file_regression):
4660
"""Test that PRs are properly split by tags/prefixes."""

0 commit comments

Comments
 (0)