This repository has been archived by the owner on Jul 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
tests.py
203 lines (167 loc) · 6.98 KB
/
tests.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
import os
from subprocess import call
import unittest
import semvertag
DEVNULL = open(os.devnull, 'wb')
class BaseSemVerTagTest(unittest.TestCase):
def setUp(self):
call("rm -Rf tmp".split())
call("mkdir -p tmp/repo-origin".split())
call("ls",
cwd="tmp",
stdout=DEVNULL)
call("git init".split(),
cwd="tmp/repo-origin",
stdout=DEVNULL)
call("touch readme.md".split(),
cwd="tmp/repo-origin",
stdout=DEVNULL)
call("git add .".split(),
cwd="tmp/repo-origin",
stdout=DEVNULL)
call("git commit -m start".split(),
cwd="tmp/repo-origin",
stdout=DEVNULL)
call("git clone repo-origin repo".split(),
cwd="tmp",
stdout=DEVNULL,
stderr=DEVNULL)
def semvertag(self, command, cwd='tmp/repo'):
parser = semvertag.get_argparser()
args_list = ['--cwd', cwd]
args_list.extend(command.split())
args = parser.parse_args(args_list)
response = args.func(args)
return response
def gittag(self, tagname):
call('git tag {}'.format(tagname).split(),
cwd="tmp/repo",
stdout=DEVNULL)
def tearDown(self):
call("rm -Rf tmp".split())
class TestSemVerTag(BaseSemVerTagTest):
def setUp(self):
super(TestSemVerTag, self).setUp()
self.gittag('1.0.0')
self.gittag('1.0.1+1')
self.gittag('1.0.1+2')
self.gittag('1.0.1+3')
self.gittag('1.2.1+3')
self.gittag('1.2.1-foo+2')
self.gittag('1.2.1-foo+1')
self.gittag('1.3.1-bar+1')
self.gittag('1.3.2-bar')
self.gittag('plum-0.0.2-bar+1')
self.gittag('plum-0.0.2-bar+2')
self.gittag('plum-0.0.1-bar+2')
# unsupported strings
self.gittag('plum-0.0.a-bar+2')
self.gittag('plum-0.0.a-bar+2bc')
def test_latest(self):
ver = self.semvertag('latest').strip()
assert ver == "1.2.1+3"
ver = self.semvertag('latest --stage foo ').strip()
assert ver == "1.2.1-foo+2"
ver = self.semvertag('latest --stage bar ').strip()
assert ver == "1.3.2-bar"
ver = self.semvertag('latest --stage bar --prefix plum- ').strip()
assert ver == "plum-0.0.2-bar+2"
def test_bump(self):
ver = self.semvertag('bump').strip()
assert ver == "1.2.1+4"
ver = self.semvertag('bump --stage foo').strip()
assert ver == "1.2.1-foo+3"
ver = self.semvertag('bump --stage bar').strip()
assert ver == "1.3.2-bar+1"
ver = self.semvertag('bump --stage bar --prefix plum-').strip()
assert ver == "plum-0.0.2-bar+3"
def test_bump_tagging(self):
ver = self.semvertag('bump --tag').strip()
assert ver == "1.2.1+4"
ver = self.semvertag('bump --tag').strip()
assert ver == "1.2.1+5"
ver = self.semvertag('bump --stage foo --tag').strip()
assert ver == "1.2.1-foo+3"
ver = self.semvertag('bump --stage foo --tag').strip()
assert ver == "1.2.1-foo+4"
ver = self.semvertag('bump --stage bar --prefix plum- --tag').strip()
assert ver == "plum-0.0.2-bar+3"
ver = self.semvertag('bump --stage bar --prefix plum- --tag').strip()
assert ver == "plum-0.0.2-bar+4"
def test_set_arbitrary_tag(self):
ver = self.semvertag('tag foobar-1.2.3').strip()
assert ver == 'foobar-1.2.3'
def test_fields_bumping(self):
ver = self.semvertag('tag precious-0.0.1').strip()
assert ver == 'precious-0.0.1'
ver = self.semvertag('bump --prefix precious- --tag').strip()
assert ver == "precious-0.0.1+1"
ver = self.semvertag('bump --prefix precious- --tag patch').strip()
assert ver == "precious-0.0.2"
ver = self.semvertag('bump --prefix precious- --tag minor').strip()
assert ver == "precious-0.1.0"
ver = self.semvertag('bump --prefix precious- --tag major').strip()
assert ver == "precious-1.0.0"
ver = self.semvertag('bump --prefix precious- --tag').strip()
assert ver == "precious-1.0.0+1"
def test_list(self):
tags = self.semvertag('list').strip()
assert tags == "1.2.1+3\n1.0.1+3\n1.0.1+2\n1.0.1+1\n1.0.0"
tags = self.semvertag('list --csv').strip()
assert tags == "1.2.1+3,1.0.1+3,1.0.1+2,1.0.1+1,1.0.0"
tags = self.semvertag('list --reverse').strip()
assert tags == "1.0.0\n1.0.1+1\n1.0.1+2\n1.0.1+3\n1.2.1+3"
tags = self.semvertag('list --reverse --csv').strip()
assert tags == "1.0.0,1.0.1+1,1.0.1+2,1.0.1+3,1.2.1+3"
class TestInitialiseTags(BaseSemVerTagTest):
# Test that initial tag is created correctly with empty repos.
def test_starting_tag(self):
ver = self.semvertag('bump --tag').strip()
tags = self.semvertag('list').strip()
assert ver == '0.0.0+1'
assert tags == '0.0.0+1'
def test_starting_tag_patch(self):
ver = self.semvertag('bump patch --tag').strip()
tags = self.semvertag('list').strip()
assert ver == '0.0.1'
assert tags == '0.0.1'
def test_starting_tag_minor(self):
ver = self.semvertag('bump minor --tag').strip()
tags = self.semvertag('list').strip()
assert ver == '0.1.0'
assert tags == '0.1.0'
def test_starting_tag_minor_suffix(self):
ver = self.semvertag('bump minor --tag --stage foo').strip()
tags = self.semvertag('list --stage foo').strip()
assert ver == '0.1.0-foo'
assert tags == '0.1.0-foo'
def test_starting_tag_minor_prefix(self):
ver = self.semvertag('bump minor --tag --prefix plum-').strip()
tags = self.semvertag('list --prefix plum-').strip()
assert ver == 'plum-0.1.0'
assert tags == 'plum-0.1.0'
def test_tagging_scheme_initialisation_can_coexist(self):
ver = self.semvertag('bump patch --tag').strip()
foo_ver = self.semvertag('bump patch --tag --stage foo').strip()
plum_ver = self.semvertag('bump patch --tag --prefix plum-').strip()
assert ver == '0.0.1'
assert foo_ver == '0.0.1-foo'
assert plum_ver == 'plum-0.0.1'
tags = self.semvertag('list').strip()
assert tags == '0.0.1'
tags = self.semvertag('list --stage foo').strip()
assert tags == '0.0.1-foo'
tags = self.semvertag('list --prefix plum-').strip()
assert tags == 'plum-0.0.1'
# Test that latest command reports the correct tags when no tags are present
def test_starting_latest(self):
ver = self.semvertag('latest').strip()
assert ver == '0.0.0'
def test_starting_latest_suffix(self):
ver = self.semvertag('latest --stage foo').strip()
assert ver == '0.0.0-foo'
def test_starting_latest_prefix(self):
ver = self.semvertag('latest --prefix plum-').strip()
assert ver == 'plum-0.0.0'
if __name__ == '__main__':
unittest.main()