~ubuntu-branches/debian/sid/bzr-builddeb/sid

« back to all changes in this revision

Viewing changes to tests/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij, Jelmer Vernooij, Jonathan Riddell, Scott Kitterman
  • Date: 2011-07-15 12:15:22 UTC
  • Revision ID: james.westby@ubuntu.com-20110715121522-avtc0uc3uuzcg7zn
Tags: 2.7.5
[ Jelmer Vernooij ]
* New 'bzr dep3-patch' subcommand that can generate DEP-3 compliant
  patches. LP: #460576

[ Jonathan Riddell ]
* Use new set_commit_message() hook in bzr to set the commit
  message from debian/changelog and set fixed bugs in tags. LP: #707274

[ Jelmer Vernooij ]
* Add dependency on devscripts >= 2.10.59, required now that 'dch --
  package' is used. LP: #783122
* Fix support for native packages with dashes in their version in
  sources.list. LP: #796853
* Fix deprecation warnings for TestCase.failUnlessExists and
  TestCase.failIfExists in bzr 2.4.

[ Scott Kitterman ]
* Delete debian/bzr-builddeb.dirs so the long obsolete and empty
  /usr/lib/python2.4/site-packages/bzrlib/plugins/bzr-builddeb/ is no
  longer created. Closes: #631564

[ Jelmer Vernooij ]
* Add support for xz and lzma tarballs. LP: #553668
* When importing upstream component tarballs, don't repack bz2/lzma
  tarballs to gz if the package is in v3 source format. LP: #810531

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import tarfile
24
24
import zipfile
25
25
 
26
 
from copy import deepcopy
27
26
import doctest
28
27
import os
29
 
from unittest import TestSuite
 
28
 
 
29
from bzrlib import tests
30
30
 
31
31
try:
32
32
    from debian.changelog import Version, Changelog
34
34
    # Prior to 0.1.15 the debian module was called debian_bundle
35
35
    from debian_bundle.changelog import Version, Changelog
36
36
 
37
 
from bzrlib.tests import TestUtil, multiply_tests, TestCaseWithTransport
 
37
from bzrlib.tests import TestUtil, multiply_tests, ModuleAvailableFeature
38
38
 
39
39
 
40
40
def make_new_upstream_dir(source, dest):
82
82
    shutil.rmtree(source)
83
83
 
84
84
 
85
 
tarball_functions = [('dir', make_new_upstream_dir, '../package-0.2'),
86
 
                     ('.tar.gz', make_new_upstream_tarball,
87
 
                      '../package-0.2.tar.gz'),
88
 
                     ('.tar.bz2', make_new_upstream_tarball_bz2,
89
 
                      '../package-0.2.tar.bz2'),
90
 
                     ('.zip', make_new_upstream_tarball_zip,
91
 
                      '../package-0.2.zip'),
92
 
                     ('.tar', make_new_upstream_tarball_bare,
93
 
                      '../package-0.2.tar'),
94
 
                     ]
95
 
 
96
 
 
97
 
class RepackTarballAdaptor(object):
98
 
 
99
 
    def adapt(self, test):
100
 
        result = TestSuite()
101
 
        for (name, function, source) in tarball_functions:
102
 
            new_test = deepcopy(test)
103
 
            source = os.path.basename(source)
104
 
            new_test.build_tarball = function(source)
105
 
            new_test.old_tarball = source
106
 
            def make_new_id():
107
 
                new_id = '%s(%s)' % (test.id(), name)
108
 
                return lambda: new_id
109
 
            new_test.id = make_new_id()
110
 
            result.addTest(new_test)
111
 
        return result
 
85
def make_new_upstream_tarball_xz(source, dest):
 
86
    import lzma
 
87
    f = lzma.LZMAFile(dest, 'w')
 
88
    try:
 
89
        tar = tarfile.open(None, 'w', f)
 
90
        try:
 
91
            tar.add(source)
 
92
        finally:
 
93
            tar.close()
 
94
    finally:
 
95
        f.close()
 
96
    shutil.rmtree(source)
 
97
 
 
98
def make_new_upstream_tarball_lzma(source, dest):
 
99
    import lzma
 
100
    f = lzma.LZMAFile(dest, 'w', options={'format': 'alone'})
 
101
    try:
 
102
        tar = tarfile.open(None, 'w', f)
 
103
        try:
 
104
            tar.add(source)
 
105
        finally:
 
106
            tar.close()
 
107
    finally:
 
108
        f.close()
 
109
    shutil.rmtree(source)
112
110
 
113
111
 
114
112
def load_tests(standard_tests, module, loader):
119
117
            'test_bzrtools_import',
120
118
            'test_commit_message',
121
119
            'test_config',
 
120
            'test_dep3',
122
121
            'test_dh_make',
