Skip to content

Commit

Permalink
test: provide tests for update_changelog_on_bump config option
Browse files Browse the repository at this point in the history
  • Loading branch information
janw authored and Lee-W committed Nov 4, 2020
1 parent 9263057 commit 7a2bf96
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
12 changes: 12 additions & 0 deletions tests/commands/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import pytest

from commitizen import defaults
Expand All @@ -9,3 +11,13 @@ def config():
_config = BaseConfig()
_config.settings.update({"name": defaults.name})
return _config


@pytest.fixture()
def changelog_path() -> str:
return os.path.join(os.getcwd(), "CHANGELOG.md")


@pytest.fixture()
def config_path() -> str:
return os.path.join(os.getcwd(), "pyproject.toml")
33 changes: 33 additions & 0 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,36 @@ def test_none_increment_should_not_call_git_tag(mocker, tmp_commitizen_project):

# restore pop stashed
git.tag = stashed_git_tag


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_bump_with_changelog_arg(mocker, changelog_path):
create_file_and_commit("feat(user): new file")
testargs = ["cz", "bump", "--yes", "--changelog"]
mocker.patch.object(sys, "argv", testargs)
cli.main()
tag_exists = git.tag_exist("0.2.0")
assert tag_exists is True

with open(changelog_path, "r") as f:
out = f.read()
assert out.startswith("#")
assert "0.2.0" in out


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_bump_with_changelog_config(mocker, changelog_path, config_path):
create_file_and_commit("feat(user): new file")
with open(config_path, "a") as fp:
fp.write("update_changelog_on_bump = true\n")

testargs = ["cz", "bump", "--yes"]
mocker.patch.object(sys, "argv", testargs)
cli.main()
tag_exists = git.tag_exist("0.2.0")
assert tag_exists is True

with open(changelog_path, "r") as f:
out = f.read()
assert out.startswith("#")
assert "0.2.0" in out
11 changes: 0 additions & 11 deletions tests/commands/test_changelog_command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import sys
from datetime import date

Expand All @@ -15,16 +14,6 @@
from tests.utils import create_file_and_commit


@pytest.fixture()
def changelog_path() -> str:
return os.path.join(os.getcwd(), "CHANGELOG.md")


@pytest.fixture()
def config_path() -> str:
return os.path.join(os.getcwd(), "pyproject.toml")


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_changelog_on_empty_project(mocker):
testargs = ["cz", "changelog", "--dry-run"]
Expand Down
2 changes: 2 additions & 0 deletions tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"changelog_file": "CHANGELOG.md",
"changelog_incremental": False,
"changelog_start_rev": None,
"update_changelog_on_bump": False,
}

_new_settings = {
Expand All @@ -46,6 +47,7 @@
"changelog_file": "CHANGELOG.md",
"changelog_incremental": False,
"changelog_start_rev": None,
"update_changelog_on_bump": False,
}

_read_settings = {
Expand Down

0 comments on commit 7a2bf96

Please sign in to comment.