Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4d8f987

Browse files
test(SemVer): refine tests and remove unnecessary tests which test the behavior of library
1 parent cc981fc commit 4d8f987

File tree

2 files changed

+207
-380
lines changed

2 files changed

+207
-380
lines changed

‎tests/test_version_scheme_semver.py‎

Lines changed: 125 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,81 @@
1-
import itertools
2-
import random
1+
from __future__ import annotations
32

43
import pytest
54

6-
from commitizen.version_schemes import SemVer, VersionProtocol
7-
8-
simple_flow = [
9-
(("0.1.0", "PATCH", None, 0, None), "0.1.1"),
10-
(("0.1.0", "PATCH", None, 0, 1), "0.1.1-dev1"),
11-
(("0.1.1", "MINOR", None, 0, None), "0.2.0"),
12-
(("0.2.0", "MINOR", None, 0, None), "0.3.0"),
13-
(("0.2.0", "MINOR", None, 0, 1), "0.3.0-dev1"),
14-
(("0.3.0", "PATCH", None, 0, None), "0.3.1"),
15-
(("0.3.0", "PATCH", "alpha", 0, None), "0.3.1-a0"),
16-
(("0.3.1a0", None, "alpha", 0, None), "0.3.1-a1"),
17-
(("0.3.0", "PATCH", "alpha", 1, None), "0.3.1-a1"),
18-
(("0.3.1a0", None, "alpha", 1, None), "0.3.1-a1"),
19-
(("0.3.1a0", None, None, 0, None), "0.3.1"),
20-
(("0.3.1", "PATCH", None, 0, None), "0.3.2"),
21-
(("0.4.2", "MAJOR", "alpha", 0, None), "1.0.0-a0"),
22-
(("1.0.0a0", None, "alpha", 0, None), "1.0.0-a1"),
23-
(("1.0.0a1", None, "alpha", 0, None), "1.0.0-a2"),
24-
(("1.0.0a1", None, "alpha", 0, 1), "1.0.0-a2-dev1"),
25-
(("1.0.0a2.dev0", None, "alpha", 0, 1), "1.0.0-a3-dev1"),
26-
(("1.0.0a2.dev0", None, "alpha", 0, 0), "1.0.0-a3-dev0"),
27-
(("1.0.0a1", None, "beta", 0, None), "1.0.0-b0"),
28-
(("1.0.0b0", None, "beta", 0, None), "1.0.0-b1"),
29-
(("1.0.0b1", None, "rc", 0, None), "1.0.0-rc0"),
30-
(("1.0.0rc0", None, "rc", 0, None), "1.0.0-rc1"),
31-
(("1.0.0rc0", None, "rc", 0, 1), "1.0.0-rc1-dev1"),
32-
(("1.0.0rc0", "PATCH", None, 0, None), "1.0.0"),
33-
(("1.0.0a3.dev0", None, "beta", 0, None), "1.0.0-b0"),
34-
(("1.0.0", "PATCH", None, 0, None), "1.0.1"),
35-
(("1.0.1", "PATCH", None, 0, None), "1.0.2"),
36-
(("1.0.2", "MINOR", None, 0, None), "1.1.0"),
37-
(("1.1.0", "MINOR", None, 0, None), "1.2.0"),
38-
(("1.2.0", "PATCH", None, 0, None), "1.2.1"),
39-
(("1.2.1", "MAJOR", None, 0, None), "2.0.0"),
40-
]
41-
42-
local_versions = [
43-
(("4.5.0+0.1.0", "PATCH", None, 0, None), "4.5.0+0.1.1"),
44-
(("4.5.0+0.1.1", "MINOR", None, 0, None), "4.5.0+0.2.0"),
45-
(("4.5.0+0.2.0", "MAJOR", None, 0, None), "4.5.0+1.0.0"),
46-
]
47-
48-
# never bump backwards on pre-releases
49-
linear_prerelease_cases = [
50-
(("0.1.1b1", None, "alpha", 0, None), "0.1.1-b2"),
51-
(("0.1.1rc0", None, "alpha", 0, None), "0.1.1-rc1"),
52-
(("0.1.1rc0", None, "beta", 0, None), "0.1.1-rc1"),
53-
]
54-
55-
weird_cases = [
56-
(("1.1", "PATCH", None, 0, None), "1.1.1"),
57-
(("1", "MINOR", None, 0, None), "1.1.0"),
58-
(("1", "MAJOR", None, 0, None), "2.0.0"),
59-
(("1a0", None, "alpha", 0, None), "1.0.0-a1"),
60-
(("1a0", None, "alpha", 1, None), "1.0.0-a1"),
61-
(("1", None, "beta", 0, None), "1.0.0-b0"),
62-
(("1", None, "beta", 1, None), "1.0.0-b1"),
63-
(("1beta", None, "beta", 0, None), "1.0.0-b1"),
64-
(("1.0.0alpha1", None, "alpha", 0, None), "1.0.0-a2"),
65-
(("1", None, "rc", 0, None), "1.0.0-rc0"),
66-
(("1.0.0rc1+e20d7b57f3eb", "PATCH", None, 0, None), "1.0.0"),
67-
]
68-
69-
# test driven development
70-
tdd_cases = [
71-
(("0.1.1", "PATCH", None, 0, None), "0.1.2"),
72-
(("0.1.1", "MINOR", None, 0, None), "0.2.0"),
73-
(("2.1.1", "MAJOR", None, 0, None), "3.0.0"),
74-
(("0.9.0", "PATCH", "alpha", 0, None), "0.9.1-a0"),
75-
(("0.9.0", "MINOR", "alpha", 0, None), "0.10.0-a0"),
76-
(("0.9.0", "MAJOR", "alpha", 0, None), "1.0.0-a0"),
77-
(("0.9.0", "MAJOR", "alpha", 1, None), "1.0.0-a1"),
78-
(("1.0.0a2", None, "beta", 0, None), "1.0.0-b0"),
79-
(("1.0.0a2", None, "beta", 1, None), "1.0.0-b1"),
80-
(("1.0.0beta1", None, "rc", 0, None), "1.0.0-rc0"),
81-
(("1.0.0rc1", None, "rc", 0, None), "1.0.0-rc2"),
82-
(("1.0.0-a0", None, "rc", 0, None), "1.0.0-rc0"),
83-
(("1.0.0-alpha1", None, "alpha", 0, None), "1.0.0-a2"),
84-
]
85-
86-
exact_cases = [
87-
(("1.0.0", "PATCH", None, 0, None), "1.0.1"),
88-
(("1.0.0", "MINOR", None, 0, None), "1.1.0"),
89-
# with exact_increment=False: "1.0.0-b0"
90-
(("1.0.0a1", "PATCH", "beta", 0, None), "1.0.1-b0"),
91-
# with exact_increment=False: "1.0.0-b1"
92-
(("1.0.0b0", "PATCH", "beta", 0, None), "1.0.1-b0"),
93-
# with exact_increment=False: "1.0.0-rc0"
94-
(("1.0.0b1", "PATCH", "rc", 0, None), "1.0.1-rc0"),
95-
# with exact_increment=False: "1.0.0-rc1"
96-
(("1.0.0rc0", "PATCH", "rc", 0, None), "1.0.1-rc0"),
97-
# with exact_increment=False: "1.0.0-rc1-dev1"
98-
(("1.0.0rc0", "PATCH", "rc", 0, 1), "1.0.1-rc0-dev1"),
99-
# with exact_increment=False: "1.0.0-b0"
100-
(("1.0.0a1", "MINOR", "beta", 0, None), "1.1.0-b0"),
101-
# with exact_increment=False: "1.0.0-b1"
102-
(("1.0.0b0", "MINOR", "beta", 0, None), "1.1.0-b0"),
103-
# with exact_increment=False: "1.0.0-rc0"
104-
(("1.0.0b1", "MINOR", "rc", 0, None), "1.1.0-rc0"),
105-
# with exact_increment=False: "1.0.0-rc1"
106-
(("1.0.0rc0", "MINOR", "rc", 0, None), "1.1.0-rc0"),
107-
# with exact_increment=False: "1.0.0-rc1-dev1"
108-
(("1.0.0rc0", "MINOR", "rc", 0, 1), "1.1.0-rc0-dev1"),
109-
# with exact_increment=False: "2.0.0"
110-
(("2.0.0b0", "MAJOR", None, 0, None), "3.0.0"),
111-
# with exact_increment=False: "2.0.0"
112-
(("2.0.0b0", "MINOR", None, 0, None), "2.1.0"),
113-
# with exact_increment=False: "2.0.0"
114-
(("2.0.0b0", "PATCH", None, 0, None), "2.0.1"),
115-
# same with exact_increment=False
116-
(("2.0.0b0", "MAJOR", "alpha", 0, None), "3.0.0-a0"),
117-
# with exact_increment=False: "2.0.0b1"
118-
(("2.0.0b0", "MINOR", "alpha", 0, None), "2.1.0-a0"),
119-
# with exact_increment=False: "2.0.0b1"
120-
(("2.0.0b0", "PATCH", "alpha", 0, None), "2.0.1-a0"),
121-
]
5+
from commitizen.version_schemes import Increment, Prerelease, SemVer, VersionProtocol
1226

