Repository navigation
Expand file tree
/
Copy pathtest_notes.py
More file actions
221 lines (184 loc) · 6.61 KB
/
Copy pathtest_notes.py
File metadata and controls
221 lines (184 loc) · 6.61 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
from pathlib import Path
from textwrap import dedent
import pytest
from conftest import action, run
@pytest.fixture
def tagged_repository(repository: Path) -> Path:
(repository / "CHANGELOG.md").write_text(
dedent(
"""\
# Changelog
<!-- towncrier release notes start -->
<a name="release-0-2-0"></a>
## 0.2.0 (2026-10-20)
<a name="release-0-2-0-added"></a>
### Added
- Add a new feature ([#2](https://github.com/tox-dev/fixture/pull/2)) by
[@gaborbernat](https://github.com/gaborbernat).
""",
),
)
run(repository, "git", "add", "CHANGELOG.md")
run(repository, "git", "commit", "-m", "Release 0.2.0")
run(repository, "git", "tag", "0.2.0")
return repository
def test_render_release_notes_uses_tagged_changelog(
tagged_repository: Path, tmp_path: Path, action_scripts: Path
) -> None:
result = action(
tagged_repository,
tmp_path,
action_scripts,
"render-release-notes",
version="0.2.0",
TAG="0.2.0",
ARTIFACT_URL="https://pypi.org/project/fixture/0.2.0/",
)
assert result.returncode == 0, result.stderr
assert (tmp_path / "release-notes.md").read_text() == dedent(
"""\
<a name="release-0-2-0-added"></a>
### Features
- Add a new feature ([#2](https://github.com/tox-dev/fixture/pull/2)) by [@gaborbernat](https://github.com/gaborbernat).
[🐍 PyPI release](https://pypi.org/project/fixture/0.2.0/)
[📜 Full Changelog](https://github.com/tox-dev/fixture/compare/0.1.0...0.2.0)
""",
)
def test_render_release_notes_reports_previous_tag(
tagged_repository: Path, tmp_path: Path, action_scripts: Path
) -> None:
result = action(
tagged_repository,
tmp_path,
action_scripts,
"render-release-notes",
version="0.2.0",
TAG="0.2.0",
)
assert result.returncode == 0, result.stderr
assert "previous=0.1.0" in (tmp_path / "output").read_text()
def test_render_release_notes_accepts_first_release(
tagged_repository: Path, tmp_path: Path, action_scripts: Path
) -> None:
run(tagged_repository, "git", "tag", "-d", "0.1.0")
result = action(
tagged_repository,
tmp_path,
action_scripts,
"render-release-notes",
version="0.2.0",
TAG="0.2.0",
)
assert result.returncode == 0, result.stderr
assert "### Features" in (tmp_path / "release-notes.md").read_text()
assert "compare/" not in (tmp_path / "release-notes.md").read_text()
@pytest.mark.parametrize(
("role", "path"),
[pytest.param("pr", "pull", id="pull-request"), pytest.param("issue", "issues", id="issue")],
)
def test_render_release_notes_converts_rst_reference(
tagged_repository: Path, tmp_path: Path, action_scripts: Path, role: str, path: str
) -> None:
(tagged_repository / "CHANGELOG.rst").write_text(
f"0.2.0 (2026-10-20)\n==================\n\nFixed\n-----\n\n- Correct a bug (:{role}:`4`).\n",
)
result = action(
tagged_repository,
tmp_path,
action_scripts,
"render-release-notes",
version="0.2.0",
TAG="0.2.0",
CHANGELOG="CHANGELOG.rst",
)
assert result.returncode == 0, result.stderr
assert (
f"Correct a bug ([#4](https://github.com/tox-dev/fixture/{path}/4))"
in (tmp_path / "release-notes.md").read_text()
)
def test_render_release_notes_custom_artifact_label(
tagged_repository: Path, tmp_path: Path, action_scripts: Path
) -> None:
result = action(
tagged_repository,
tmp_path,
action_scripts,
"render-release-notes",
version="0.2.0",
TAG="0.2.0",
ARTIFACT_URL="https://github.com/tox-dev/fixture/releases/download/0.2.0/fixture.pyz",
ARTIFACT_LABEL="Zipapp",
)
assert result.returncode == 0, result.stderr
assert (
"[📦 Zipapp](https://github.com/tox-dev/fixture/releases/download/0.2.0/fixture.pyz)"
in (tmp_path / "release-notes.md").read_text()
)
def test_render_release_notes_lists_every_artifact_line(
tagged_repository: Path, tmp_path: Path, action_scripts: Path
) -> None:
result = action(
tagged_repository,
tmp_path,
action_scripts,
"render-release-notes",
version="0.2.0",
TAG="0.2.0",
ARTIFACT_URL="https://pypi.org/project/fixture/0.2.0/\nhttps://pypi.org/project/fixture-bare/0.2.0/\n",
ARTIFACT_LABEL="PyPI: fixture\nPyPI: fixture-bare\n",
)
assert result.returncode == 0, result.stderr
assert (
"[🐍 PyPI: fixture](https://pypi.org/project/fixture/0.2.0/), "
"[🐍 PyPI: fixture-bare](https://pypi.org/project/fixture-bare/0.2.0/)\n"
) in (tmp_path / "release-notes.md").read_text()
def test_render_release_notes_rejects_unpaired_labels(
tagged_repository: Path, tmp_path: Path, action_scripts: Path
) -> None:
result = action(
tagged_repository,
tmp_path,
action_scripts,
"render-release-notes",
version="0.2.0",
TAG="0.2.0",
ARTIFACT_URL="https://pypi.org/project/fixture/0.2.0/\nhttps://pypi.org/project/fixture-bare/0.2.0/",
ARTIFACT_LABEL="PyPI: fixture",
)
assert result.returncode != 0
assert "artifact-label has 1 lines for 2 artifact-url lines" in result.stdout
def test_render_release_notes_selects_package_section(
tagged_repository: Path, tmp_path: Path, action_scripts: Path
) -> None:
(tagged_repository / "CHANGELOG.md").write_text(
dedent(
"""\
# Changelog
## fixture
### 0.2.0 (2026-10-20)
#### Added
- Add a new feature ([#2](https://github.com/tox-dev/fixture/pull/2)) by
[@gaborbernat](https://github.com/gaborbernat).
## other
### 0.2.0 (2026-10-20)
#### Added
- Add a feature to the other package.
""",
),
)
run(tagged_repository, "git", "add", "CHANGELOG.md")
run(tagged_repository, "git", "commit", "-m", "Release fixture 0.2.0")
run(tagged_repository, "git", "tag", "fixture/0.2.0")
result = action(
tagged_repository,
tmp_path,
action_scripts,
"render-release-notes",
version="fixture/0.2.0",
TAG="fixture/0.2.0",
PACKAGE="fixture",
)
assert result.returncode == 0, result.stderr
notes = (tmp_path / "release-notes.md").read_text()
assert "Add a new feature" in notes
assert "other package" not in notes