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
360
361
362
363
364
365
366
367
368
369
|
# vim: set fileencoding=utf-8 :
"""Test L{gbp.scripts.dch} main"""
from . import context
# Try unittest2 for CentOS
try:
import unittest2 as unittest
except ImportError:
import unittest
from tests.testutils import (DebianGitTestRepo, OsReleaseFile,
get_dch_default_urgency)
from gbp.scripts import dch
import os
import re
# Older dch compatibility
default_urgency = get_dch_default_urgency()
# For Ubuntu compatibility
os_release = OsReleaseFile('/etc/lsb-release')
# OS release codename and snapshot of version 0.9-2~1
if os_release['DISTRIB_ID'] == 'Ubuntu':
os_codename = os_release['DISTRIB_CODENAME']
snap_header_0_9 = r'^test-package\s\(0.9-1ubuntu1~1\.gbp([0-9a-f]{6})\)\sUNRELEASED;\surgency=%s' % default_urgency
new_version_0_9 = '0.9-1ubuntu1'
else:
os_codename = 'unstable'
snap_header_0_9 = r'^test-package\s\(0.9-2~1\.gbp([0-9a-f]{6})\)\sUNRELEASED;\surgency=%s' % default_urgency
new_version_0_9 = '0.9-2'
# Snapshot of version 1.0-1~1
snap_header_1 = r'^test-package\s\(1.0-1~1\.gbp([0-9a-f]{6})\)\sUNRELEASED;\surgency=%s' % default_urgency
# Snapshot of version 1.0-1~2
snap_header_1_2 = r'^test-package\s\(1.0-1~2\.gbp([0-9a-f]{6})\)\sUNRELEASED;\surgency=%s' % default_urgency
snap_mark = r'\s{2}\*{2}\sSNAPSHOT\sbuild\s@'
deb_tag = "debian/0.9-1"
deb_tag_msg = "Pre stable release version 0.9-1"
cl_debian = """test-package (0.9-1) unstable; urgency=%s
[ Debian Maintainer ]
* New pre stable upstream release
-- Debian Maintainer <maint@debian.org> Mon, 17 Oct 2011 10:15:22 +0200
""" % default_urgency
@unittest.skipIf(not os.path.exists('/usr/bin/dch'), "Dch not found")
class TestScriptDch(DebianGitTestRepo):
"""Test git-dch"""
def setUp(self):
DebianGitTestRepo.setUp(self)
self.add_file("foo", "bar")
self.repo.create_tag("upstream/0.9", msg="upstream version 0.9")
self.add_file("bar", "foo")
self.repo.create_tag("upstream/1.0", msg="upstream version 1.0")
self.repo.create_branch("debian")
self.repo.set_branch("debian")
self.upstream_tag = "upstream/%(version)s"
self.top = os.path.abspath(os.path.curdir)
os.mkdir(os.path.join(self.repo.path, "debian"))
context.chdir(self.repo.path)
self.add_file("debian/changelog", cl_debian)
self.add_file("debian/control", """Source: test-package\nSection: test\n""")
self.options = ["--upstream-tag=%s" % self.upstream_tag, "--debian-branch=debian",
"--id-length=0", "--spawn-editor=/bin/true"]
self.repo.create_tag(deb_tag, msg=deb_tag_msg, commit="HEAD~1")
def tearDown(self):
DebianGitTestRepo.tearDown(self)
def run_dch(self, dch_options=None):
# Take care to copy the list
options = self.options[:]
if dch_options is not None:
options.extend(dch_options)
ret = dch.main(options)
self.assertEqual(ret, 0)
return open("debian/changelog").readlines()
def test_dch_main_new_upstream_version(self):
"""Test dch.py like git-dch script does: new upstream version"""
lines = self.run_dch()
self.assertEqual("test-package (1.0-1) UNRELEASED; urgency=%s\n" % default_urgency, lines[0])
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_new_upstream_version_with_release(self):
"""Test dch.py like git-dch script does: new upstream version - release"""
options = ["--release"]
lines = self.run_dch(options)
self.assertEqual("test-package (1.0-1) %s; urgency=%s\n" % (os_codename, default_urgency), lines[0])
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_new_upstream_version_with_auto(self):
"""Test dch.py like git-dch script does: new upstream version - guess last commit"""
options = ["--auto"]
lines = self.run_dch(options)
self.assertEqual("test-package (1.0-1) UNRELEASED; urgency=%s\n" % default_urgency, lines[0])
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_new_upstream_version_with_snapshot(self):
"""Test dch.py like git-dch script does: new upstream version - snapshot mode"""
options = ["--snapshot"]
lines = self.run_dch(options)
header = re.search(snap_header_1, lines[0])
self.assertIsNotNone(header)
self.assertEqual(header.lastindex, 1)
self.assertIsNotNone(re.search(snap_mark + header.group(1), lines[2]))
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_new_upstream_version_with_2_snapshots_auto(self):
"""Test dch.py like git-dch script does: new upstream version - two snapshots - auto"""
options = ["--snapshot"]
lines = self.run_dch(options)
header1 = re.search(snap_header_1, lines[0])
self.assertIsNotNone(header1)
self.assertEqual(header1.lastindex, 1)
self.assertIsNotNone(re.search(snap_mark + header1.group(1), lines[2]))
self.assertIn(""" * added debian/control\n""", lines)
# New snapshot, use auto to guess last one
self.add_file("debian/compat", "9")
options.append("--auto")
lines = self.run_dch(options)
header2 = re.search(snap_header_1_2, lines[0])
self.assertIsNotNone(header2)
self.assertEqual(header2.lastindex, 1)
self.assertIsNotNone(re.search(snap_mark + header2.group(1), lines[2]))
# First snapshot entry must be concatenated with the last one
self.assertNotIn(header1.group(0) + "\n", lines)
self.assertIn(""" * added debian/control\n""", lines)
self.assertIn(""" * added debian/compat\n""", lines)
def test_dch_main_new_upstream_version_with_2_snapshots_commit_auto(self):
"""Test dch.py like git-dch script does: new upstream version - two committed snapshots - auto"""
options = ["--commit"]
options.append("--commit-msg=TEST-COMMITTED-SNAPSHOT")
options.append("--snapshot")
lines = self.run_dch(options)
header1 = re.search(snap_header_1, lines[0])
self.assertIsNotNone(header1)
self.assertEqual(header1.lastindex, 1)
self.assertIsNotNone(re.search(snap_mark + header1.group(1), lines[2]))
self.assertIn(""" * added debian/control\n""", lines)
# New snapshot, use auto to guess last one
self.add_file("debian/compat", "9")
options.append("--auto")
lines = self.run_dch(options)
header2 = re.search(snap_header_1_2, lines[0])
self.assertIsNotNone(header2)
self.assertEqual(header2.lastindex, 1)
self.assertIsNotNone(re.search(snap_mark + header2.group(1), lines[2]))
self.assertIn(""" * added debian/control\n""", lines)
self.assertIn(""" * added debian/compat\n""", lines)
# First snapshot entry must have disapear
self.assertNotIn(header1.group(0) + "\n", lines)
# But its changelog must be included in the new one
self.assertIn(""" * TEST-COMMITTED-SNAPSHOT\n""", lines)
def test_dch_main_new_upstream_version_with_auto_release(self):
"""Test dch.py like git-dch script does: new upstream version - auto - release"""
options = ["--auto", "--release"]
lines = self.run_dch(options)
self.assertEqual("test-package (1.0-1) %s; urgency=%s\n" % (os_codename, default_urgency), lines[0])
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_new_upstream_version_with_auto_snapshot(self):
"""Test dch.py like git-dch script does: new upstream version - auto - snapshot mode"""
options = [ "--auto", "--snapshot" ]
options.append("--snapshot")
lines = self.run_dch(options)
header = re.search(snap_header_1, lines[0])
self.assertIsNotNone(header)
self.assertEqual(header.lastindex, 1)
self.assertIsNotNone(re.search(snap_mark + header.group(1), lines[2]))
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_new_upstream_version_with_snapshot_release(self):
"""Test dch.py like git-dch script does: new upstream version - snapshot - release"""
options = ["--snapshot", "--release"]
self.assertRaises(SystemExit, self.run_dch, options)
def test_dch_main_new_upstream_version_with_distribution(self):
"""Test dch.py like git-dch script does: new upstream version - set distribution"""
options = ["--distribution=testing", "--force-distribution"]
lines = self.run_dch(options)
self.assertEqual("test-package (1.0-1) testing; urgency=%s\n" % default_urgency, lines[0])
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_new_upstream_version_with_release_distribution(self):
"""Test dch.py like git-dch script does: new upstream version - release - set distribution"""
options = ["--release", "--distribution=testing", "--force-distribution"]
lines = self.run_dch(options)
self.assertEqual("test-package (1.0-1) testing; urgency=%s\n" % default_urgency, lines[0])
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_new_upstream_version_with_snapshot_distribution(self):
"""Test dch.py like git-dch script does: new upstream version - snapshot mode - do not set distribution"""
options = ["--snapshot", "--distribution=testing"]
lines = self.run_dch(options)
header = re.search(snap_header_1, lines[0])
self.assertIsNotNone(header)
self.assertEqual(header.lastindex, 1)
self.assertIsNotNone(re.search(snap_mark + header.group(1), lines[2]))
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_new_upstream_version_with_2_snapshots_auto_distribution(self):
"""Test dch.py like git-dch script does: new upstream version - two snapshots - do not set distribution"""
options = ["--snapshot", "--distribution=testing"]
lines = self.run_dch(options)
header1 = re.search(snap_header_1, lines[0])
self.assertIsNotNone(header1)
self.assertEqual(header1.lastindex, 1)
self.assertIsNotNone(re.search(snap_mark + header1.group(1), lines[2]))
self.assertIn(""" * added debian/control\n""", lines)
# New snapshot, use auto to guess last one
self.add_file("debian/compat", "9")
options.append("--auto")
lines = self.run_dch(options)
header2 = re.search(snap_header_1_2, lines[0])
self.assertIsNotNone(header2)
self.assertEqual(header2.lastindex, 1)
self.assertIsNotNone(re.search(snap_mark + header2.group(1), lines[2]))
# First snapshot entry must be concatenated with the last one
self.assertNotIn(header1.group(0) + "\n", lines)
self.assertIn(""" * added debian/control\n""", lines)
self.assertIn(""" * added debian/compat\n""", lines)
# But its changelog must not be included in the new one since
# we do not commit
self.assertNotIn(""" * TEST-COMMITTED-SNAPSHOT\n""", lines)
def test_dch_main_new_upstream_version_with_2_snapshots_commit_auto_distribution(self):
"""Test dch.py like git-dch script does: new upstream version - two committed snapshots - do not set distribution"""
options = ["--commit"]
options.append("--commit-msg=TEST-COMMITTED-SNAPSHOT")
options.append("--snapshot")
options.append("--distribution=testing")
lines = self.run_dch(options)
header1 = re.search(snap_header_1, lines[0])
self.assertIsNotNone(header1)
self.assertEqual(header1.lastindex, 1)
self.assertIsNotNone(re.search(snap_mark + header1.group(1), lines[2]))
self.assertIn(""" * added debian/control\n""", lines)
# New snapshot, use auto to guess last one
self.add_file("debian/compat", "9")
options.append("--auto")
lines = self.run_dch(options)
header2 = re.search(snap_header_1_2, lines[0])
self.assertIsNotNone(header2)
self.assertEqual(header2.lastindex, 1)
self.assertIsNotNone(re.search(snap_mark + header2.group(1), lines[2]))
self.assertIn(""" * added debian/control\n""", lines)
self.assertIn(""" * added debian/compat\n""", lines)
# First snapshot entry must have disapear
self.assertNotIn(header1.group(0) + "\n", lines)
# But its changelog must be included in the new one
self.assertIn(""" * TEST-COMMITTED-SNAPSHOT\n""", lines)
def test_dch_main_new_upstream_version_with_urgency(self):
"""Test dch.py like git-dch script does: new upstream version - set urgency"""
options = ["--urgency=emergency"]
lines = self.run_dch(options)
self.assertEqual("test-package (1.0-1) UNRELEASED; urgency=emergency\n", lines[0])
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_new_upstream_version_with_release_urgency(self):
"""Test dch.py like git-dch script does: new upstream version - release - set urgency"""
options = ["--release", "--urgency=emergency"]
lines = self.run_dch(options)
self.assertEqual("test-package (1.0-1) %s; urgency=emergency\n" % os_codename, lines[0])
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_new_upstream_version_with_snapshot_urgency(self):
"""Test dch.py like git-dch script does: new upstream version - snapshot mode - set urgency"""
options = ["--snapshot", "--urgency=emergency"]
lines = self.run_dch(options)
header = re.search(snap_header_1, lines[0])
self.assertIsNotNone(header)
self.assertEqual(header.lastindex, 1)
self.assertIsNotNone(re.search(snap_mark + header.group(1), lines[2]))
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_increment_debian_version(self):
"""Test dch.py like git-dch script does: increment debian version"""
self.repo.delete_tag("debian/0.9-1")
self.repo.create_tag("debian/0.9-1", msg="Pre stable release version 0.9-1", commit="HEAD~2")
self.repo.delete_tag("upstream/1.0")
lines = self.run_dch()
self.assertEqual("test-package (%s) UNRELEASED; urgency=%s\n" % (new_version_0_9, default_urgency), lines[0])
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_increment_debian_version_with_release(self):
"""Test dch.py like git-dch script does: increment debian version - release"""
self.repo.delete_tag("upstream/1.0")
options = ["--release"]
lines = self.run_dch(options)
self.assertEqual("test-package (%s) %s; urgency=%s\n" % (new_version_0_9, os_codename, default_urgency), lines[0])
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_increment_debian_version_with_auto(self):
"""Test dch.py like git-dch script does: increment debian version - guess last commit"""
self.repo.delete_tag("upstream/1.0")
options = ["--auto"]
lines = self.run_dch(options)
self.assertEqual("test-package (%s) UNRELEASED; urgency=%s\n" % (new_version_0_9, default_urgency), lines[0])
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_increment_debian_version_with_snapshot(self):
"""Test dch.py like git-dch script does: increment debian version - snapshot mode"""
self.repo.delete_tag("upstream/1.0")
options = ["--snapshot"]
lines = self.run_dch(options)
header = re.search(snap_header_0_9, lines[0])
self.assertIsNotNone(header)
self.assertEqual(header.lastindex, 1)
self.assertIsNotNone(re.search(snap_mark + header.group(1), lines[2]))
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_increment_debian_version_with_auto_release(self):
"""Test dch.py like git-dch script does: increment debian version - auto - release"""
self.repo.delete_tag("upstream/1.0")
options = ["--auto", "--release"]
lines = self.run_dch(options)
self.assertEqual("test-package (%s) %s; urgency=%s\n" % (new_version_0_9, os_codename, default_urgency), lines[0])
self.assertIn(""" * added debian/control\n""", lines)
def test_dch_main_increment_debian_version_with_auto_snapshot(self):
"""Test dch.py like git-dch script does: increment debian version - auto - snapshot mode"""
self.repo.delete_tag("upstream/1.0")
options = ["--auto", "--snapshot"]
lines = self.run_dch(options)
header = re.search(snap_header_0_9, lines[0])
self.assertIsNotNone(header)
self.assertEqual(header.lastindex, 1)
self.assertIsNotNone(re.search(snap_mark + header.group(1), lines[2]))
self.assertIn(""" * added debian/control\n""", lines)
|