summaryrefslogtreecommitdiff
path: root/tests/test_Changelog.py
blob: d0572c1ecb0c9f16a102b822734c9a07900bc064 (plain)
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
# vim: set fileencoding=utf-8 :

"""
Test L{gbp.deb.changelog.ChangeLog}
"""
from . import context
import os
import nose

cl_debian = """git-buildpackage (0.5.32) unstable; urgency=low

  * [efe9220] Use known_compressions in guess_upstream_version too
    (Closes: #645477)
  * [e984baf] git-import-orig: fix --filter

 -- Guido Günther <agx@sigxcpu.org>  Mon, 17 Oct 2011 10:15:22 +0200

git-buildpackage (0.5.31) unstable; urgency=low

  [ Guido Günther ]
  * [3588d88] Fix pristine-tar error message
  * [8da98da] gbp-pq: don't fail on missing series file but create an empty
    branch instead

  [ Salvatore Bonaccorso ]
  * [b33cf74] Fix URL to cl2vcs service.
    Refer to https://honk.sigxcpu.org/cl2vcs instead of
    https://honk.sigxcpu.org/cl2vcs for the cl2vcs service. (Closes: #640141)

 -- Guido Günther <agx@sigxcpu.org>  Wed, 28 Sep 2011 20:21:34 +0200
"""

cl_upstream="""python-dateutil (1.0-1) unstable; urgency=low

  * Initial release (Closes: #386256)

 -- Guido Günther <agx@sigxcpu.org>  Wed,  6 Sep 2006 10:33:06 +0200
"""

cl_epoch="""xserver-xorg-video-nv (1:1.2.0-3) unstable; urgency=low

  [ Steve Langasek ]
  * Upload to unstable

 -- David Nusinow <dnusinow@debian.org>  Mon, 18 Sep 2006 19:57:45 -0400
"""

def setup():
    """Setup test module"""
    if not os.path.exists('/usr/bin/dch'):
        raise nose.SkipTest('dch tool not present')

def test_parse_debian_only():
    """
    Parse a the changelog of debian only package

    Methods tested:
         - L{gbp.deb.changelog.ChangeLog.__init__}
         - L{gbp.deb.changelog.ChangeLog.is_native}

    Properties tested:
         - L{gbp.deb.changelog.ChangeLog.version}
         - L{gbp.deb.changelog.ChangeLog.debian_version}
         - L{gbp.deb.changelog.ChangeLog.upstream_version}
         - L{gbp.deb.changelog.ChangeLog.epoch}
         - L{gbp.deb.changelog.ChangeLog.noepoch}

    >>> import gbp.deb.changelog
    >>> cl = gbp.deb.changelog.ChangeLog(cl_debian)
    >>> cl.version
    '0.5.32'
    >>> cl.version == cl['Version']
    True
    >>> cl.debian_version
    '0.5.32'
    >>> cl.debian_version == cl['Debian-Version']
    True
    >>> cl.noepoch
    '0.5.32'
    >>> cl.noepoch == cl['NoEpoch-Version']
    True
    >>> cl.epoch
    >>> cl.upstream_version
    >>> cl.is_native()
    True
    """

def test_parse_no_eopch():
    """
    Parse a the changelog of a package without eopch

    Methods tested:
         - L{gbp.deb.changelog.ChangeLog.__init__}
         - L{gbp.deb.changelog.ChangeLog.has_epoch}
         - L{gbp.deb.changelog.ChangeLog.is_native}

    Properties tested:
         - L{gbp.deb.changelog.ChangeLog.version}
         - L{gbp.deb.changelog.ChangeLog.debian_version}
         - L{gbp.deb.changelog.ChangeLog.upstream_version}
         - L{gbp.deb.changelog.ChangeLog.epoch}
         - L{gbp.deb.changelog.ChangeLog.noepoch}

    >>> import gbp.deb.changelog
    >>> cl = gbp.deb.changelog.ChangeLog(cl_upstream)
    >>> cl.version
    '1.0-1'
    >>> cl.version == cl['Version']
    True
    >>> cl.debian_version
    '1'
    >>> cl.debian_version == cl['Debian-Version']
    True
    >>> cl.noepoch
    '1.0-1'
    >>> cl.noepoch == cl['NoEpoch-Version']
    True
    >>> cl.epoch
    >>> cl.upstream_version
    '1.0'
    >>> cl.has_epoch()
    False
    >>> cl.is_native()
    False
    """

def test_parse_eopch():
    """
    Parse a the changelog of a package without epoch

    Methods tested:
         - L{gbp.deb.changelog.ChangeLog.__init__}
         - L{gbp.deb.changelog.ChangeLog.has_epoch}
         - L{gbp.deb.changelog.ChangeLog.is_native}

    Properties tested:
         - L{gbp.deb.changelog.ChangeLog.version}
         - L{gbp.deb.changelog.ChangeLog.debian_version}
         - L{gbp.deb.changelog.ChangeLog.upstream_version}
         - L{gbp.deb.changelog.ChangeLog.epoch}
         - L{gbp.deb.changelog.ChangeLog.noepoch}

    >>> import gbp.deb.changelog
    >>> cl = gbp.deb.changelog.ChangeLog(cl_epoch)
    >>> cl.version
    '1:1.2.0-3'
    >>> cl.version == cl['Version']
    True
    >>> cl.debian_version
    '3'
    >>> cl.debian_version == cl['Debian-Version']
    True
    >>> cl.noepoch
    '1.2.0-3'
    >>> cl.noepoch == cl['NoEpoch-Version']
    True
    >>> cl.epoch
    '1'
    >>> cl.upstream_version
    '1.2.0'
    >>> cl.has_epoch()
    True
    >>> cl.is_native()
    False
    """

