Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1cbcff6

Browse files
author
Jan Willhaus
committed
test(bump): provide tests for update_changelog_on_bump config option
1 parent 970acb9 commit 1cbcff6

File tree

4 files changed

+62
-6
lines changed

4 files changed

+62
-6
lines changed

tests/commands/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import pytest
24

35
from commitizen import defaults
@@ -9,3 +11,13 @@ def config():
911
_config = BaseConfig()
1012
_config.settings.update({"name": defaults.name})
1113
return _config
14+
15+
16+
@pytest.fixture()
17+
def changelog_path() -> str:
18+
return os.path.join(os.getcwd(), "CHANGELOG.md")
19+
20+
21+
@pytest.fixture()
22+
def config_path() -> str:
23+
return os.path.join(os.getcwd(), "pyproject.toml")

tests/commands/test_bump_command.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import inspect
2+
import os
23
import sys
34
from unittest.mock import MagicMock
45

@@ -301,3 +302,50 @@ def test_none_increment_should_not_call_git_tag(mocker, tmp_commitizen_project):
301302

302303
# restore pop stashed
303304
git.tag = stashed_git_tag
305+
306+
307+
@pytest.mark.usefixtures("tmp_commitizen_project")
308+
def test_bump_with_changelog_arg(mocker, changelog_path):
309+
create_file_and_commit("feat(user): new file")
310+
testargs = ["cz", "bump", "--yes", "--changelog"]
311+
mocker.patch.object(sys, "argv", testargs)
312+
cli.main()
313+
tag_exists = git.tag_exist("0.2.0")
314+
assert tag_exists is True
315+
316+
with open(changelog_path, "r") as f:
317+
out = f.read()
318+
assert out.startswith("#")
319+
assert "0.2.0" in out
320+
321+
322+
@pytest.mark.usefixtures("tmp_commitizen_project")
323+
def test_bump_with_changelog_config(mocker, changelog_path, config_path):
324+
create_file_and_commit("feat(user): new file")
325+
with open(config_path, "a") as fp:
326+
fp.write("update_changelog_on_bump = true\n")
327+
328+
testargs = ["cz", "bump", "--yes"]
329+
mocker.patch.object(sys, "argv", testargs)
330+
cli.main()
331+
tag_exists = git.tag_exist("0.2.0")
332+
assert tag_exists is True
333+
334+
with open(changelog_path, "r") as f:
335+
out = f.read()
336+
assert out.startswith("#")
337+
assert "0.2.0" in out
338+
339+
340+
@pytest.mark.usefixtures("tmp_commitizen_project")
341+
def test_bump_with_negated_changelog_config(mocker, changelog_path, config_path):
342+
create_file_and_commit("feat(user): new file")
343+
with open(config_path, "a") as fp:
344+
fp.write("update_changelog_on_bump = true\n")
345+
346+
testargs = ["cz", "bump", "--yes", "--no-changelog"]
347+
mocker.patch.object(sys, "argv", testargs)
348+
cli.main()
349+
tag_exists = git.tag_exist("0.2.0")
350+
assert tag_exists is True
351+
assert not os.path.exists(changelog_path)

tests/commands/test_changelog_command.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import sys
32
from datetime import date
43

@@ -15,11 +14,6 @@
1514
from tests.utils import create_file_and_commit
1615

1716

18-
@pytest.fixture()
19-
def changelog_path() -> str:
20-
return os.path.join(os.getcwd(), "CHANGELOG.md")
21-
22-
2317
@pytest.mark.usefixtures("tmp_commitizen_project")
2418
def test_changelog_on_empty_project(mocker):
2519
testargs = ["cz", "changelog", "--dry-run"]

tests/test_conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"version_files": ["commitizen/__version__.py", "pyproject.toml"],
3333
"style": [["pointer", "reverse"], ["question", "underline"]],
3434
"changelog_file": "CHANGELOG.md",
35+
"update_changelog_on_bump": False,
3536
}
3637

3738
_new_settings = {
@@ -42,6 +43,7 @@
4243
"version_files": ["commitizen/__version__.py", "pyproject.toml"],
4344
"style": [["pointer", "reverse"], ["question", "underline"]],
4445
"changelog_file": "CHANGELOG.md",
46+
"update_changelog_on_bump": False,
4547
}
4648

4749
_read_settings = {

0 commit comments

Comments
 (0)