forked from dbt-labs/dbt-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_semver.py
185 lines (146 loc) · 5.96 KB
/
test_semver.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
import unittest
import itertools
from dbt.exceptions import VersionsNotCompatibleException
from dbt.semver import VersionSpecifier, UnboundedVersionSpecifier, \
VersionRange, reduce_versions, versions_compatible, \
resolve_to_specific_version, filter_installable
def create_range(start_version_string, end_version_string):
start = UnboundedVersionSpecifier()
end = UnboundedVersionSpecifier()
if start_version_string is not None:
start = VersionSpecifier.from_version_string(start_version_string)
if end_version_string is not None:
end = VersionSpecifier.from_version_string(end_version_string)
return VersionRange(start=start, end=end)
class TestSemver(unittest.TestCase):
def assertVersionSetResult(self, inputs, output_range):
expected = create_range(*output_range)
for permutation in itertools.permutations(inputs):
self.assertEqual(
reduce_versions(*permutation),
expected)
def assertInvalidVersionSet(self, inputs):
for permutation in itertools.permutations(inputs):
with self.assertRaises(VersionsNotCompatibleException):
reduce_versions(*permutation)
def test__versions_compatible(self):
self.assertTrue(
versions_compatible('0.0.1', '0.0.1'))
self.assertFalse(
versions_compatible('0.0.1', '0.0.2'))
self.assertTrue(
versions_compatible('>0.0.1', '0.0.2'))
self.assertFalse(
versions_compatible('0.4.5a1', '0.4.5a2'))
def test__reduce_versions(self):
self.assertVersionSetResult(
['0.0.1', '0.0.1'],
['=0.0.1', '=0.0.1'])
self.assertVersionSetResult(
['0.0.1'],
['=0.0.1', '=0.0.1'])
self.assertVersionSetResult(
['>0.0.1'],
['>0.0.1', None])
self.assertVersionSetResult(
['<0.0.1'],
[None, '<0.0.1'])
self.assertVersionSetResult(
['>0.0.1', '0.0.2'],
['=0.0.2', '=0.0.2'])
self.assertVersionSetResult(
['0.0.2', '>=0.0.2'],
['=0.0.2', '=0.0.2'])
self.assertVersionSetResult(
['>0.0.1', '>0.0.2', '>0.0.3'],
['>0.0.3', None])
self.assertVersionSetResult(
['>0.0.1', '<0.0.3'],
['>0.0.1', '<0.0.3'])
self.assertVersionSetResult(
['>0.0.1', '0.0.2', '<0.0.3'],
['=0.0.2', '=0.0.2'])
self.assertVersionSetResult(
['>0.0.1', '>=0.0.1', '<0.0.3'],
['>0.0.1', '<0.0.3'])
self.assertVersionSetResult(
['>0.0.1', '<0.0.3', '<=0.0.3'],
['>0.0.1', '<0.0.3'])
self.assertVersionSetResult(
['>0.0.1', '>0.0.2', '<0.0.3', '<0.0.4'],
['>0.0.2', '<0.0.3'])
self.assertVersionSetResult(
['<=0.0.3', '>=0.0.3'],
['>=0.0.3', '<=0.0.3'])
self.assertInvalidVersionSet(['>0.0.2', '0.0.1'])
self.assertInvalidVersionSet(['>0.0.2', '0.0.2'])
self.assertInvalidVersionSet(['<0.0.2', '0.0.2'])
self.assertInvalidVersionSet(['<0.0.2', '>0.0.3'])
self.assertInvalidVersionSet(['<=0.0.3', '>0.0.3'])
self.assertInvalidVersionSet(['<0.0.3', '>=0.0.3'])
self.assertInvalidVersionSet(['<0.0.3', '>0.0.3'])
def test__resolve_to_specific_version(self):
self.assertEqual(
resolve_to_specific_version(
create_range('>0.0.1', None),
['0.0.1', '0.0.2']),
'0.0.2')
self.assertEqual(
resolve_to_specific_version(
create_range('>=0.0.2', None),
['0.0.1', '0.0.2']),
'0.0.2')
self.assertEqual(
resolve_to_specific_version(
create_range('>=0.0.3', None),
['0.0.1', '0.0.2']),
None)
self.assertEqual(
resolve_to_specific_version(
create_range('>=0.0.3', '<0.0.5'),
['0.0.3', '0.0.4', '0.0.5']),
'0.0.4')
self.assertEqual(
resolve_to_specific_version(
create_range(None, '<=0.0.5'),
['0.0.3', '0.1.4', '0.0.5']),
'0.0.5')
self.assertEqual(
resolve_to_specific_version(
create_range('=0.4.5a2', '=0.4.5a2'),
['0.4.5a1', '0.4.5a2']),
'0.4.5a2')
self.assertEqual(
resolve_to_specific_version(
create_range('=0.7.6', '=0.7.6'),
['0.7.6-b1', '0.7.6']),
'0.7.6')
self.assertEqual(
resolve_to_specific_version(
create_range('>=1.0.0', None),
['1.0.0', '1.1.0a1', '1.1.0', '1.2.0a1']),
'1.2.0a1')
self.assertEqual(
resolve_to_specific_version(
create_range('>=1.0.0', '<1.2.0'),
['1.0.0', '1.1.0a1', '1.1.0', '1.2.0a1']),
'1.1.0')
self.assertEqual(
resolve_to_specific_version(
create_range('>=1.0.0', None),
['1.0.0', '1.1.0a1', '1.1.0', '1.2.0a1', '1.2.0']),
'1.2.0')
self.assertEqual(
resolve_to_specific_version(
create_range('>=1.0.0', '<1.2.0'),
['1.0.0', '1.1.0a1', '1.1.0', '1.2.0a1', '1.2.0']),
'1.1.0')
def test__filter_installable(self):
assert filter_installable(
['1.1.0', '1.2.0a1', '1.0.0','2.1.0-alpha','2.2.0asdf','2.1.0','2.2.0','2.2.0-fishtown-beta','2.2.0-2'],
install_prerelease=True
) == ['1.0.0', '1.1.0', '1.2.0a1','2.1.0-alpha','2.1.0','2.2.0asdf','2.2.0-fishtown-beta','2.2.0-2','2.2.0']
assert filter_installable(
['1.1.0', '1.2.0a1', '1.0.0','2.1.0-alpha','2.2.0asdf','2.1.0','2.2.0','2.2.0-fishtown-beta'],
install_prerelease=False
) == ['1.0.0', '1.1.0','2.1.0','2.2.0']