11import sys
2- from datetime import date
32
43import pytest
54
@@ -27,7 +26,7 @@ def test_changelog_on_empty_project(mocker):
2726
2827
2928@pytest .mark .usefixtures ("tmp_commitizen_project" )
30- def test_changelog_from_version_zero_point_two (mocker , capsys ):
29+ def test_changelog_from_version_zero_point_two (mocker , capsys , file_regression ):
3130 create_file_and_commit ("feat: new file" )
3231 create_file_and_commit ("refactor: not in changelog" )
3332
@@ -46,11 +45,11 @@ def test_changelog_from_version_zero_point_two(mocker, capsys):
4645 cli .main ()
4746
4847 out , _ = capsys .readouterr ()
49- assert out == "## Unreleased \n \n ### Feat \n \n - after 0.2 \n - after 0.2.0 \n \n "
48+ file_regression . check ( out , extension = ".md" )
5049
5150
5251@pytest .mark .usefixtures ("tmp_commitizen_project" )
53- def test_changelog_with_different_cz (mocker , capsys ):
52+ def test_changelog_with_different_cz (mocker , capsys , file_regression ):
5453 create_file_and_commit ("JRA-34 #comment corrected indent issue" )
5554 create_file_and_commit ("JRA-35 #time 1w 2d 4h 30m Total work logged" )
5655
@@ -60,14 +59,11 @@ def test_changelog_with_different_cz(mocker, capsys):
6059 with pytest .raises (DryRunExit ):
6160 cli .main ()
6261 out , _ = capsys .readouterr ()
63- assert (
64- out
65- == "## Unreleased\n \n \n - JRA-35 #time 1w 2d 4h 30m Total work logged\n - JRA-34 #comment corrected indent issue\n \n "
66- )
62+ file_regression .check (out , extension = ".md" )
6763
6864
6965@pytest .mark .usefixtures ("tmp_commitizen_project" )
70- def test_changelog_from_start (mocker , capsys , changelog_path ):
66+ def test_changelog_from_start (mocker , capsys , changelog_path , file_regression ):
7167 create_file_and_commit ("feat: new file" )
7268 create_file_and_commit ("refactor: is in changelog" )
7369 create_file_and_commit ("Merge into master" )
@@ -78,16 +74,12 @@ def test_changelog_from_start(mocker, capsys, changelog_path):
7874
7975 with open (changelog_path , "r" ) as f :
8076 out = f .read ()
81-
82- assert (
83- out
84- == "## Unreleased\n \n ### Refactor\n \n - is in changelog\n \n ### Feat\n \n - new file\n "
85- )
77+ file_regression .check (out , extension = ".md" )
8678
8779
8880@pytest .mark .usefixtures ("tmp_commitizen_project" )
8981def test_changelog_replacing_unreleased_using_incremental (
90- mocker , capsys , changelog_path
82+ mocker , capsys , changelog_path , file_regression
9183):
9284 create_file_and_commit ("feat: add new output" )
9385 create_file_and_commit ("fix: output glitch" )
@@ -112,15 +104,13 @@ def test_changelog_replacing_unreleased_using_incremental(
112104 with open (changelog_path , "r" ) as f :
113105 out = f .read ()
114106
115- today = date .today ().isoformat ()
116- assert (
117- out
118- == 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 "
119- )
107+ file_regression .check (out , extension = ".md" )
120108
121109
122110@pytest .mark .usefixtures ("tmp_commitizen_project" )
123- def test_changelog_is_persisted_using_incremental (mocker , capsys , changelog_path ):
111+ def test_changelog_is_persisted_using_incremental (
112+ mocker , capsys , changelog_path , file_regression
113+ ):
124114
125115 create_file_and_commit ("feat: add new output" )
126116 create_file_and_commit ("fix: output glitch" )
@@ -149,15 +139,13 @@ def test_changelog_is_persisted_using_incremental(mocker, capsys, changelog_path
149139 with open (changelog_path , "r" ) as f :
150140 out = f .read ()
151141
152- today = date .today ().isoformat ()
153- assert (
154- out
155- == 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 "
156- )
142+ file_regression .check (out , extension = ".md" )
157143
158144
159145@pytest .mark .usefixtures ("tmp_commitizen_project" )
160- def test_changelog_incremental_angular_sample (mocker , capsys , changelog_path ):
146+ def test_changelog_incremental_angular_sample (
147+ mocker , capsys , changelog_path , file_regression
148+ ):
161149 with open (changelog_path , "w" ) as f :
162150 f .write (
163151 "# [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 "
@@ -183,10 +171,7 @@ def test_changelog_incremental_angular_sample(mocker, capsys, changelog_path):
183171 with open (changelog_path , "r" ) as f :
184172 out = f .read ()
185173
186- assert (
187- out
188- == "## 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 "
189- )
174+ file_regression .check (out , extension = ".md" )
190175
191176
192177KEEP_A_CHANGELOG = """# Changelog
@@ -215,7 +200,9 @@ def test_changelog_incremental_angular_sample(mocker, capsys, changelog_path):
215200
216201
217202@pytest .mark .usefixtures ("tmp_commitizen_project" )
218- def test_changelog_incremental_keep_a_changelog_sample (mocker , capsys , changelog_path ):
203+ def test_changelog_incremental_keep_a_changelog_sample (
204+ mocker , capsys , changelog_path , file_regression
205+ ):
219206 with open (changelog_path , "w" ) as f :
220207 f .write (KEEP_A_CHANGELOG )
221208 create_file_and_commit ("irrelevant commit" )
@@ -235,10 +222,7 @@ def test_changelog_incremental_keep_a_changelog_sample(mocker, capsys, changelog
235222 with open (changelog_path , "r" ) as f :
236223 out = f .read ()
237224
238- assert (
239- out
240- == """# 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 """
241- )
225+ file_regression .check (out , extension = ".md" )
242226
243227
244228@pytest .mark .usefixtures ("tmp_commitizen_project" )
@@ -287,7 +271,7 @@ def test_changelog_hook_customize(mocker, config_customize):
287271
288272@pytest .mark .usefixtures ("tmp_commitizen_project" )
289273def test_changelog_multiple_incremental_do_not_add_new_lines (
290- mocker , capsys , changelog_path
274+ mocker , capsys , changelog_path , file_regression
291275):
292276 """Test for bug https://github.com/commitizen-tools/commitizen/issues/192"""
293277 create_file_and_commit ("feat: add new output" )
@@ -317,7 +301,7 @@ def test_changelog_multiple_incremental_do_not_add_new_lines(
317301 with open (changelog_path , "r" ) as f :
318302 out = f .read ()
319303
320- assert out . startswith ( "# " )
304+ file_regression . check ( out , extension = ".md " )
321305
322306
323307@pytest .mark .usefixtures ("tmp_commitizen_project" )
@@ -394,7 +378,7 @@ def test_changelog_in_non_git_project(tmpdir, config, mocker):
394378
395379
396380@pytest .mark .usefixtures ("tmp_commitizen_project" )
397- def test_breaking_change_content_v1_beta (mocker , capsys ):
381+ def test_breaking_change_content_v1_beta (mocker , capsys , file_regression ):
398382 commit_message = (
399383 "feat(users): email pattern corrected\n \n "
400384 "BREAKING CHANGE: migrate by renaming user to users\n \n "
@@ -406,15 +390,11 @@ def test_breaking_change_content_v1_beta(mocker, capsys):
406390 with pytest .raises (DryRunExit ):
407391 cli .main ()
408392 out , _ = capsys .readouterr ()
409-
410- assert out == (
411- "## Unreleased\n \n ### Feat\n \n - **users**: email pattern corrected\n \n "
412- "### BREAKING CHANGE\n \n - migrate by renaming user to users\n \n "
413- )
393+ file_regression .check (out , extension = ".md" )
414394
415395
416396@pytest .mark .usefixtures ("tmp_commitizen_project" )
417- def test_breaking_change_content_v1 (mocker , capsys ):
397+ def test_breaking_change_content_v1 (mocker , capsys , file_regression ):
418398 commit_message = (
419399 "feat(users): email pattern corrected\n \n "
420400 "body content\n \n "
@@ -427,14 +407,11 @@ def test_breaking_change_content_v1(mocker, capsys):
427407 cli .main ()
428408 out , _ = capsys .readouterr ()
429409
430- assert out == (
431- "## Unreleased\n \n ### Feat\n \n - **users**: email pattern corrected\n \n "
432- "### BREAKING CHANGE\n \n - migrate by renaming user to users\n \n "
433- )
410+ file_regression .check (out , extension = ".md" )
434411
435412
436413@pytest .mark .usefixtures ("tmp_commitizen_project" )
437- def test_breaking_change_content_v1_multiline (mocker , capsys ):
414+ def test_breaking_change_content_v1_multiline (mocker , capsys , file_regression ):
438415 commit_message = (
439416 "feat(users): email pattern corrected\n \n "
440417 "body content\n \n "
@@ -448,17 +425,13 @@ def test_breaking_change_content_v1_multiline(mocker, capsys):
448425 with pytest .raises (DryRunExit ):
449426 cli .main ()
450427 out , _ = capsys .readouterr ()
451-
452- assert out == (
453- "## Unreleased\n \n ### Feat\n \n - **users**: email pattern corrected\n \n "
454- "### BREAKING CHANGE\n \n - migrate by renaming user to users.\n "
455- "and then connect the thingy with the other thingy"
456- "\n \n "
457- )
428+ file_regression .check (out , extension = ".md" )
458429
459430
460431@pytest .mark .usefixtures ("tmp_commitizen_project" )
461- def test_changelog_config_flag_increment (mocker , changelog_path , config_path ):
432+ def test_changelog_config_flag_increment (
433+ mocker , changelog_path , config_path , file_regression
434+ ):
462435
463436 with open (config_path , "a" ) as f :
464437 f .write ("changelog_incremental = true\n " )
@@ -475,10 +448,13 @@ def test_changelog_config_flag_increment(mocker, changelog_path, config_path):
475448 out = f .read ()
476449
477450 assert "this should be persisted using increment" in out
451+ file_regression .check (out , extension = ".md" )
478452
479453
480454@pytest .mark .usefixtures ("tmp_commitizen_project" )
481- def test_changelog_config_start_rev_option (mocker , capsys , config_path ):
455+ def test_changelog_config_start_rev_option (
456+ mocker , capsys , config_path , file_regression
457+ ):
482458
483459 # create commit and tag
484460 create_file_and_commit ("feat: new file" )
@@ -499,7 +475,7 @@ def test_changelog_config_start_rev_option(mocker, capsys, config_path):
499475 cli .main ()
500476
501477 out , _ = capsys .readouterr ()
502- assert out == "## Unreleased \n \n ### Feat \n \n - after 0.2 \n - after 0.2.0 \n \n "
478+ file_regression . check ( out , extension = ".md" )
503479
504480
505481@pytest .mark .usefixtures ("tmp_commitizen_project" )
0 commit comments