|
1 | 1 | from pathlib import Path |
2 | 2 | from subprocess import run |
3 | 3 |
|
| 4 | +from pytest import mark |
4 | 5 |
|
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): |
6 | 33 | """The output of all file_regressions should be the same, testing diff opts.""" |
7 | 34 | path_tmp = Path(tmpdir) |
8 | 35 | path_output = path_tmp.joinpath("out.md") |
9 | 36 |
|
10 | 37 | url = "https://github.com/executablebooks/github-activity" |
11 | 38 | org, repo = ("executablebooks", "github-activity") |
12 | 39 |
|
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) |
16 | 42 | 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") |
18 | 44 |
|
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") |
24 | 45 |
|
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") |
30 | 51 |
|
31 | | - # CLI with non-existent branch |
32 | 52 | cmd = f"github-activity {org}/{repo} -s 2019-09-01 -u 2019-11-01 -o {path_output} -b foo" |
33 | 53 | run(cmd.split(), check=True) |
34 | 54 | md = path_output.read_text() |
35 | 55 | assert "Contributors to this release" in md |
36 | 56 | assert "Merged PRs" not in md |
37 | 57 |
|
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 | | - |
44 | 58 |
|
45 | 59 | def test_pr_split(tmpdir, file_regression): |
46 | 60 | """Test that PRs are properly split by tags/prefixes.""" |
|
0 commit comments