aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/06_test_upstream_source.py
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2011-07-25 15:02:08 +0200
committerGuido Günther <agx@sigxcpu.org>2011-07-25 17:15:42 +0200
commite05e98532a662ec5d65df74cf60f63dc331897c3 (patch)
tree8496e918e98b5a7f3de51d77376628b980cc52c5 /tests/06_test_upstream_source.py
parent8d0143a7c1eb8f852ac2c95024a3cb438deb5c7f (diff)
Add tests for UpstreamSource
* tar and zipfile unpacking * (filtered) tar packing
Diffstat (limited to 'tests/06_test_upstream_source.py')
-rw-r--r--tests/06_test_upstream_source.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/06_test_upstream_source.py b/tests/06_test_upstream_source.py
new file mode 100644
index 00000000..13e0e95f
--- /dev/null
+++ b/tests/06_test_upstream_source.py
@@ -0,0 +1,86 @@
+# Test the UpstreamSource class
+
+import glob
+import os
+import shutil
+import tarfile
+import tempfile
+import unittest
+import zipfile
+
+from gbp.deb import UpstreamSource
+
+class TestDir(unittest.TestCase):
+ def test_directory(self):
+ """Upstream source is a directory"""
+ source = UpstreamSource('.')
+ self.assertEqual(source.is_orig, False)
+ self.assertEqual(source.path, '.')
+ self.assertEqual(source.unpacked, '.')
+
+
+class TestTar(unittest.TestCase):
+ def _check_tar(self, us, positive=[], negative=[]):
+ t = tarfile.open(name=us.path, mode="r:bz2")
+ for f in positive:
+ i = t.getmember(f)
+ self.assertEqual(type(i), tarfile.TarInfo)
+
+ for f in negative:
+ try:
+ t.getmember(f)
+ self.fail("Found %s in archive" % f)
+ except KeyError:
+ pass
+ t.close()
+
+ def setUp(self):
+ self.tmpdir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__, dir='.')
+
+ def tearDown(self):
+ if not os.getenv("GBP_TESTS_NOCLEAN"):
+ shutil.rmtree(self.tmpdir)
+
+ def test_pack_tar(self):
+ """Check if packing tar archives works"""
+ source = UpstreamSource(os.path.abspath("gbp/"))
+ target = os.path.join(self.tmpdir,
+ "gbp_0.1.tar.bz2")
+ repacked = source.pack(target)
+ self.assertEqual(repacked.is_orig, True)
+ self.assertEqual(repacked.is_dir, False)
+ self._check_tar(repacked, ["gbp/deb.py", "gbp/__init__.py"])
+
+ def test_pack_filtered(self):
+ """Check if filtering out files works"""
+ source = UpstreamSource(os.path.abspath("gbp/"))
+ target = os.path.join(self.tmpdir,
+ "gbp_0.1.tar.bz2")
+ repacked = source.pack(target, ["__init__.py"])
+ self.assertEqual(repacked.is_orig, True)
+ self.assertEqual(repacked.is_dir, False)
+ self._check_tar(repacked, ["gbp/deb.py"],
+ ["gbp/__init__.py"])
+
+
+class TestZip(unittest.TestCase):
+ def setUp(self):
+ self.tmpdir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__, dir='.')
+ self.zipfile = os.path.join(self.tmpdir, "gbp-0.1.zip")
+ z = zipfile.ZipFile(os.path.join(self.tmpdir, "gbp-0.1.zip"), "w")
+ for f in glob.glob("gbp/*.py"):
+ z.write(f, f, zipfile.ZIP_DEFLATED)
+ z.close()
+
+ def tearDown(self):
+ if not os.getenv("GBP_TESTS_NOCLEAN"):
+ shutil.rmtree(self.tmpdir)
+
+ def test_unpack(self):
+ source = UpstreamSource(self.zipfile)
+ self.assertEqual(source.is_orig, False)
+ self.assertEqual(source.is_dir, False)
+ self.assertEqual(source.unpacked, None)
+ source.unpack(self.tmpdir)
+ self.assertNotEqual(source.unpacked, None)
+