-
-
Notifications
You must be signed in to change notification settings - Fork 256
/
test_version_scheme_pep440.py
133 lines (119 loc) · 4.72 KB
/
test_version_scheme_pep440.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import itertools
import pytest
from commitizen.version_schemes import Pep440, VersionProtocol
simple_flow = [
(("0.1.0", "PATCH", None, 0, None), "0.1.1"),
(("0.1.0", "PATCH", None, 0, 1), "0.1.1.dev1"),
(("0.1.1", "MINOR", None, 0, None), "0.2.0"),
(("0.2.0", "MINOR", None, 0, None), "0.3.0"),
(("0.2.0", "MINOR", None, 0, 1), "0.3.0.dev1"),
(("0.3.0", "PATCH", None, 0, None), "0.3.1"),
(("0.3.0", "PATCH", "alpha", 0, None), "0.3.1a0"),
(("0.3.1a0", None, "alpha", 0, None), "0.3.1a1"),
(("0.3.0", "PATCH", "alpha", 1, None), "0.3.1a1"),
(("0.3.1a0", None, "alpha", 1, None), "0.3.1a1"),
(("0.3.1a0", None, None, 0, None), "0.3.1"),
(("0.3.1", "PATCH", None, 0, None), "0.3.2"),
(("0.4.2", "MAJOR", "alpha", 0, None), "1.0.0a0"),
(("1.0.0a0", None, "alpha", 0, None), "1.0.0a1"),
(("1.0.0a1", None, "alpha", 0, None), "1.0.0a2"),
(("1.0.0a1", None, "alpha", 0, 1), "1.0.0a2.dev1"),
(("1.0.0a2.dev0", None, "alpha", 0, 1), "1.0.0a3.dev1"),
(("1.0.0a2.dev0", None, "alpha", 0, 0), "1.0.0a3.dev0"),
(("1.0.0a1", None, "beta", 0, None), "1.0.0b0"),
(("1.0.0b0", None, "beta", 0, None), "1.0.0b1"),
(("1.0.0b1", None, "rc", 0, None), "1.0.0rc0"),
(("1.0.0rc0", None, "rc", 0, None), "1.0.0rc1"),
(("1.0.0rc0", None, "rc", 0, 1), "1.0.0rc1.dev1"),
(("1.0.0rc0", "PATCH", None, 0, None), "1.0.0"),
(("1.0.0a3.dev0", None, "beta", 0, None), "1.0.0b0"),
(("1.0.0", "PATCH", None, 0, None), "1.0.1"),
(("1.0.1", "PATCH", None, 0, None), "1.0.2"),
(("1.0.2", "MINOR", None, 0, None), "1.1.0"),
(("1.1.0", "MINOR", None, 0, None), "1.2.0"),
(("1.2.0", "PATCH", None, 0, None), "1.2.1"),
(("1.2.1", "MAJOR", None, 0, None), "2.0.0"),
]
local_versions = [
(("4.5.0+0.1.0", "PATCH", None, 0, None), "4.5.0+0.1.1"),
(("4.5.0+0.1.1", "MINOR", None, 0, None), "4.5.0+0.2.0"),
(("4.5.0+0.2.0", "MAJOR", None, 0, None), "4.5.0+1.0.0"),
]
# this cases should be handled gracefully
unexpected_cases = [
(("0.1.1rc0", None, "alpha", 0, None), "0.1.1a0"),
(("0.1.1b1", None, "alpha", 0, None), "0.1.1a0"),
]
weird_cases = [
(("1.1", "PATCH", None, 0, None), "1.1.1"),
(("1", "MINOR", None, 0, None), "1.1.0"),
(("1", "MAJOR", None, 0, None), "2.0.0"),
(("1a0", None, "alpha", 0, None), "1.0.0a1"),
(("1a0", None, "alpha", 1, None), "1.0.0a1"),
(("1", None, "beta", 0, None), "1.0.0b0"),
(("1", None, "beta", 1, None), "1.0.0b1"),
(("1beta", None, "beta", 0, None), "1.0.0b1"),
(("1.0.0alpha1", None, "alpha", 0, None), "1.0.0a2"),
(("1", None, "rc", 0, None), "1.0.0rc0"),
(("1.0.0rc1+e20d7b57f3eb", "PATCH", None, 0, None), "1.0.0"),
]
# test driven development
tdd_cases = [
(("0.1.1", "PATCH", None, 0, None), "0.1.2"),
(("0.1.1", "MINOR", None, 0, None), "0.2.0"),
(("2.1.1", "MAJOR", None, 0, None), "3.0.0"),
(("0.9.0", "PATCH", "alpha", 0, None), "0.9.1a0"),
(("0.9.0", "MINOR", "alpha", 0, None), "0.10.0a0"),
(("0.9.0", "MAJOR", "alpha", 0, None), "1.0.0a0"),
(("0.9.0", "MAJOR", "alpha", 1, None), "1.0.0a1"),
(("1.0.0a2", None, "beta", 0, None), "1.0.0b0"),
(("1.0.0a2", None, "beta", 1, None), "1.0.0b1"),
(("1.0.0beta1", None, "rc", 0, None), "1.0.0rc0"),
(("1.0.0rc1", None, "rc", 0, None), "1.0.0rc2"),
]
@pytest.mark.parametrize(
"test_input,expected",
itertools.chain(tdd_cases, weird_cases, simple_flow, unexpected_cases),
)
def test_bump_pep440_version(test_input, expected):
current_version = test_input[0]
increment = test_input[1]
prerelease = test_input[2]
prerelease_offset = test_input[3]
devrelease = test_input[4]
assert (
str(
Pep440(current_version).bump(
increment=increment,
prerelease=prerelease,
prerelease_offset=prerelease_offset,
devrelease=devrelease,
)
)
== expected
)
@pytest.mark.parametrize("test_input,expected", local_versions)
def test_bump_pep440_version_local(test_input, expected):
current_version = test_input[0]
increment = test_input[1]
prerelease = test_input[2]
prerelease_offset = test_input[3]
devrelease = test_input[4]
is_local_version = True
assert (
str(
Pep440(current_version).bump(
increment=increment,
prerelease=prerelease,
prerelease_offset=prerelease_offset,
devrelease=devrelease,
is_local_version=is_local_version,
)
)
== expected
)
def test_pep440_scheme_property():
version = Pep440("0.0.1")
assert version.scheme is Pep440
def test_pep440_implement_version_protocol():
assert isinstance(Pep440("0.0.1"), VersionProtocol)