9
9
from tests .utils import create_file_and_commit
10
10
11
11
12
+ @pytest .fixture ()
13
+ def changelog_path () -> str :
14
+ return os .path .join (os .getcwd (), "CHANGELOG.md" )
15
+
16
+
12
17
@pytest .mark .usefixtures ("tmp_commitizen_project" )
13
18
def test_changlog_on_empty_project (mocker ):
14
19
testargs = ["cz" , "changelog" , "--dry-run" ]
@@ -38,7 +43,7 @@ def test_changlog_from_version_zero_point_two(mocker, capsys):
38
43
cli .main ()
39
44
40
45
out , _ = capsys .readouterr ()
41
- assert out == "\n ## Unreleased\n \n ### Feat\n \n - after 0.2\n - after 0.2.0\n \n "
46
+ assert out == "## Unreleased\n \n ### Feat\n \n - after 0.2\n - after 0.2.0\n \n "
42
47
43
48
44
49
@pytest .mark .usefixtures ("tmp_commitizen_project" )
@@ -54,13 +59,12 @@ def test_changlog_with_different_cz(mocker, capsys):
54
59
out , _ = capsys .readouterr ()
55
60
assert (
56
61
out
57
- == "\n ## Unreleased\n \n \n - JRA-35 #time 1w 2d 4h 30m Total work logged\n - JRA-34 #comment corrected indent issue\n \n "
62
+ == "## Unreleased\n \n \n - JRA-35 #time 1w 2d 4h 30m Total work logged\n - JRA-34 #comment corrected indent issue\n \n "
58
63
)
59
64
60
65
61
66
@pytest .mark .usefixtures ("tmp_commitizen_project" )
62
- def test_changlog_from_start (mocker , capsys ):
63
- changelog_path = os .path .join (os .getcwd (), "CHANGELOG.md" )
67
+ def test_changlog_from_start (mocker , capsys , changelog_path ):
64
68
create_file_and_commit ("feat: new file" )
65
69
create_file_and_commit ("refactor: is in changelog" )
66
70
create_file_and_commit ("Merge into master" )
@@ -74,14 +78,14 @@ def test_changlog_from_start(mocker, capsys):
74
78
75
79
assert (
76
80
out
77
- == "\n ## Unreleased\n \n ### Refactor\n \n - is in changelog\n \n ### Feat\n \n - new file\n "
81
+ == "## Unreleased\n \n ### Refactor\n \n - is in changelog\n \n ### Feat\n \n - new file\n "
78
82
)
79
83
80
84
81
85
@pytest .mark .usefixtures ("tmp_commitizen_project" )
82
- def test_changlog_replacing_unreleased_using_incremental (mocker , capsys ):
83
- changelog_path = os . path . join ( os . getcwd (), "CHANGELOG.md" )
84
-
86
+ def test_changlog_replacing_unreleased_using_incremental (
87
+ mocker , capsys , changelog_path
88
+ ):
85
89
create_file_and_commit ("feat: add new output" )
86
90
create_file_and_commit ("fix: output glitch" )
87
91
create_file_and_commit ("Merge into master" )
@@ -108,13 +112,12 @@ def test_changlog_replacing_unreleased_using_incremental(mocker, capsys):
108
112
today = date .today ().isoformat ()
109
113
assert (
110
114
out
111
- == f"\n \n ## Unreleased\n \n ### Feat\n \n - add more stuff\n \n ### Fix\n \n - mama gotta work\n \n ## 0.2.0 ({ today } )\n \n ### Fix\n \n - output glitch\n \n ### Feat\n \n - add new output\n "
115
+ == f"## Unreleased\n \n ### Feat\n \n - add more stuff\n \n ### Fix\n \n - mama gotta work\n \n ## 0.2.0 ({ today } )\n \n ### Fix\n \n - output glitch\n \n ### Feat\n \n - add new output\n "
112
116
)
113
117
114
118
115
119
@pytest .mark .usefixtures ("tmp_commitizen_project" )
116
- def test_changlog_is_persisted_using_incremental (mocker , capsys ):
117
- changelog_path = os .path .join (os .getcwd (), "CHANGELOG.md" )
120
+ def test_changlog_is_persisted_using_incremental (mocker , capsys , changelog_path ):
118
121
119
122
create_file_and_commit ("feat: add new output" )
120
123
create_file_and_commit ("fix: output glitch" )
@@ -146,13 +149,12 @@ def test_changlog_is_persisted_using_incremental(mocker, capsys):
146
149
today = date .today ().isoformat ()
147
150
assert (
148
151
out
149
- == f"\n \n ## Unreleased\n \n ### Feat\n \n - add more stuff\n \n ### Fix\n \n - mama gotta work\n \n ## 0.2.0 ({ today } )\n \n ### Fix\n \n - output glitch\n \n ### Feat\n \n - add new output\n \n note: this should be persisted using increment\n "
152
+ == f"## Unreleased\n \n ### Feat\n \n - add more stuff\n \n ### Fix\n \n - mama gotta work\n \n ## 0.2.0 ({ today } )\n \n ### Fix\n \n - output glitch\n \n ### Feat\n \n - add new output\n \n note: this should be persisted using increment\n "
150
153
)
151
154
152
155
153
156
@pytest .mark .usefixtures ("tmp_commitizen_project" )
154
- def test_changlog_incremental_angular_sample (mocker , capsys ):
155
- changelog_path = os .path .join (os .getcwd (), "CHANGELOG.md" )
157
+ def test_changlog_incremental_angular_sample (mocker , capsys , changelog_path ):
156
158
with open (changelog_path , "w" ) as f :
157
159
f .write (
158
160
"# [10.0.0-next.3](https://github.com/angular/angular/compare/10.0.0-next.2...10.0.0-next.3) (2020-04-22)\n "
@@ -180,7 +182,7 @@ def test_changlog_incremental_angular_sample(mocker, capsys):
180
182
181
183
assert (
182
184
out
183
- == "\n ## Unreleased\n \n ### Feat\n \n - add more stuff\n - add new output\n \n ### Fix\n \n - mama gotta work\n - output glitch\n \n # [10.0.0-next.3](https://github.com/angular/angular/compare/10.0.0-next.2...10.0.0-next.3) (2020-04-22)\n \n ### Bug Fixes\n * **common:** format day-periods that cross midnight ([#36611](https://github.com/angular/angular/issues/36611)) ([c6e5fc4](https://github.com/angular/angular/commit/c6e5fc4)), closes [#36566](https://github.com/angular/angular/issues/36566)\n "
185
+ == "## Unreleased\n \n ### Feat\n \n - add more stuff\n - add new output\n \n ### Fix\n \n - mama gotta work\n - output glitch\n \n # [10.0.0-next.3](https://github.com/angular/angular/compare/10.0.0-next.2...10.0.0-next.3) (2020-04-22)\n \n ### Bug Fixes\n * **common:** format day-periods that cross midnight ([#36611](https://github.com/angular/angular/issues/36611)) ([c6e5fc4](https://github.com/angular/angular/commit/c6e5fc4)), closes [#36566](https://github.com/angular/angular/issues/36566)\n "
184
186
)
185
187
186
188
@@ -210,8 +212,7 @@ def test_changlog_incremental_angular_sample(mocker, capsys):
210
212
211
213
212
214
@pytest .mark .usefixtures ("tmp_commitizen_project" )
213
- def test_changlog_incremental_keep_a_changelog_sample (mocker , capsys ):
214
- changelog_path = os .path .join (os .getcwd (), "CHANGELOG.md" )
215
+ def test_changlog_incremental_keep_a_changelog_sample (mocker , capsys , changelog_path ):
215
216
with open (changelog_path , "w" ) as f :
216
217
f .write (KEEP_A_CHANGELOG )
217
218
create_file_and_commit ("irrelevant commit" )
@@ -233,7 +234,7 @@ def test_changlog_incremental_keep_a_changelog_sample(mocker, capsys):
233
234
234
235
assert (
235
236
out
236
- == """# Changelog\n All notable changes to this project will be documented in this file.\n \n The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),\n and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n \n \n ## Unreleased\n \n ### Feat\n \n - add more stuff\n - add new output\n \n ### Fix\n \n - mama gotta work\n - output glitch\n \n ## [1.0.0] - 2017-06-20\n ### Added\n - New visual identity by [@tylerfortune8](https://github.com/tylerfortune8).\n - Version navigation.\n \n ### Changed\n - Start using "changelog" over "change log" since it\' s the common usage.\n \n ### Removed\n - Section about "changelog" vs "CHANGELOG".\n \n ## [0.3.0] - 2015-12-03\n ### Added\n - RU translation from [@aishek](https://github.com/aishek).\n """
237
+ == """# Changelog\n All notable changes to this project will be documented in this file.\n \n The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),\n and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n \n ## Unreleased\n \n ### Feat\n \n - add more stuff\n - add new output\n \n ### Fix\n \n - mama gotta work\n - output glitch\n \n ## [1.0.0] - 2017-06-20\n ### Added\n - New visual identity by [@tylerfortune8](https://github.com/tylerfortune8).\n - Version navigation.\n \n ### Changed\n - Start using "changelog" over "change log" since it\' s the common usage.\n \n ### Removed\n - Section about "changelog" vs "CHANGELOG".\n \n ## [0.3.0] - 2015-12-03\n ### Added\n - RU translation from [@aishek](https://github.com/aishek).\n """
237
238
)
238
239
239
240
@@ -251,6 +252,43 @@ def test_changlog_hook(mocker, config):
251
252
)
252
253
mocker .patch .object (changelog .cz , "changelog_hook" , changelog_hook_mock )
253
254
changelog ()
254
- full_changelog = "\n ## Unreleased\n \n ### Refactor\n \n - is in changelog\n \n ### Feat\n \n - new file\n "
255
+ full_changelog = (
256
+ "## Unreleased\n \n ### Refactor\n \n - is in changelog\n \n ### Feat\n \n - new file\n "
257
+ )
255
258
256
259
changelog_hook_mock .assert_called_with (full_changelog , full_changelog )
260
+
261
+
262
+ @pytest .mark .usefixtures ("tmp_commitizen_project" )
263
+ def test_changlog_multiple_incremental_do_not_add_new_lines (
264
+ mocker , capsys , changelog_path
265
+ ):
266
+ """Test for bug https://github.com/commitizen-tools/commitizen/issues/192"""
267
+ create_file_and_commit ("feat: add new output" )
268
+
269
+ testargs = ["cz" , "changelog" , "--incremental" ]
270
+ mocker .patch .object (sys , "argv" , testargs )
271
+ cli .main ()
272
+
273
+ create_file_and_commit ("fix: output glitch" )
274
+
275
+ testargs = ["cz" , "changelog" , "--incremental" ]
276
+ mocker .patch .object (sys , "argv" , testargs )
277
+ cli .main ()
278
+
279
+ create_file_and_commit ("fix: mama gotta work" )
280
+
281
+ testargs = ["cz" , "changelog" , "--incremental" ]
282
+ mocker .patch .object (sys , "argv" , testargs )
283
+ cli .main ()
284
+
285
+ create_file_and_commit ("feat: add more stuff" )
286
+
287
+ testargs = ["cz" , "changelog" , "--incremental" ]
288
+ mocker .patch .object (sys , "argv" , testargs )
289
+ cli .main ()
290
+
291
+ with open (changelog_path , "r" ) as f :
292
+ out = f .read ()
293
+
294
+ assert out .startswith ("#" )
0 commit comments