123
122
            'test_hooks',
124
123
            'test_import_dsc',
148
147
                              old_tarball='../package-0.2.tar.gz')),
149
148
                 ('.tar.bz2', dict(build_tarball=make_new_upstream_tarball_bz2,
150
149
                              old_tarball='../package-0.2.tar.bz2')),
 
150
                 ('.tar.xz', dict(build_tarball=make_new_upstream_tarball_xz,
 
151
                              old_tarball='../package-0.2.tar.xz',
 
152
                              _test_needs_features=[LzmaFeature])),
 
153
                 ('.tar.lzma', dict(build_tarball=make_new_upstream_tarball_lzma,
 
154
                              old_tarball='../package-0.2.tar.lzma',
 
155
                              _test_needs_features=[LzmaFeature])),
151
156
                 ('.zip', dict(build_tarball=make_new_upstream_tarball_zip,
152
157
                              old_tarball='../package-0.2.zip')),
153
158
                 ('.tar', dict(build_tarball=make_new_upstream_tarball_bare,
157
162
    return suite
158
163
 
159
164
 
 
165
class TestCaseWithTransport(tests.TestCaseWithTransport):
 
166
 
 
167
    if not getattr(tests.TestCaseWithTransport, "assertPathDoesNotExist", None):
 
168
        # Compatibility with bzr < 2.4
 
169
        def assertPathDoesNotExist(self, path):
 
170
            self.failIfExists(path)
 
171
 
 
172
        def assertPathExists(self, path):
 
173
            self.failUnlessExists(path)
 
174
 
 
175
 
 
176
class TestCaseInTempDir(tests.TestCaseInTempDir):
 
177
 
 
178
    if not getattr(tests.TestCaseInTempDir, "assertPathDoesNotExist", None):
 
179
        # Compatibility with bzr < 2.4
 
180
        def assertPathDoesNotExist(self, path):
 
181
            self.failIfExists(path)
 
182
 
 
183
        def assertPathExists(self, path):
 
184
            self.failUnlessExists(path)
 
185
 
 
186
 
160
187
class BuilddebTestCase(TestCaseWithTransport):
161
188
 
162
189
    package_name = 'test'
238
265
    >>> builder.dsc_name()
239
266
    """
240
267
 
241
 
    def __init__(self, name, version, native=False, version3=False):
 
268
    def __init__(self, name, version, native=False, version3=False,
 
269
            multiple_upstream_tarballs=None):
 
270
        """
 
271
        :param name: Package name
 
272
        :param version: Package version
 
273
        :param native: Whether to build a native source package
 
274
        :param version3: Whether to build a version 3.0 source package
 
275
        :param multiple_upstream_tarballs: A list of each top-level directory
 
276
            within the upstream tree which is to be packed as a source format
 
277
            3.0 (quilt) additional upstream tarball
 
278
        """
242
279
        self.upstream_files = {}
243
280
        self.upstream_symlinks = {}
244
281
        self.debian_files = {}
245
282
        self.name = name
246
283
        self.native = native
247
284
        self.version3 = version3
 
285
        self.multiple_upstream_tarballs = multiple_upstream_tarballs
 
286
        if multiple_upstream_tarballs and not (version3 and not native):
 
287
            raise AssertionError("Multiple upstream tarballs are only "
 
288
                    "possible with 3.0 (quilt) format")
248
289
        self._cl = Changelog()
249
290
        self.new_version(version)
250
291
 
355
396
                cmd = ["dpkg-source", "-sn", "-b", basedir]
356
397
        else:
357
398
            if not self.native:
 
399
                if self.multiple_upstream_tarballs:
 
400
                    for part in self.multiple_upstream_tarballs:
 
401
                        tar_path = "%s_%s.orig-%s.tar.%s" % (self.name,
 
402
                                self._cl.version.upstream_version,
 
403
                                part, tar_format)
 
404
                        if os.path.exists(tar_path):
 
405
                            os.unlink(tar_path)
 
406
                        tar = tarfile.open(tar_path, 'w:%s' % tar_format)
 
407
                        part_basedir = os.path.join(basedir, part)
 
408
                        try:
 
409
                            tar.add(part_basedir, arcname=part)
 
410
                        finally:
 
411
                            tar.close()
 
412
                        shutil.rmtree(part_basedir)
358
413
                tar_path = "%s_%s.orig.tar.%s" % (self.name,
359
414
                        self._cl.version.upstream_version, tar_format)
360
415
                if os.path.exists(tar_path):
382
437
        assert ret == 0, "dpkg-genchanges failed, output:\n%s" % \
383
438
                (proc.stdout.read(),)
384
439
        shutil.rmtree(basedir)
 
440
 
 
441
 
 
442
LzmaFeature = ModuleAvailableFeature("lzma")