-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_version.py
359 lines (305 loc) · 13.2 KB
/
test_version.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# pylint: disable=C0111
# Missing docstring
from nose import tools
from version import Version
from script_exception import ScriptException
class Base(object):
def __init__(self):
pass
@staticmethod
def assert_raises(error_type,
error_message,
function_to_call,
*args,
**kwargs
):
with tools.assert_raises(error_type) as context_mgr: # pylint: disable=E1101
ignore_result = function_to_call(*args, **kwargs)
exception = context_mgr.exception
tools.assert_equal(exception.message, # pylint: disable=E1101
error_message,
)
class TestVersion(Base):
def __init__(self):
Base.__init__(self)
@staticmethod
def version_string_identity(version_string):
version = Version(version_string)
tools.assert_equal(version_string, # pylint: disable=E1101
version.build_version_string(),
)
@staticmethod
def version_identity(version_string):
v1 = Version(version_string)
v2 = Version(version_string)
tools.assert_equal(v1, # pylint: disable=E1101
v2,
)
def test_build_version_string1(self):
self.version_string_identity('1.2.3a4')
def test_build_version_string2(self):
self.version_string_identity('10.2.3')
def test_build_version_string3(self):
self.version_string_identity('0.20.0b0')
def test_build_version_string4(self):
self.version_string_identity('7.2.180')
def test_identity1(self):
self.version_identity('3.4.55')
def test_identity2(self):
self.version_identity('0.2.0')
def test_identity3(self):
self.version_identity('6.41.1c3')
def test_identity4(self):
self.version_identity('7.0.0a1')
def test_identity5(self):
self.version_identity('7.0.0a0')
def test_parse_validation1(self):
self.assert_raises(ScriptException,
'Error in parsing version string 00.4.55. Result 0.4.55.',
self.version_identity,
'00.4.55',
)
def test_parse_validation2(self):
self.assert_raises(ScriptException,
"Invalid version string '18.10.20X32' Result: '18.10.20'",
self.version_identity,
'18.10.20X32',
)
def test_parse_validation3(self):
self.assert_raises(ScriptException,
'Error in parsing version string 10.0.00. Result 10.0.0.',
self.version_identity,
'10.0.00',
)
def test_parse_validation4(self):
self.assert_raises(ScriptException,
'Error in parsing version string 6.41.01. Result 6.41.1.',
self.version_identity,
'6.41.01',
)
def test_parse_validation5(self):
self.assert_raises(ScriptException,
"Invalid version string 0.2",
self.version_identity,
'0.2',
)
def test_parse_validation6(self):
self.assert_raises(ScriptException,
'Error in parsing version string 6.41.01a5. Result 6.41.1a5.',
self.version_identity,
'6.41.01a5',
)
def test_parse_validation7(self):
self.assert_raises(ScriptException,
"Invalid version string 0.2b2",
self.version_identity,
'0.2b2',
)
def test_parse_validation8(self):
self.assert_raises(ScriptException,
"Invalid version string '6.41.01A5' Result: '6.41.01'",
self.version_identity,
'6.41.01A5',
)
def test_parse_validation9(self):
self.assert_raises(ScriptException,
"Invalid version string 0.2B12",
self.version_identity,
'0.2B12',
)
class TestVersionIncrement(Base):
ERROR_MESSAGES = {
'ERR1' : "Must specify an increment type (major, minor, micro) when incrementing a non-development build to a development build.",
'ERR2' : "Can not specify a development version of a normal release.",
'ERR3' : "Can't go from beta to alpha of the same version. Specify an increment type (major, minor, micro).",
'ERR4' : "Can't go from release candidate to alpha of the same version. Specify an increment type (major, minor, micro).",
'ERR5' : "Can't go from release candidate to beta of the same version. Specify an increment type (major, minor, micro).",
}
def __init__(self):
Base.__init__(self)
@staticmethod
def try_increment(version_object,
increment_type,
release_type,
expected_incremented_version_string,
):
incremented_object = version_object.increment_and_return_new(increment_type,
release_type,
)
version_object.increment_in_place(increment_type,
release_type,
)
tools.assert_equal(version_object, incremented_object) # pylint: disable=E1101
version_object_string = str(version_object)
incremented_object_string = str(incremented_object)
tools.assert_equal(version_object_string, expected_incremented_version_string) # pylint: disable=E1101
tools.assert_equal(incremented_object_string, expected_incremented_version_string) # pylint: disable=E1101
def test_all_version_increments(self):
increment_types = (Version.MAJOR_VERSION, # 10
Version.MINOR_VERSION, # 20
Version.MICRO_VERSION, # 30
Version.DEVELOPMENT_VERSION, # 40
)
release_types = (Version.ALPHA_RELEASE, # 50
Version.BETA_RELEASE, # 60
Version.CANDIDATE_RELEASE, # 70
Version.NORMAL_RELEASE, # 80
)
test_table = (
('3.1.0',
(
('4.0.0a1', '4.0.0b1', '4.0.0c1', '4.0.0' ),
('3.2.0a1', '3.2.0b1', '3.2.0c1', '3.2.0' ),
('3.1.1a1', '3.1.1b1', '3.1.1c1', '3.1.1' ),
('ERR1', 'ERR1', 'ERR1', 'ERR2' ),
)
),
('4.6.1a2',
(
('5.0.0a1', '5.0.0b1', '5.0.0c1', '5.0.0' ),
('4.7.0a1', '4.7.0b1', '4.7.0c1', '4.7.0' ),
('4.6.2a1', '4.6.2b1', '4.6.2c1', '4.6.2' ),
('4.6.1a3', '4.6.1b1', '4.6.1c1', '4.6.1' ),
)
),
('4.6.1b2',
(
('5.0.0a1', '5.0.0b1', '5.0.0c1', '5.0.0' ),
('4.7.0a1', '4.7.0b1', '4.7.0c1', '4.7.0' ),
('4.6.2a1', '4.6.2b1', '4.6.2c1', '4.6.2' ),
('ERR3', '4.6.1b3', '4.6.1c1', '4.6.1' ),
)
),
('4.6.1c2',
(
('5.0.0a1', '5.0.0b1', '5.0.0c1', '5.0.0' ),
('4.7.0a1', '4.7.0b1', '4.7.0c1', '4.7.0' ),
('4.6.2a1', '4.6.2b1', '4.6.2c1', '4.6.2' ),
('ERR4', 'ERR5', '4.6.1c3', '4.6.1' ),
)
),
('0.0.0',
(
('1.0.0a1', '1.0.0b1', '1.0.0c1', '1.0.0' ),
('0.1.0a1', '0.1.0b1', '0.1.0c1', '0.1.0' ),
('0.0.1a1', '0.0.1b1', '0.0.1c1', '0.0.1' ),
('ERR1', 'ERR1', 'ERR1', 'ERR2' ),
)
),
('18.21.0',
(
('19.0.0a1', '19.0.0b1', '19.0.0c1', '19.0.0' ),
('18.22.0a1', '18.22.0b1', '18.22.0c1', '18.22.0' ),
('18.21.1a1', '18.21.1b1', '18.21.1c1', '18.21.1' ),
('ERR1', 'ERR1', 'ERR1', 'ERR2' ),
)
),
('8.9.1c32',
(
('9.0.0a1', '9.0.0b1', '9.0.0c1', '9.0.0' ),
('8.10.0a1', '8.10.0b1', '8.10.0c1', '8.10.0' ),
('8.9.2a1', '8.9.2b1', '8.9.2c1', '8.9.2' ),
('ERR4', 'ERR5', '8.9.1c33', '8.9.1' ),
)
),
)
for version_number, result_table in test_table:
for i in range(len(increment_types)):
for j in range(len(release_types)):
increment_type = increment_types[i]
release_type = release_types[j]
expected_result = result_table[i][j]
yield (
self.run_allow_error,
version_number,
increment_type,
release_type,
expected_result,
)
def run_allow_error(self,
version_number,
increment_type,
release_type,
expected_result,
):
if expected_result.startswith('ERR'):
#print
#print "Expected Result"
#print expected_result
expected_error = self.ERROR_MESSAGES[expected_result]
self.assert_raises(
ScriptException,
expected_error,
self.try_increment,
Version(version_number),
increment_type,
release_type,
expected_result,
)
else:
self.try_increment(
Version(version_number),
increment_type,
release_type,
expected_result,
)
#
# R E L E A S E T Y P E
#
# 3.1.0 alpha beta candidate normal
#
# I major 4.0.0a1 4.0.0b1 4.0.0c1 4.0.0
# N
# C T minor 3.2.0a1 3.2.0b1 3.2.0c1 3.2.0
# R Y
# E P micro 3.1.1a1 3.1.1b1 3.1.1c1 3.1.1
# M E
# E dev error error error error - When you specify a development increment, you can't
# N | | | go from one normal release to another.
# T | | |
# Must specify an increment type when incrementing a
# non-development build to a development build. Can't
# go from 3.1.0 to 3.1.0a1 (that's going backwards)
#
#
# 4.6.1a2 alpha beta candidate normal
#
# major 5.0.0a1 5.0.0b1 5.0.0c1 5.0.0
#
# minor 4.7.0a1 4.7.0b1 4.7.0c1 4.7.0
#
# micro 4.6.2a1 4.6.2b1 4.6.2c1 4.6.2
#
# dev 4.6.1a3 4.6.1b1 4.6.1c1 4.6.1
#
#
#
# 4.6.1b2 alpha beta candidate normal
#
# major 5.0.0a1 5.0.0b1 5.0.0c1 5.0.0
#
# minor 4.7.0a1 4.7.0b1 4.7.0c1 4.7.0
#
# micro 4.6.2a1 4.6.2b1 4.6.2c1 4.6.2
#
# dev error 4.6.1b3 4.6.1c1 4.6.1
# |
# |
# Can't go from beta to alpha of the same version
#
#
# 4.6.1c2 alpha beta candidate normal
#
# major 5.0.0a1 5.0.0b1 5.0.0c1 5.0.0
#
# minor 4.7.0a1 4.7.0b1 4.7.0c1 4.7.0
#
# micro 4.6.2a1 4.6.2b1 4.6.2c1 4.6.2
#
# dev error error 4.6.1c3 4.6.1
# | |
# | |
# | Can't go from candidate to beta of the same version
# |
# Can't go from candidate to alpha of the same version
#