From 4d08aea1210231b969b15c272c0a07b7cb7e99c7 Mon Sep 17 00:00:00 2001 From: Manuel Barkhau Date: Fri, 2 Oct 2020 21:32:51 +0000 Subject: [PATCH] test commit_message config --- pylint-ignore.md | 16 +------------ test/test_cli.py | 61 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 19 deletions(-) diff --git a/pylint-ignore.md b/pylint-ignore.md index 9bbd051..5143e55 100644 --- a/pylint-ignore.md +++ b/pylint-ignore.md @@ -23,7 +23,7 @@ The recommended approach to using `pylint-ignore` is: # Overview - - [W0511: fixme (8x)](#w0511-fixme) + - [W0511: fixme (7x)](#w0511-fixme) - [W0703: broad-except (1x)](#w0703-broad-except) @@ -129,20 +129,6 @@ The recommended approach to using `pylint-ignore` is: ``` -## File test/test_cli.py - Line 599 - W0511 (fixme) - -- `message: # TODO (mb 2020-09-18):` -- `author : Manuel Barkhau ` -- `date : 2020-09-18T19:35:32` - -``` - 597: - 598: # def test_custom_commit_message(runner): -> 599: # # TODO (mb 2020-09-18): - 600: # assert False -``` - - ## File src/pycalver/v2version.py - Line 616 - W0511 (fixme) - `message: TODO (mb 2020-09-20): New Rollover Behaviour:` diff --git a/test/test_cli.py b/test/test_cli.py index 75a83d6..c1105f8 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -8,6 +8,7 @@ import io import os import re import time +import shlex import shutil import subprocess as sp @@ -209,7 +210,7 @@ def _update_config_val(filename, **kwargs): new_cfg_text = old_cfg_text for key, val in kwargs.items(): - replacement = "{} = {}\n".format(key, val) + replacement = "{} = {}".format(key, val) if replacement not in new_cfg_text: pattern = r"^{} = .*$".format(key) new_cfg_text = re.sub(pattern, replacement, new_cfg_text, flags=re.MULTILINE) @@ -597,6 +598,58 @@ def test_v2_get_diff(runner): assert '+current_version = "v202010.1003-beta"' in diff_lines -# def test_custom_commit_message(runner): -# # TODO (mb 2020-09-18): -# assert False +def test_hg_commit_message(runner, caplog): + _add_project_files("README.md", "setup.cfg") + result = runner.invoke(cli, ['init', "-vv"]) + assert result.exit_code == 0 + + commit_message = """ + "bump from {old_version} ({old_version_pep440}) to {new_version} ({new_version_pep440})" + """ + _update_config_val("setup.cfg", current_version='"v201903.1001-alpha"') + _update_config_val("setup.cfg", commit_message=commit_message.strip()) + + _vcs_init("hg", ["README.md", "setup.cfg"]) + assert len(caplog.records) > 0 + + result = runner.invoke(cli, ['bump', "-vv", "--pin-date", "--release", "beta"]) + assert result.exit_code == 0 + + tags = shell("hg", "tags").decode("utf-8") + assert "v201903.1002-beta" in tags + + commits = shell(*shlex.split("hg log -l 2")).decode("utf-8").split("\n\n") + + summary = commits[1].split("summary:")[-1] + assert ( + "bump from v201903.1001-alpha (201903.1001a0) to v201903.1002-beta (201903.1002b0)" + in summary + ) + + +def test_git_commit_message(runner, caplog): + _add_project_files("README.md", "setup.cfg") + result = runner.invoke(cli, ['init', "-vv"]) + assert result.exit_code == 0 + + commit_message = """ + "bump: {old_version} ({old_version_pep440}) -> {new_version} ({new_version_pep440})" + """ + _update_config_val("setup.cfg", current_version='"v201903.1001-alpha"') + _update_config_val("setup.cfg", commit_message=commit_message.strip()) + + _vcs_init("git", ["README.md", "setup.cfg"]) + assert len(caplog.records) > 0 + + result = runner.invoke(cli, ['bump', "-vv", "--pin-date", "--release", "beta"]) + assert result.exit_code == 0 + + tags = shell("git", "tag", "--list").decode("utf-8") + assert "v201903.1002-beta" in tags + + commits = shell(*shlex.split("git log -l 2")).decode("utf-8").split("\n\n") + + summary = commits[1] + assert ( + "bump: v201903.1001-alpha (201903.1001a0) -> v201903.1002-beta (201903.1002b0)" in summary + )