From 17c7d3112b7e3d32e586cf6753176d2cb7ebdc3a Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Fri, 13 Mar 2020 17:54:19 +0800 Subject: [PATCH 1/4] fix(bump): fix bump find_increment error in the previous design, MAJOR will be overwritten by other --- commitizen/bump.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/commitizen/bump.py b/commitizen/bump.py index bfda1c4541..bd7b972cab 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -34,12 +34,12 @@ def find_increment( continue found_keyword = result.group(0) new_increment = increments_map_default[found_keyword] - if new_increment == "MAJOR": - increment = new_increment - break - elif increment == "MINOR" and new_increment == "PATCH": + if increment == "MAJOR": continue - increment = new_increment + elif increment == "MINOR" and new_increment == "MAJOR": + increment = new_increment + elif increment == "PATCH" or increment is None: + increment = new_increment return increment From 3cbfc1a0b5cc4c8f05f83dbbbfd4512cac4f8f0c Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Fri, 13 Mar 2020 18:05:14 +0800 Subject: [PATCH 2/4] test(config): add omit config for coverage --- pyproject.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index a62517c2f6..4c14188bc7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -89,6 +89,13 @@ git-cz = "commitizen.cli:main" 'if 0:', 'if __name__ == .__main__.:' ] + omit = [ + 'env/*', + 'venv/*', + '*/virtualenv/*', + '*/virtualenvs/*', + '*/tests/*' + ] [build-system] requires = ["poetry>=0.12"] From 1f185ab823ee67a523bc7fb17e3714e930f5929c Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Fri, 13 Mar 2020 18:05:54 +0800 Subject: [PATCH 3/4] refactor(tests/bump): use parameterize to group similliar tests --- tests/test_bump_find_increment.py | 74 +++++++++++-------------------- 1 file changed, 25 insertions(+), 49 deletions(-) diff --git a/tests/test_bump_find_increment.py b/tests/test_bump_find_increment.py index 405410712a..30e658c623 100644 --- a/tests/test_bump_find_increment.py +++ b/tests/test_bump_find_increment.py @@ -2,6 +2,8 @@ CC: Conventional commits SVE: Semantic version at the end """ +import pytest + from commitizen import bump from commitizen.git import GitCommit @@ -44,58 +46,32 @@ semantic_version_map = {"MAJOR": "MAJOR", "MINOR": "MINOR", "PATCH": "PATCH"} -def test_find_increment_type_patch(): - messages = PATCH_INCREMENTS_CC - commits = [GitCommit(rev="test", title=message) for message in messages] - increment_type = bump.find_increment(commits) - assert increment_type == "PATCH" - - -def test_find_increment_type_minor(): - messages = MINOR_INCREMENTS_CC +@pytest.mark.parametrize( + "messages, expected_type", + ( + (PATCH_INCREMENTS_CC, "PATCH"), + (MINOR_INCREMENTS_CC, "MINOR"), + (MAJOR_INCREMENTS_CC, "MAJOR"), + (NONE_INCREMENT_CC, None), + ), +) +def test_find_increment(messages, expected_type): commits = [GitCommit(rev="test", title=message) for message in messages] increment_type = bump.find_increment(commits) - assert increment_type == "MINOR" - - -def test_find_increment_type_major(): - messages = MAJOR_INCREMENTS_CC - commits = [GitCommit(rev="test", title=message) for message in messages] - increment_type = bump.find_increment(commits) - assert increment_type == "MAJOR" - - -def test_find_increment_type_patch_sve(): - messages = PATCH_INCREMENTS_SVE - commits = [GitCommit(rev="test", title=message) for message in messages] - increment_type = bump.find_increment( - commits, regex=semantic_version_pattern, increments_map=semantic_version_map - ) - assert increment_type == "PATCH" - - -def test_find_increment_type_minor_sve(): - messages = MINOR_INCREMENTS_SVE - commits = [GitCommit(rev="test", title=message) for message in messages] - increment_type = bump.find_increment( - commits, regex=semantic_version_pattern, increments_map=semantic_version_map - ) - assert increment_type == "MINOR" - - -def test_find_increment_type_major_sve(): - messages = MAJOR_INCREMENTS_SVE - commits = [GitCommit(rev="test", title=message) for message in messages] - increment_type = bump.find_increment( - commits, regex=semantic_version_pattern, increments_map=semantic_version_map - ) - assert increment_type == "MAJOR" - - -def test_find_increment_type_none(): - messages = NONE_INCREMENT_CC + assert increment_type == expected_type + + +@pytest.mark.parametrize( + "messages, expected_type", + ( + (PATCH_INCREMENTS_SVE, "PATCH"), + (MINOR_INCREMENTS_SVE, "MINOR"), + (MAJOR_INCREMENTS_SVE, "MAJOR"), + ), +) +def test_find_increment_sve(messages, expected_type): commits = [GitCommit(rev="test", title=message) for message in messages] increment_type = bump.find_increment( commits, regex=semantic_version_pattern, increments_map=semantic_version_map ) - assert increment_type is None + assert increment_type == expected_type From 6d89df3c9f35b05a1daa1fa65746873ed196d904 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Fri, 13 Mar 2020 18:11:04 +0800 Subject: [PATCH 4/4] test(bump_find_increment): reorder major commit for confirming that the order of commits does not matter --- tests/test_bump_find_increment.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_bump_find_increment.py b/tests/test_bump_find_increment.py index 30e658c623..5930be078f 100644 --- a/tests/test_bump_find_increment.py +++ b/tests/test_bump_find_increment.py @@ -10,8 +10,8 @@ NONE_INCREMENT_CC = ["docs(README): motivation", "ci: added travis"] PATCH_INCREMENTS_CC = [ - "docs(README): motivation", "fix(setup.py): future is now required for every python version", + "docs(README): motivation", ] MINOR_INCREMENTS_CC = [ @@ -23,8 +23,8 @@ MAJOR_INCREMENTS_CC = [ "feat(cli): added version", "docs(README): motivation", - "fix(setup.py): future is now required for every python version", "BREAKING CHANGE: `extends` key in config file is now used for extending other config files", # noqa + "fix(setup.py): future is now required for every python version", ] PATCH_INCREMENTS_SVE = ["readme motivation PATCH", "fix setup.py PATCH"]