aboutsummaryrefslogtreecommitdiff
path: root/tests/02_import.py
blob: d31533f0882f8af78687dc84c45c3a7b4e63de6c (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
# vim: set fileencoding=utf-8 :

import glob
import os
import shutil
import tarfile
import tempfile

import gbp.deb

class TestUnpack:
    """Make sure we unpack gzip and bzip2 archives correctly"""
    def _createArchive(self, comp):
        archive = "archive"
        name = "%s_0.1.tar.%s" % (archive, comp)
        t = tarfile.open(name= name, mode='w:%s' % comp)
        for f in glob.glob(os.path.join(self.top, "*.py")):
            t.add(os.path.join(self.top,f),
                  os.path.join("%s-%s" % (archive, comp),
                               os.path.basename(f)))
        t.close()
        return name

    def setUp(self):
        self.dir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__, dir='.')
        self.top = os.path.abspath(os.curdir)
        os.chdir(self.dir)
        self.archives = {}
        for ext in [ "gz", "bz2" ]:
            self.archives[ext] = self._createArchive(ext)

    def tearDown(self):
        os.chdir(self.top)
        if not os.getenv("GBP_TESTS_NOCLEAN"):
            shutil.rmtree(self.dir)

    def testUnpack(self):
        for (comp, archive) in self.archives.iteritems():
            gbp.deb.unpack_orig(archive, ".", [])

# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: