Mercurial > treepkg
diff test/test_builder.py @ 126:68d829cac3ff
New parameter for PBuilder.build: extra_env, a mapping with extra
environment varaibles. Also add a test case.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 22 May 2008 18:53:14 +0000 |
parents | 6e34fc4ebe39 |
children | bfcb2bbf9a52 |
line wrap: on
line diff
--- a/test/test_builder.py Thu May 22 18:12:30 2008 +0000 +++ b/test/test_builder.py Thu May 22 18:53:14 2008 +0000 @@ -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")