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
134 lines (112 loc) · 4.63 KB
/
test_cli.py
File metadata and controls
134 lines (112 loc) · 4.63 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
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_changelog_features(file_regression):
"""Combined test for multiple changelog features to minimize API calls.
This tests a few things in one regression test.
"""
from github_activity.github_activity import generate_activity_md
# This is a release that has dependabot activity, so we test that it no longer
# shows up in the changelog. It *will* show up in the release below because it's
# from before this feature was implemented.
# ref: https://github.com/executablebooks/github-activity/releases/tag/v1.1.0
org = "executablebooks"
repo = "github-activity"
since = "v1.0.2"
until = "v1.1.0"
# Test general changelog structure with a regression test
# PRs should be split by issue label.
md_full = generate_activity_md(
target=f"{org}/{repo}",
since=since,
until=until,
ignored_contributors=["choldgraf"],
)
file_regression.check(md_full, basename="test_cli_all", extension=".md")
# Test that contributor sorting works, minus @choldgraf since we filtered him out (sorry Chris)
assert (
"- Allow excluding certain usernames from changelog [#128](https://github.com/executablebooks/github-activity/pull/128) ([@stefanv](https://github.com/stefanv), [@bsipocz](https://github.com/bsipocz), [@nabobalis](https://github.com/nabobalis))"
in md_full
), "Contributors should be sorted as expected"
# Test that ignored usernames are ignored
assert "@choldgraf" not in md_full.lower(), (
"Ignored contributor should not appear in output"
)
# Test that bots are removed
assert "@dependabot" not in md_full.lower(), (
"Bot user dependabot should not appear in output"
)