Skip to content

Commit 1f185ab

Browse files
committed
refactor(tests/bump): use parameterize to group similliar tests
1 parent 3cbfc1a commit 1f185ab

File tree

1 file changed

+25
-49
lines changed

1 file changed

+25
-49
lines changed

‎tests/test_bump_find_increment.py

+25-49
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
CC: Conventional commits
33
SVE: Semantic version at the end
44
"""
5+
import pytest
6+
57
from commitizen import bump
68
from commitizen.git import GitCommit
79

@@ -44,58 +46,32 @@
4446
semantic_version_map = {"MAJOR": "MAJOR", "MINOR": "MINOR", "PATCH": "PATCH"}
4547

4648

47-
def test_find_increment_type_patch():
48-
messages = PATCH_INCREMENTS_CC
49-
commits = [GitCommit(rev="test", title=message) for message in messages]
50-
increment_type = bump.find_increment(commits)
51-
assert increment_type == "PATCH"
52-
53-
54-
def test_find_increment_type_minor():
55-
messages = MINOR_INCREMENTS_CC
49+
@pytest.mark.parametrize(
50+
"messages, expected_type",
51+
(
52+
(PATCH_INCREMENTS_CC, "PATCH"),
53+
(MINOR_INCREMENTS_CC, "MINOR"),
54+
(MAJOR_INCREMENTS_CC, "MAJOR"),
55+
(NONE_INCREMENT_CC, None),
56+
),
57+
)
58+
def test_find_increment(messages, expected_type):
5659
commits = [GitCommit(rev="test", title=message) for message in messages]
5760
increment_type = bump.find_increment(commits)
58-
assert increment_type == "MINOR"
59-
60-
61-
def test_find_increment_type_major():
62-
messages = MAJOR_INCREMENTS_CC
63-
commits = [GitCommit(rev="test", title=message) for message in messages]
64-
increment_type = bump.find_increment(commits)
65-
assert increment_type == "MAJOR"
66-
67-
68-
def test_find_increment_type_patch_sve():
69-
messages = PATCH_INCREMENTS_SVE
70-
commits = [GitCommit(rev="test", title=message) for message in messages]
71-
increment_type = bump.find_increment(
72-
commits, regex=semantic_version_pattern, increments_map=semantic_version_map
73-
)
74-
assert increment_type == "PATCH"
75-
76-
77-
def test_find_increment_type_minor_sve():
78-
messages = MINOR_INCREMENTS_SVE
79-
commits = [GitCommit(rev="test", title=message) for message in messages]
80-
increment_type = bump.find_increment(
81-
commits, regex=semantic_version_pattern, increments_map=semantic_version_map
82-
)
83-
assert increment_type == "MINOR"
84-
85-
86-
def test_find_increment_type_major_sve():
87-
messages = MAJOR_INCREMENTS_SVE
88-
commits = [GitCommit(rev="test", title=message) for message in messages]
89-
increment_type = bump.find_increment(
90-
commits, regex=semantic_version_pattern, increments_map=semantic_version_map
91-
)
92-
assert increment_type == "MAJOR"
93-
94-
95-
def test_find_increment_type_none():
96-
messages = NONE_INCREMENT_CC
61+
assert increment_type == expected_type
62+
63+
64+
@pytest.mark.parametrize(
65+
"messages, expected_type",
66+
(
67+
(PATCH_INCREMENTS_SVE, "PATCH"),
68+
(MINOR_INCREMENTS_SVE, "MINOR"),
69+
(MAJOR_INCREMENTS_SVE, "MAJOR"),
70+
),
71+
)
72+
def test_find_increment_sve(messages, expected_type):
9773
commits = [GitCommit(rev="test", title=message) for message in messages]
9874
increment_type = bump.find_increment(
9975
commits, regex=semantic_version_pattern, increments_map=semantic_version_map
10076
)
101-
assert increment_type is None
77+
assert increment_type == expected_type

0 commit comments

Comments
 (0)