1237

1248
@pytest.mark.parametrize(
1259
"test_input, expected",
126-
itertools.chain(tdd_cases, weird_cases, simple_flow, linear_prerelease_cases),
10+
[
11+
# tdd_cases
12+
(("0.1.1", "PATCH", None, 0, None), "0.1.2"),
13+
(("0.1.1", "MINOR", None, 0, None), "0.2.0"),
14+
(("2.1.1", "MAJOR", None, 0, None), "3.0.0"),
15+
(("0.9.0", "PATCH", "alpha", 0, None), "0.9.1-a0"),
16+
(("0.9.0", "MINOR", "alpha", 0, None), "0.10.0-a0"),
17+
(("0.9.0", "MAJOR", "alpha", 0, None), "1.0.0-a0"),
18+
(("0.9.0", "MAJOR", "alpha", 1, None), "1.0.0-a1"),
19+
(("1.0.0a2", None, "beta", 0, None), "1.0.0-b0"),
20+
(("1.0.0a2", None, "beta", 1, None), "1.0.0-b1"),
21+
(("1.0.0beta1", None, "rc", 0, None), "1.0.0-rc0"),
22+
(("1.0.0rc1", None, "rc", 0, None), "1.0.0-rc2"),
23+
(("1.0.0-a0", None, "rc", 0, None), "1.0.0-rc0"),
24+
(("1.0.0-alpha1", None, "alpha", 0, None), "1.0.0-a2"),
25+
# weird_cases
26+
(("1.1", "PATCH", None, 0, None), "1.1.1"),
27+
(("1", "MINOR", None, 0, None), "1.1.0"),
28+
(("1", "MAJOR", None, 0, None), "2.0.0"),
29+
(("1a0", None, "alpha", 0, None), "1.0.0-a1"),
30+
(("1a0", None, "alpha", 1, None), "1.0.0-a1"),
31+
(("1", None, "beta", 0, None), "1.0.0-b0"),
32+
(("1", None, "beta", 1, None), "1.0.0-b1"),
33+
(("1beta", None, "beta", 0, None), "1.0.0-b1"),
34+
(("1.0.0alpha1", None, "alpha", 0, None), "1.0.0-a2"),
35+
(("1", None, "rc", 0, None), "1.0.0-rc0"),
36+
(("1.0.0rc1+e20d7b57f3eb", "PATCH", None, 0, None), "1.0.0"),
37+
# simple_flow
38+
(("0.1.0", "PATCH", None, 0, None), "0.1.1"),
39+
(("0.1.0", "PATCH", None, 0, 1), "0.1.1-dev1"),
40+
(("0.1.1", "MINOR", None, 0, None), "0.2.0"),
41+
(("0.2.0", "MINOR", None, 0, None), "0.3.0"),
42+
(("0.2.0", "MINOR", None, 0, 1), "0.3.0-dev1"),
43+
(("0.3.0", "PATCH", None, 0, None), "0.3.1"),
44+
(("0.3.0", "PATCH", "alpha", 0, None), "0.3.1-a0"),
45+
(("0.3.1a0", None, "alpha", 0, None), "0.3.1-a1"),
46+
(("0.3.0", "PATCH", "alpha", 1, None), "0.3.1-a1"),
47+
(("0.3.1a0", None, "alpha", 1, None), "0.3.1-a1"),
48+
(("0.3.1a0", None, None, 0, None), "0.3.1"),
49+
(("0.3.1", "PATCH", None, 0, None), "0.3.2"),
50+
(("0.4.2", "MAJOR", "alpha", 0, None), "1.0.0-a0"),
51+
(("1.0.0a0", None, "alpha", 0, None), "1.0.0-a1"),
52+
(("1.0.0a1", None, "alpha", 0, None), "1.0.0-a2"),
53+
(("1.0.0a1", None, "alpha", 0, 1), "1.0.0-a2-dev1"),
54+
(("1.0.0a2.dev0", None, "alpha", 0, 1), "1.0.0-a3-dev1"),
55+
(("1.0.0a2.dev0", None, "alpha", 0, 0), "1.0.0-a3-dev0"),
56+
(("1.0.0a1", None, "beta", 0, None), "1.0.0-b0"),
57+
(("1.0.0b0", None, "beta", 0, None), "1.0.0-b1"),
58+
(("1.0.0b1", None, "rc", 0, None), "1.0.0-rc0"),
59+
(("1.0.0rc0", None, "rc", 0, None), "1.0.0-rc1"),
60+
(("1.0.0rc0", None, "rc", 0, 1), "1.0.0-rc1-dev1"),
61+
(("1.0.0rc0", "PATCH", None, 0, None), "1.0.0"),
62+
(("1.0.0a3.dev0", None, "beta", 0, None), "1.0.0-b0"),
63+
(("1.0.0", "PATCH", None, 0, None), "1.0.1"),
64+
(("1.0.1", "PATCH", None, 0, None), "1.0.2"),
65+
(("1.0.2", "MINOR", None, 0, None), "1.1.0"),
66+
(("1.1.0", "MINOR", None, 0, None), "1.2.0"),
67+
(("1.2.0", "PATCH", None, 0, None), "1.2.1"),
68+
(("1.2.1", "MAJOR", None, 0, None), "2.0.0"),
69+
# linear_prerelease_cases
70+
(("0.1.1b1", None, "alpha", 0, None), "0.1.1-b2"),
71+
(("0.1.1rc0", None, "alpha", 0, None), "0.1.1-rc1"),
72+
(("0.1.1rc0", None, "beta", 0, None), "0.1.1-rc1"),
73+
],
12774
)
128-
def test_bump_semver_version(test_input, expected):
129-
current_version = test_input[0]
130-
increment = test_input[1]
131-
prerelease = test_input[2]
132-
prerelease_offset = test_input[3]
133-
devrelease = test_input[4]
75+
def test_bump_semver_version(
76+
test_input: tuple[str, Increment, Prerelease | None, int, int | None], expected: str
77+
):
78+
current_version, increment, prerelease, prerelease_offset, devrelease = test_input
13479
assert (
13580
str(
13681
SemVer(current_version).bump(
@@ -144,13 +89,49 @@ def test_bump_semver_version(test_input, expected):
14489
)
14590

14691

147-
@pytest.mark.parametrize("test_input, expected", exact_cases)
148-
def test_bump_semver_version_force(test_input, expected):
149-
current_version = test_input[0]
150-
increment = test_input[1]
151-
prerelease = test_input[2]
152-
prerelease_offset = test_input[3]
153-
devrelease = test_input[4]
92+
@pytest.mark.parametrize(
93+
"test_input, expected",
94+
[
95+
(("1.0.0", "PATCH", None, 0, None), "1.0.1"),
96+
(("1.0.0", "MINOR", None, 0, None), "1.1.0"),
97+
# with exact_increment=False: "1.0.0-b0"
98+
(("1.0.0a1", "PATCH", "beta", 0, None), "1.0.1-b0"),
99+
# with exact_increment=False: "1.0.0-b1"
100+
(("1.0.0b0", "PATCH", "beta", 0, None), "1.0.1-b0"),
101+
# with exact_increment=False: "1.0.0-rc0"
102+
(("1.0.0b1", "PATCH", "rc", 0, None), "1.0.1-rc0"),
103+
# with exact_increment=False: "1.0.0-rc1"
104+
(("1.0.0rc0", "PATCH", "rc", 0, None), "1.0.1-rc0"),
105+
# with exact_increment=False: "1.0.0-rc1-dev1"
106+
(("1.0.0rc0", "PATCH", "rc", 0, 1), "1.0.1-rc0-dev1"),
107+
# with exact_increment=False: "1.0.0-b0"
108+
(("1.0.0a1", "MINOR", "beta", 0, None), "1.1.0-b0"),
109+
# with exact_increment=False: "1.0.0-b1"
110+
(("1.0.0b0", "MINOR", "beta", 0, None), "1.1.0-b0"),
111+
# with exact_increment=False: "1.0.0-rc0"
112+
(("1.0.0b1", "MINOR", "rc", 0, None), "1.1.0-rc0"),
113+
# with exact_increment=False: "1.0.0-rc1"
114+
(("1.0.0rc0", "MINOR", "rc", 0, None), "1.1.0-rc0"),
115+
# with exact_increment=False: "1.0.0-rc1-dev1"
116+
(("1.0.0rc0", "MINOR", "rc", 0, 1), "1.1.0-rc0-dev1"),
117+
# with exact_increment=False: "2.0.0"
118+
(("2.0.0b0", "MAJOR", None, 0, None), "3.0.0"),
119+
# with exact_increment=False: "2.0.0"
120+
(("2.0.0b0", "MINOR", None, 0, None), "2.1.0"),
121+
# with exact_increment=False: "2.0.0"
122+
(("2.0.0b0", "PATCH", None, 0, None), "2.0.1"),
123+
# same with exact_increment=False
124+
(("2.0.0b0", "MAJOR", "alpha", 0, None), "3.0.0-a0"),
125+
# with exact_increment=False: "2.0.0b1"
126+
(("2.0.0b0", "MINOR", "alpha", 0, None), "2.1.0-a0"),
127+
# with exact_increment=False: "2.0.0b1"
128+
(("2.0.0b0", "PATCH", "alpha", 0, None), "2.0.1-a0"),
129+
],
130+
)
131+
def test_bump_semver_version_force(
132+
test_input: tuple[str, Increment, Prerelease | None, int, int | None], expected: str
133+
):
134+
current_version, increment, prerelease, prerelease_offset, devrelease = test_input
154135
assert (
155136
str(
156137
SemVer(current_version).bump(
@@ -165,13 +146,18 @@ def test_bump_semver_version_force(test_input, expected):
165146
)
166147

167148

168-
@pytest.mark.parametrize("test_input,expected", local_versions)
169-
def test_bump_semver_version_local(test_input, expected):
170-
current_version = test_input[0]
171-
increment = test_input[1]
172-
prerelease = test_input[2]
173-
prerelease_offset = test_input[3]
174-
devrelease = test_input[4]
149+
@pytest.mark.parametrize(
150+
"test_input, expected",
151+
[
152+
(("4.5.0+0.1.0", "PATCH", None, 0, None), "4.5.0+0.1.1"),
153+
(("4.5.0+0.1.1", "MINOR", None, 0, None), "4.5.0+0.2.0"),
154+
(("4.5.0+0.2.0", "MAJOR", None, 0, None), "4.5.0+1.0.0"),
155+
],
156+
)
157+
def test_bump_semver_version_local(
158+
test_input: tuple[str, Increment, Prerelease | None, int, int | None], expected: str
159+
):
160+
current_version, increment, prerelease, prerelease_offset, devrelease = test_input
175161
is_local_version = True
176162
assert (
177163
str(
@@ -194,76 +180,3 @@ def test_semver_scheme_property():
194180

195181
def test_semver_implement_version_protocol():
196182
assert isinstance(SemVer("0.0.1"), VersionProtocol)
197-
198-
199-
def test_semver_sortable():
200-
test_input = [x[0][0] for x in simple_flow]
201-
test_input.extend([x[1] for x in simple_flow])
202-
# randomize
203-
random_input = [SemVer(x) for x in random.sample(test_input, len(test_input))]
204-
assert len(random_input) == len(test_input)
205-
sorted_result = [str(x) for x in sorted(random_input)]
206-
assert sorted_result == [
207-
"0.1.0",
208-
"0.1.0",
209-
"0.1.1-dev1",
210-
"0.1.1",
211-
"0.1.1",
212-
"0.2.0",
213-
"0.2.0",
214-
"0.2.0",
215-
"0.3.0-dev1",
216-
"0.3.0",
217-
"0.3.0",
218-
"0.3.0",
219-
"0.3.0",
220-
"0.3.1-a0",
221-
"0.3.1-a0",
222-
"0.3.1-a0",
223-
"0.3.1-a0",
224-
"0.3.1-a1",
225-
"0.3.1-a1",
226-
"0.3.1-a1",
227-
"0.3.1",
228-
"0.3.1",
229-
"0.3.1",
230-
"0.3.2",
231-
"0.4.2",
232-
"1.0.0-a0",
233-
"1.0.0-a0",
234-
"1.0.0-a1",
235-
"1.0.0-a1",
236-
"1.0.0-a1",
237-
"1.0.0-a1",
238-
"1.0.0-a2-dev0",
239-
"1.0.0-a2-dev0",
240-
"1.0.0-a2-dev1",
241-
"1.0.0-a2",
242-
"1.0.0-a3-dev0",
243-
"1.0.0-a3-dev0",
244-
"1.0.0-a3-dev1",
245-
"1.0.0-b0",
246-
"1.0.0-b0",
247-
"1.0.0-b0",
248-
"1.0.0-b1",
249-
"1.0.0-b1",
250-
"1.0.0-rc0",
251-
"1.0.0-rc0",
252-
"1.0.0-rc0",
253-
"1.0.0-rc0",
254-
"1.0.0-rc1-dev1",
255-
"1.0.0-rc1",
256-
"1.0.0",
257-
"1.0.0",
258-
"1.0.1",
259-
"1.0.1",
260-
"1.0.2",
261-
"1.0.2",
262-
"1.1.0",
263-
"1.1.0",
264-
"1.2.0",
265-
"1.2.0",
266-
"1.2.1",
267-
"1.2.1",
268-
"2.0.0",
269-
]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /