diff options
author | Guido Günther <agx@sigxcpu.org> | 2011-07-25 15:02:08 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2011-07-25 17:15:42 +0200 |
commit | e05e98532a662ec5d65df74cf60f63dc331897c3 (patch) | |
tree | 8496e918e98b5a7f3de51d77376628b980cc52c5 /tests/02_test_import.py | |
parent | 8d0143a7c1eb8f852ac2c95024a3cb438deb5c7f (diff) |
Add tests for UpstreamSource
* tar and zipfile unpacking
* (filtered) tar packing
Diffstat (limited to 'tests/02_test_import.py')
-rw-r--r-- | tests/02_test_import.py | 66 |
1 files changed, 55 insertions, 11 deletions
diff --git a/tests/02_test_import.py b/tests/02_test_import.py index d31533f..33628ea 100644 --- a/tests/02_test_import.py +++ b/tests/02_test_import.py @@ -10,16 +10,28 @@ 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) + archive_prefix = "archive" + + def _unpack_dir(self, compression): + return "%s-%s" % (self.archive_prefix, compression) + + def _check_files(self, files, comp): + """Check if files exist in the unpacked dir""" + for f in files: + target = os.path.join(self._unpack_dir(comp), f) + assert os.path.exists(target), "%s does not exist" % target + + def _create_archive(self, comp): + filelist = [ os.path.basename(f) for f in + glob.glob(os.path.join(self.top, "g*-*")) ] + + name = "%s_0.1.tar.%s" % (self.archive_prefix, 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))) + for f in filelist: + t.add(os.path.join(self.top, f), + os.path.join(self._unpack_dir(comp), f)) t.close() - return name + return name, filelist def setUp(self): self.dir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__, dir='.') @@ -27,15 +39,47 @@ class TestUnpack: os.chdir(self.dir) self.archives = {} for ext in [ "gz", "bz2" ]: - self.archives[ext] = self._createArchive(ext) + self.archives[ext] = self._create_archive(ext) def tearDown(self): os.chdir(self.top) if not os.getenv("GBP_TESTS_NOCLEAN"): shutil.rmtree(self.dir) - def testUnpack(self): + def test_unpack(self): + for (comp, archive) in self.archives.iteritems(): + gbp.deb.unpack_orig(archive[0], ".", []) + + def test_upstream_source_type(self): + for (comp, archive) in self.archives.iteritems(): + source = gbp.deb.UpstreamSource(archive[0]) + assert source.is_orig == True + assert source.is_dir == False + assert source.unpacked == None + source.unpack(".") + assert source.is_orig == True + assert source.is_dir == False + assert type(source.unpacked) == str + + def test_upstream_source_unpack(self): + for (comp, archive) in self.archives.iteritems(): + source = gbp.deb.UpstreamSource(archive[0]) + source.unpack(".") + self._check_files(archive[1], comp) + + def test_upstream_source_unpack_no_filter(self): + for (comp, archive) in self.archives.iteritems(): + source = gbp.deb.UpstreamSource(archive[0]) + source.unpack(".", []) + self._check_files(archive[1], comp) + + def test_upstream_source_unpack_filtered(self): + exclude = "git-buildpackage" + for (comp, archive) in self.archives.iteritems(): - gbp.deb.unpack_orig(archive, ".", []) + source = gbp.deb.UpstreamSource(archive[0]) + source.unpack(".", [exclude]) + archive[1].remove(exclude) + self._check_files(archive[1], comp) # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: |