def test_parse_name():
    """
    Methods tested:
         - L{gbp.deb.changelog.ChangeLog.__init__}

    Properties tested:
         - L{gbp.deb.changelog.ChangeLog.name}

    >>> import gbp.deb.changelog
    >>> cl = gbp.deb.changelog.ChangeLog(cl_debian)
    >>> cl.name
    'git-buildpackage'
    """

def test_parse_last_mod():
    """
    Test author, email and date of last modification

    Methods tested:
         - L{gbp.deb.changelog.ChangeLog.__init__}

    Properties tested:
         - L{gbp.deb.changelog.ChangeLog.name}
         - L{gbp.deb.changelog.ChangeLog.email}
         - L{gbp.deb.changelog.ChangeLog.date}

    >>> import gbp.deb.changelog
    >>> cl = gbp.deb.changelog.ChangeLog(cl_debian)
    >>> cl.author.startswith('Guido')
    True
    >>> cl.email
    'agx@sigxcpu.org'
    >>> cl.date
    'Mon, 17 Oct 2011 10:15:22 +0200'
    """

def test_parse_sections():
    """
    Test if we can parse sections out of the changelog

    Methods tested:
         - L{gbp.deb.changelog.ChangeLog.__init__}
         - L{gbp.deb.changelog.ChangeLogSection.__init__}
         - L{gbp.deb.changelog.ChangeLogSection.parse}

    Properties tested:
         - L{gbp.deb.changelog.ChangeLog.sections}

    >>> import gbp.deb.changelog
    >>> cl = gbp.deb.changelog.ChangeLog(cl_debian)
    >>> cl.sections[0].package
    'git-buildpackage'
    >>> cl.sections[0].version
    '0.5.32'
    >>> cl.sections[1].package
    'git-buildpackage'
    >>> cl.sections[1].version
    '0.5.31'
    """

def test_add_section():
    """
    Test if we can add a section to an existant changelog

    Methods tested:
         - L{gbp.deb.changelog.ChangeLog.__init__}
         - L{gbp.deb.changelog.ChangeLog._parse}
         - L{gbp.deb.changelog.ChangeLog.add_section}
         - L{gbp.deb.changelog.ChangeLog.spawn_dch}

    >>> import os
    >>> import tempfile
    >>> import shutil
    >>> import gbp.deb.changelog
    >>> olddir = os.path.abspath(os.path.curdir)
    >>> testdir = tempfile.mkdtemp(prefix='gbp-test-changelog-')
    >>> testdebdir = os.path.join(testdir, 'debian')
    >>> testclname = os.path.join(testdebdir, "changelog")
    >>> os.mkdir(testdebdir)
    >>> clh = open(os.path.join(testdebdir, "changelog"), "w")
    >>> clh.write(cl_debian)
    >>> clh.close()
    >>> os.chdir(testdir)
    >>> os.path.abspath(os.path.curdir) == testdir
    True
    >>> cl = gbp.deb.changelog.ChangeLog(filename=testclname)
    >>> cl.add_section(msg=["Test add section"], distribution=None, author="Debian Maintainer", email="maint@debian.org")
    >>> cl = gbp.deb.changelog.ChangeLog(filename=testclname)
    >>> cl.version
    '0.5.33'
    >>> cl.debian_version
    '0.5.33'
    >>> cl['Distribution'] in ['UNRELEASED', 'unstable']
    True
    >>> 'Test add section' in cl['Changes']
    True
    >>> os.chdir(olddir)
    >>> os.path.abspath(os.path.curdir) == olddir
    True
    >>> shutil.rmtree(testdir, ignore_errors=True)
    """

def test_add_entry():
    """
    Test if we can add an entry to an existant changelog

    Methods tested:
         - L{gbp.deb.changelog.ChangeLog.__init__}
         - L{gbp.deb.changelog.ChangeLog._parse}
         - L{gbp.deb.changelog.ChangeLog.add_entry}
         - L{gbp.deb.changelog.ChangeLog.spawn_dch}

    >>> import os
    >>> import tempfile
    >>> import shutil
    >>> import gbp.deb.changelog
    >>> olddir = os.path.abspath(os.path.curdir)
    >>> testdir = tempfile.mkdtemp(prefix='gbp-test-changelog-')
    >>> testdebdir = os.path.join(testdir, 'debian')
    >>> testclname = os.path.join(testdebdir, "changelog")
    >>> os.mkdir(testdebdir)
    >>> clh = open(os.path.join(testdebdir, "changelog"), "w")
    >>> clh.write(cl_debian)
    >>> clh.close()
    >>> os.chdir(testdir)
    >>> os.path.abspath(os.path.curdir) == testdir
    True
    >>> cl = gbp.deb.changelog.ChangeLog(filename=testclname)
    >>> cl.add_section(msg=["Test add section"], distribution=None, author="Debian Maintainer", email="maint@debian.org")
    >>> cl.add_entry(msg=["Test add entry"], author="Debian Maintainer", email="maint@debian.org")
    >>> cl = gbp.deb.changelog.ChangeLog(filename=testclname)
    >>> cl.version
    '0.5.33'
    >>> cl.debian_version
    '0.5.33'
    >>> cl['Distribution'] in ['UNRELEASED', 'unstable']
    True
    >>> 'Test add entry' in cl['Changes']
    True
    >>> os.chdir(olddir)
    >>> os.path.abspath(os.path.curdir) == olddir
    True
    >>> shutil.rmtree(testdir, ignore_errors=True)
    """