From 7a2bf967c7ca93eea7737161e4f183620558d556 Mon Sep 17 00:00:00 2001 From: Jan Willhaus Date: Wed, 4 Nov 2020 14:13:10 +0100 Subject: [PATCH] test: provide tests for update_changelog_on_bump config option --- tests/commands/conftest.py | 12 +++++++++ tests/commands/test_bump_command.py | 33 ++++++++++++++++++++++++ tests/commands/test_changelog_command.py | 11 -------- tests/test_conf.py | 2 ++ 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/tests/commands/conftest.py b/tests/commands/conftest.py index cadf369f0..25bab0446 100644 --- a/tests/commands/conftest.py +++ b/tests/commands/conftest.py @@ -1,3 +1,5 @@ +import os + import pytest from commitizen import defaults @@ -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") diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index 73982a336..ce19c136b 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -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 diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index d52d157c7..aceaaf9d9 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -1,4 +1,3 @@ -import os import sys from datetime import date @@ -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"] diff --git a/tests/test_conf.py b/tests/test_conf.py index ba621bd63..919fb46e7 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -34,6 +34,7 @@ "changelog_file": "CHANGELOG.md", "changelog_incremental": False, "changelog_start_rev": None, + "update_changelog_on_bump": False, } _new_settings = { @@ -46,6 +47,7 @@ "changelog_file": "CHANGELOG.md", "changelog_incremental": False, "changelog_start_rev": None, + "update_changelog_on_bump": False, } _read_settings = {