Debian Codegraph @

script/test_bump_changelog.py

raw
1 # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
2 # For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE
3 # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt
4
5 import logging
6
7 import pytest
8 from bump_changelog import (
9 VersionType,
10 get_next_version,
11 get_next_versions,
12 transform_content,
13 )
14
15
16 @pytest.mark.parametrize(
17 "version,version_type,expected_version,expected_versions",
18 [
19 ["2.6.1", VersionType.PATCH, "2.6.2", ["2.6.2"]],
20 ["2.10.0", VersionType.MINOR, "2.11.0", ["2.11.0", "2.10.1"]],
21 ["10.1.10", VersionType.PATCH, "10.1.11", ["10.1.11"]],
22 [
23 "2.6.0",
24 VersionType.MINOR,
25 "2.7.0",
26 [
27 "2.7.0",
28 "2.6.1",
29 ],
30 ],
31 ["2.6.1", VersionType.MAJOR, "3.0.0", ["3.1.0", "3.0.1"]],
32 ["2.6.1-dev0", VersionType.PATCH, "2.6.2", ["2.6.2"]],
33 [
34 "2.6.1-dev0",
35 VersionType.MINOR,
36 "2.7.0",
37 [
38 "2.7.1",
39 "2.7.0",
40 ],
41 ],
42 ["2.6.1-dev0", VersionType.MAJOR, "3.0.0", ["3.1.0", "3.0.1"]],
43 ["2.7.0", VersionType.PATCH, "2.7.1", ["2.7.1"]],
44 ["2.7.0", VersionType.MINOR, "2.8.0", ["2.8.0", "2.7.1"]],
45 ["2.7.0", VersionType.MAJOR, "3.0.0", ["3.1.0", "3.0.1"]],
46 ["2.0.0", VersionType.PATCH, "2.0.1", ["2.0.1"]],
47 ["2.0.0", VersionType.MINOR, "2.1.0", ["2.1.0", "2.0.1"]],
48 ["2.0.0", VersionType.MAJOR, "3.0.0", ["3.1.0", "3.0.1"]],
49 ],
50 )
51 def test_get_next_version(version, version_type, expected_version, expected_versions):
52 assert get_next_version(version, version_type) == expected_version
53 if version_type == VersionType.PATCH or (
54 version_type == VersionType.MINOR and version.endswith(".0")
55 ):
56 assert get_next_versions(version, version_type) == expected_versions
57
58
59 @pytest.mark.parametrize(
60 "old_content,version,expected_error",
61 [
62 [
63 """
64 What's New in astroid 2.7.0?
65 ============================
66 Release date: TBA
67
68 What's New in astroid 2.6.1?
69 ============================
70 Release date: TBA
71
72 What's New in astroid 2.6.0?
73 ============================
74 Release date: TBA
75 """,
76 "2.6.1",
77 r"There should be only two release dates 'TBA' \(2.6.1 and 2.7.0\)",
78 ],
79 [
80 """===================
81 astroid's ChangeLog
82 ===================
83
84 What's New in astroid 2.6.0?
85 ============================
86 Release date: TBA
87 """,
88 "2.6.1",
89 "text for this version '2.6.1' did not exists",
90 ],
91 [
92 """
93 What's New in astroid 2.6.2?
94 ============================
95 Release date: TBA
96
97 What's New in astroid 2.6.1?
98 ============================
99 Release date: TBA
100 """,
101 "2.6.1",
102 "The text for the next version '2.6.2' already exists",
103 ],
104 [
105 """
106 What's New in astroid 3.0.0?
107 ============================
108 Release date: TBA
109
110 What's New in astroid 2.6.10?
111 ============================
112 Release date: TBA
113 """,
114 "3.0.0",
115 r"There should be only one release date 'TBA' \(3.0.0\)",
116 ],
117 [
118 """
119 What's New in astroid 2.7.0?
120 ============================
121 Release date: TBA
122
123 What's New in astroid 2.6.10?
124 ============================
125 Release date: TBA
126 """,
127 "2.7.0",
128 r"There should be only one release date 'TBA' \(2.7.0\)",
129 ],
130 ],
131 )
132 def test_update_content_error(old_content, version, expected_error, caplog):
133 caplog.set_level(logging.DEBUG)
134 with pytest.raises(AssertionError, match=expected_error):
135 transform_content(old_content, version)
136
137
138 def test_update_content(caplog):
139 caplog.set_level(logging.DEBUG)
140 old_content = """
141 ===================
142 astroid's ChangeLog
143 ===================
144
145 What's New in astroid 2.6.1?
146 ============================
147 Release date: TBA
148 """
149 expected_beginning = """
150 ===================
151 astroid's ChangeLog
152 ===================
153
154 What's New in astroid 2.6.2?
155 ============================
156 Release date: TBA
157
158
159
160 What's New in astroid 2.6.1?
161 ============================
162 Release date: 20"""
163
164 new_content = transform_content(old_content, "2.6.1")
165 assert new_content[: len(expected_beginning)] == expected_beginning
166
167
168 def test_update_content_minor():
169 old_content = """
170 ===================
171 astroid's ChangeLog
172 ===================
173
174 What's New in astroid 2.7.0?
175 ============================
176 Release date: TBA
177 """
178 expected_beginning = """
179 ===================
180 astroid's ChangeLog
181 ===================
182
183 What's New in astroid 2.8.0?
184 ============================
185 Release date: TBA
186
187
188
189 What's New in astroid 2.7.1?
190 ============================
191 Release date: TBA
192
193
194
195 What's New in astroid 2.7.0?
196 ============================
197 Release date: 20"""
198
199 new_content = transform_content(old_content, "2.7.0")
200 assert new_content[: len(expected_beginning)] == expected_beginning
201
202
203 def test_update_content_major(caplog):
204 caplog.set_level(logging.DEBUG)
205 old_content = """
206 ===================
207 astroid's ChangeLog
208 ===================
209
210 What's New in astroid 3.0.0?
211 ============================
212 Release date: TBA
213
214 What's New in astroid 2.7.1?
215 ============================
216 Release date: 2020-04-03
217
218 What's New in astroid 2.7.0?
219 ============================
220 Release date: 2020-04-01
221 """
222 expected_beginning = """
223 ===================
224 astroid's ChangeLog
225 ===================
226
227 What's New in astroid 3.1.0?
228 ============================
229 Release date: TBA
230
231
232
233 What's New in astroid 3.0.1?
234 ============================
235 Release date: TBA
236
237
238
239 What's New in astroid 3.0.0?
240 ============================
241 Release date: 20"""
242 new_content = transform_content(old_content, "3.0.0")
243 assert new_content[: len(expected_beginning)] == expected_beginning