[Treepkg-commits] r51 - in trunk: test treepkg
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu May 22 20:53:15 CEST 2008
Author: bh
Date: 2008-05-22 20:53:14 +0200 (Thu, 22 May 2008)
New Revision: 51
Modified:
trunk/test/test_builder.py
trunk/treepkg/builder.py
Log:
New parameter for PBuilder.build: extra_env, a mapping with extra
environment varaibles. Also add a test case.
Modified: trunk/test/test_builder.py
===================================================================
--- trunk/test/test_builder.py 2008-05-22 18:12:30 UTC (rev 50)
+++ trunk/test/test_builder.py 2008-05-22 18:53:14 UTC (rev 51)
@@ -17,10 +17,14 @@
from filesupport import FileTestMixin
# helper program to dump the command line arguments into a file so that
-# test cases can check them.
+# test cases can check them. Also if the environment variable
+# TREEPKG_TEST is set, create the file named by it.
dump_command_line_py = """
-import sys
+import sys, os
open(sys.argv[1], 'w').write(repr(sys.argv[2:]))
+value = os.environ.get('TREEPKG_TEST')
+if value:
+ open(value, 'w').close()
"""
class PBuilderTests(unittest.TestCase, FileTestMixin):
@@ -105,6 +109,29 @@
'my_dsc_file'])
self.failUnless(os.path.isdir(binary_dir_name))
+ def test_build_with_extra_env(self):
+ """Tests the PBuilder.build method with the extra_env parameter"""
+ binary_dir_name = self.temp_file_name("binary")
+ if os.path.exists(binary_dir_name):
+ os.rmdir(binary_dir_name)
+ env_test_file = self.temp_file_name(self.id() + "_envtest", remove=True)
+ # sanity check: the binary directory must not exist yet.
+ self.failIf(os.path.exists(binary_dir_name))
+ # sanity check: the environment variable TREEPKG_TEST must not
+ # be set yet
+ self.failIf("TREEPKG_TEST" in os.environ)
+
+ builder = PBuilder("my_pbuilderrc", self.root_command)
+ builder.build("my_dsc_file", binary_dir_name, "the_logfile",
+ extra_env=dict(TREEPKG_TEST=env_test_file))
+ self.check_command_line(['/usr/sbin/pbuilder', 'build',
+ '--configfile', 'my_pbuilderrc',
+ '--logfile', 'the_logfile',
+ '--buildresult', binary_dir_name,
+ 'my_dsc_file'])
+ self.failUnless(os.path.isdir(binary_dir_name))
+ self.failUnless(os.path.exists(env_test_file))
+
def test_run_script(self):
builder = PBuilder("my_pbuilderrc", self.root_command)
builder.run_script("my_script", logfile="the_logfile")
Modified: trunk/treepkg/builder.py
===================================================================
--- trunk/treepkg/builder.py 2008-05-22 18:12:30 UTC (rev 50)
+++ trunk/treepkg/builder.py 2008-05-22 18:53:14 UTC (rev 51)
@@ -32,7 +32,7 @@
self.root_cmd = root_cmd
def build(self, dsc_file, binary_dir, logfile, bindmounts=(),
- extra_packages=()):
+ extra_packages=(), extra_env=None):
"""Build a binary packager from a source package
Parameters:
dsc_file -- name of the debian .dsc file of the source package
@@ -60,7 +60,8 @@
rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc,
logfile=logfile, bindir=binary_dir, dsc=dsc_file,
args=args),
- suppress_output=True)
+ suppress_output=True,
+ extra_env=extra_env)
# remove the source package files put into the binary directory
# by pbuilder
for filename in os.listdir(binary_dir):
More information about the Treepkg-commits
mailing list