forked from executablebooks/github-activity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli.py
More file actions
143 lines (116 loc) · 4.83 KB
/
Copy pathtest_cli.py
File metadata and controls
143 lines (116 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import shutil
from pathlib import Path
from subprocess import run
from pytest import mark
@mark.parametrize(
"cmd,basename",
[
# CLI with URL
(
"github-activity {url} -s 2021-01-01 -u 2021-01-15 -o {path_output}",
"cli_w_url",
),
# CLI with parts
(
"github-activity {org}/{repo} -s 2021-01-01 -u 2021-01-15 -o {path_output}",
"cli_w_parts",
),
# CLI with explicit branch filter (using master since that was likely the name in 2021)
(
"github-activity {org}/{repo} -s 2021-01-01 -u 2021-01-15 -o {path_output} -b master",
"cli_def_branch",
),
# CLI with no target
(
"github-activity -s 2021-01-01 -u 2021-01-15 -o {path_output}",
"cli_no_target",
),
],
)
def test_cli(tmpdir, file_regression, cmd, basename):
"""The output of all file_regressions should be the same, testing diff opts."""
path_tmp = Path(tmpdir)
path_output = path_tmp.joinpath("out.md")
url = "https://github.com/executablebooks/github-activity"
org, repo = ("executablebooks", "github-activity")
command = cmd.format(path_output=path_output, url=url, org=org, repo=repo)
run(command.split(), check=True)
md = path_output.read_text()
file_regression.check(md, basename=basename, extension=".md")
def test_cli_dot_config(tmp_path, monkeypatch, file_regression):
"""Test that pyproject.toml config is loaded"""
cmd = "github-activity -s 2021-01-01 -u 2021-01-15 -o {path_output}"
basename = "cli_no_target_pyproject"
path_output = tmp_path / "out.md"
# We need to augment the repository with a custom .githubactivity.json
# but since a local git repo is only needed to get the origin a shallow
# clone is enough
run(
[
"git",
"clone",
"--depth=1",
"https://github.com/executablebooks/github-activity",
str(tmp_path / "repo"),
],
check=True,
)
tests_dir = Path(__file__).parent
shutil.copyfile(
str(tests_dir / "resources" / "cli_no_target.githubactivity.json"),
str(tmp_path / "repo" / ".githubactivity.json"),
)
# cd into a subdirectory so we test the lookup of .githubactivity.json
monkeypatch.chdir(tmp_path / "repo" / "tests")
command = cmd.format(path_output=path_output)
run(command.split(), check=True)
md = path_output.read_text()
file_regression.check(md, basename=basename, extension=".md")
def test_cli_nonexistent_branch(tmpdir):
path_tmp = Path(tmpdir)
path_output = path_tmp.joinpath("out.md")
org, repo = ("executablebooks", "github-activity")
cmd = f"github-activity {org}/{repo} -s 2021-01-01 -u 2021-01-15 -o {path_output} -b foo"
run(cmd.split(), check=True)
md = path_output.read_text()
assert "Contributors to this release" in md
assert "Merged PRs" not in md
def test_pr_split(tmpdir, file_regression):
"""Test that PRs are properly split by tags/prefixes."""
path_tmp = Path(tmpdir)
path_output = path_tmp.joinpath("out.md")
url = "https://github.com/executablebooks/github-activity"
# Test PR tag/prefix splitting using recent consecutive releases
cmd = f"github-activity {url} -s v1.0.2 -u v1.0.3 -o {path_output}"
run(cmd.split(), check=True)
md = path_output.read_text()
md = md.split("## Contributors to this release")[0]
file_regression.check(md, extension=".md")
def test_cli_all(tmpdir, file_regression):
"""Test that a full changelog is created"""
path_tmp = Path(tmpdir)
path_output = path_tmp.joinpath("out.md")
# Use recent consecutive releases to reduce API calls
cmd = f"github-activity executablebooks/github-activity -s v1.0.2 -u v1.0.3 -o {path_output}"
run(cmd.split(), check=True)
md = path_output.read_text()
file_regression.check(md, extension=".md")
def test_cli_ignore_user(tmpdir):
"""Test that a full changelog is created"""
path_tmp = Path(tmpdir)
path_output = path_tmp.joinpath("out.md")
# Add end date to limit query range
cmd = f"github-activity executablebooks/github-activity --ignore-contributor choldgraf -s v1.0.2 -u v1.0.3 -o {path_output}"
run(cmd.split(), check=True)
md = path_output.read_text()
assert "@choldgraf" not in md
def test_contributor_sorting(tmpdir, file_regression):
"""Test that PR author appears first, then rest of contributors, sorted"""
path_tmp = Path(tmpdir)
path_output = path_tmp.joinpath("out.md")
org, repo = ("executablebooks", "github-activity")
# Test contributor sorting using recent consecutive releases
cmd = f"github-activity {org}/{repo} -s v0.2.0 -u v0.3.0 -o {path_output}"
run(cmd.split(), check=True)
md = path_output.read_text()
file_regression.check(md, extension=".md")