forked from dbt-labs/dbt-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_semver.py
136 lines (105 loc) · 4.15 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
import unittest
import itertools
from dbt.exceptions import VersionsNotCompatibleException
from dbt.semver import VersionSpecifier, UnboundedVersionSpecifier, \
VersionRange, reduce_versions, versions_compatible, \
resolve_to_specific_version
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'))
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')