Mercurial > treepkg
comparison 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 |
comparison
equal
deleted
inserted
replaced
125:34e08d52956e | 126:68d829cac3ff |
---|---|
15 from treepkg.run import call | 15 from treepkg.run import call |
16 | 16 |
17 from filesupport import FileTestMixin | 17 from filesupport import FileTestMixin |
18 | 18 |
19 # helper program to dump the command line arguments into a file so that | 19 # helper program to dump the command line arguments into a file so that |
20 # test cases can check them. | 20 # test cases can check them. Also if the environment variable |
21 # TREEPKG_TEST is set, create the file named by it. | |
21 dump_command_line_py = """ | 22 dump_command_line_py = """ |
22 import sys | 23 import sys, os |
23 open(sys.argv[1], 'w').write(repr(sys.argv[2:])) | 24 open(sys.argv[1], 'w').write(repr(sys.argv[2:])) |
25 value = os.environ.get('TREEPKG_TEST') | |
26 if value: | |
27 open(value, 'w').close() | |
24 """ | 28 """ |
25 | 29 |
26 class PBuilderTests(unittest.TestCase, FileTestMixin): | 30 class PBuilderTests(unittest.TestCase, FileTestMixin): |
27 | 31 |
28 def setUp(self): | 32 def setUp(self): |
102 '--extrapackages', "texinfo", | 106 '--extrapackages', "texinfo", |
103 '--logfile', 'the_logfile', | 107 '--logfile', 'the_logfile', |
104 '--buildresult', binary_dir_name, | 108 '--buildresult', binary_dir_name, |
105 'my_dsc_file']) | 109 'my_dsc_file']) |
106 self.failUnless(os.path.isdir(binary_dir_name)) | 110 self.failUnless(os.path.isdir(binary_dir_name)) |
111 | |
112 def test_build_with_extra_env(self): | |
113 """Tests the PBuilder.build method with the extra_env parameter""" | |
114 binary_dir_name = self.temp_file_name("binary") | |
115 if os.path.exists(binary_dir_name): | |
116 os.rmdir(binary_dir_name) | |
117 env_test_file = self.temp_file_name(self.id() + "_envtest", remove=True) | |
118 # sanity check: the binary directory must not exist yet. | |
119 self.failIf(os.path.exists(binary_dir_name)) | |
120 # sanity check: the environment variable TREEPKG_TEST must not | |
121 # be set yet | |
122 self.failIf("TREEPKG_TEST" in os.environ) | |
123 | |
124 builder = PBuilder("my_pbuilderrc", self.root_command) | |
125 builder.build("my_dsc_file", binary_dir_name, "the_logfile", | |
126 extra_env=dict(TREEPKG_TEST=env_test_file)) | |
127 self.check_command_line(['/usr/sbin/pbuilder', 'build', | |
128 '--configfile', 'my_pbuilderrc', | |
129 '--logfile', 'the_logfile', | |
130 '--buildresult', binary_dir_name, | |
131 'my_dsc_file']) | |
132 self.failUnless(os.path.isdir(binary_dir_name)) | |
133 self.failUnless(os.path.exists(env_test_file)) | |
107 | 134 |
108 def test_run_script(self): | 135 def test_run_script(self): |
109 builder = PBuilder("my_pbuilderrc", self.root_command) | 136 builder = PBuilder("my_pbuilderrc", self.root_command) |
110 builder.run_script("my_script", logfile="the_logfile") | 137 builder.run_script("my_script", logfile="the_logfile") |
111 self.check_command_line(['/usr/sbin/pbuilder', 'execute', | 138 self.check_command_line(['/usr/sbin/pbuilder', 'execute', |