forked from metabrainz/picard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_versions.py
114 lines (86 loc) · 3.9 KB
/
test_versions.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
# -*- coding: utf-8 -*-
import sys
import unittest
from picard import (version_to_string,
version_from_string,
VersionError)
# assertLess is available since 2.7 only
if sys.version_info[:2] == (2, 6):
def assertLess(self, a, b, msg=None):
if not a < b:
self.fail('%s not less than %s' % (repr(a), repr(b)))
unittest.TestCase.assertLess = assertLess
class VersionsTest(unittest.TestCase):
def test_version_conv_1(self):
l, s = (0, 0, 1, 'dev', 1), '0.0.1dev1'
self.assertEqual(version_to_string(l), s)
self.assertEqual(l, version_from_string(s))
def test_version_conv_2(self):
l, s = (1, 1, 0, 'final', 0), '1.1.0final0'
self.assertEqual(version_to_string(l), s)
self.assertEqual(l, version_from_string(s))
def test_version_conv_3(self):
l, s = (1, 1, 0, 'dev', 0), '1.1.0dev0'
self.assertEqual(version_to_string(l), s)
self.assertEqual(l, version_from_string(s))
def test_version_conv_4(self):
l, s = (1, 0, 2, 'final', 0), '1.0.2'
self.assertEqual(version_to_string(l, short=True), s)
self.assertEqual(l, version_from_string(s))
def test_version_conv_5(self):
l, s = (999, 999, 999, 'dev', 999), '999.999.999dev999'
self.assertEqual(version_to_string(l), s)
self.assertEqual(l, version_from_string(s))
def test_version_conv_6(self):
l = (1, 0, 2, 'xx', 0)
self.assertRaises(VersionError, version_to_string, (l))
def test_version_conv_7(self):
l, s = (1, 1, 0, 'final', 0), '1.1'
self.assertEqual(version_to_string(l, short=True), s)
def test_version_conv_8(self):
l, s = (1, 1, 1, 'final', 0), '1.1.1'
self.assertEqual(version_to_string(l, short=True), s)
def test_version_conv_9(self):
l, s = (1, 1, 0, 'final', 1), '1.1'
self.assertEqual(version_to_string(l, short=True), s)
def test_version_conv_10(self):
l, s = (1, 1, 0, 'dev', 0), '1.1.0dev0'
self.assertEqual(version_to_string(l, short=True), s)
def test_version_conv_11(self):
l, s = ('1', '1', '0', 'dev', '0'), '1.1.0dev0'
self.assertEqual(version_to_string(l), s)
def test_version_conv_12(self):
l, s = (1, 1, 0, 'dev', 0), '1_1_0_dev_0'
self.assertEqual(l, version_from_string(s))
def test_version_conv_13(self):
l, s = (1, 1, 0, 'dev', 0), 'anything_28_1_1_0_dev_0'
self.assertEqual(l, version_from_string(s))
def test_version_conv_14(self):
l = 'anything_28x_1_0_dev_0'
self.assertRaises(VersionError, version_to_string, (l))
def test_version_conv_15(self):
l, s = (1, 1, 0, 'final', 0), 'anything_28_1_1_0'
self.assertEqual(l, version_from_string(s))
def test_version_conv_16(self):
self.assertRaises(VersionError, version_from_string, '1.1.0dev')
def test_version_conv_17(self):
self.assertRaises(VersionError, version_from_string, '1.1.0devx')
def test_version_conv_18(self):
l, s = (1, 1, 0, 'final', 0), '1.1'
self.assertEqual(version_to_string(l, short=True), s)
self.assertEqual(l, version_from_string(s))
def test_version_conv_19(self):
self.assertRaises(VersionError, version_from_string, '123')
def test_version_conv_20(self):
self.assertRaises(VersionError, version_from_string, '123.')
def test_api_versions_1(self):
"Check api versions format and order (from oldest to newest)"
from picard import api_versions
len_api_versions = len(api_versions)
if len_api_versions > 1:
for i in xrange(len_api_versions - 1):
a = version_from_string(api_versions[i])
b = version_from_string(api_versions[i+1])
self.assertLess(a, b)
elif len_api_versions == 1:
a = version_from_string(api_versions[0])