diff test/test_builder.py @ 121:890bb70920d6

Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic installation of extra packages that should be available in the pbuilder chroot. Also add corresponding tests.
author Bernhard Herzog <bh@intevation.de>
date Wed, 21 May 2008 16:47:34 +0000
parents 92116333ef77
children 6e34fc4ebe39
line wrap: on
line diff
--- a/test/test_builder.py	Wed May 21 16:46:16 2008 +0000
+++ b/test/test_builder.py	Wed May 21 16:47:34 2008 +0000
@@ -12,6 +12,7 @@
 import unittest
 
 from treepkg.builder import PBuilder
+from treepkg.run import call
 
 from filesupport import FileTestMixin
 
@@ -22,8 +23,7 @@
 open(sys.argv[1], 'w').write(repr(sys.argv[2:]))
 """
 
-
-class TestPBuilder(unittest.TestCase, FileTestMixin):
+class PBuilderTests(unittest.TestCase, FileTestMixin):
 
     def setUp(self):
         self.dump_command_line = self.create_temp_file("dump_command_line.py",
@@ -35,6 +35,9 @@
     def check_command_line(self, args):
         self.checkFileContents(self.command_line_file, repr(args))
 
+
+class TestPBuilder(PBuilderTests):
+
     def test_build(self):
         """Tests the PBuilder.build method.
         The test checks whether the build method creates the binary_dir
@@ -80,3 +83,93 @@
                                  '--bindmounts', '/home/builder/foo',
                                  '--bindmounts', '/home/builder/treepkg',
                                  'my_script'])
+
+
+class TestPBuilderWithBinaryPackage(PBuilderTests):
+
+    minimal_package = [
+        ("debian",
+         [("control", """\
+Source: minimal
+Section: utils
+Priority: optional
+Maintainer: Bernhard Herzog <bh@intevation.de>
+Standards-Version: 3.7.2.2
+Build-Depends: debhelper
+
+Package: minimal
+Architecture: any
+Depends: ${shlibs:Depends}
+Description: Minimal package for test purposes
+"""),
+          ("rules", 0755, """\
+#!/usr/bin/make -f
+
+build: build-stamp
+build-stamp:
+	dh_testdir
+	touch build-stamp
+
+clean:
+	dh_testdir
+	dh_testroot
+	rm -f build-stamp
+	dh_clean
+
+# Build architecture-dependent files here.
+binary-arch:
+	dh_testdir
+	dh_testroot
+	dh_installdocs README
+	dh_installchangelogs
+	dh_fixperms
+	dh_installdeb
+	dh_gencontrol
+	dh_md5sums
+	dh_builddeb
+
+binary: binary-arch
+.PHONY: build build-stamp clean binary-arch binary
+"""),
+          ("changelog", """\
+minimal (1.0-1) unstable; urgency=low
+
+  * Newly packaged
+
+ -- Bernhard Herzog <bh@intevation.de>  Wed, 21 May 2008 16:10:29 +0200
+""")]),
+        ("README", """\
+This is a minimal debian package for test purposes
+"""),
+        ]
+
+    pbuilder_files = [("pbuilderrc", ""),
+                      ("extra-pkg", [])]
+
+    def setUp(self):
+        PBuilderTests.setUp(self)
+        self.temp_base_dir = self.create_temp_dir(self.id())
+        self.minimal_packge_dir = os.path.join(self.temp_base_dir,
+                                               "minimal-1.0")
+        self.create_files(self.minimal_packge_dir, self.minimal_package)
+        call(["dpkg-buildpackage", "-rfakeroot", "-b", "-uc"],
+             cwd=self.minimal_packge_dir, suppress_output=True)
+        self.minimal_package_deb = os.path.join(self.temp_base_dir,
+                                                "minimal_1.0-1_i386.deb")
+        self.pbuilder_basedir = os.path.join(self.temp_base_dir, "pbuilder")
+        self.create_files(self.pbuilder_basedir, self.pbuilder_files)
+        self.extra_pkg_dir = os.path.join(self.pbuilder_basedir, "extra-pkg")
+        self.pbuilderrc = os.path.join(self.pbuilder_basedir, "pbuilderrc")
+
+    def test_add_binaries_to_extra_pkg(self):
+        """Tests the PBuilder.add_binaries_to_extra_pkg method"""
+        builder = PBuilder(self.pbuilderrc, self.root_command)
+        # sanity check: the extra-pkg directory should be empty now
+        self.assertEquals(os.listdir(self.extra_pkg_dir), [])
+
+        builder.add_binaries_to_extra_pkg([self.minimal_package_deb])
+
+        self.assertEquals(sorted(os.listdir(self.extra_pkg_dir)),
+                          ["Packages", "minimal_1.0-1_i386.deb"])
+        self.check_command_line(['/usr/sbin/pbuilder', 'update',
+                                 '--configfile', self.pbuilderrc])
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)