bh@118: # Copyright (C) 2007, 2008 by Intevation GmbH bh@118: # Authors: bh@118: # Bernhard Herzog bh@118: # bh@118: # This program is free software under the GPL (>=v2) bh@118: # Read the file COPYING coming with the software for details. bh@118: bh@118: """Tests for treepkg.builder""" bh@118: bh@118: import sys bh@118: import os bh@118: import unittest bh@118: bh@118: from treepkg.builder import PBuilder bh@118: bh@118: from filesupport import FileTestMixin bh@118: bh@118: # helper program to dump the command line arguments into a file so that bh@118: # test cases can check them. bh@118: dump_command_line_py = """ bh@118: import sys bh@118: open(sys.argv[1], 'w').write(repr(sys.argv[2:])) bh@118: """ bh@118: bh@118: bh@118: class TestPBuilder(unittest.TestCase, FileTestMixin): bh@118: bh@118: def setUp(self): bh@118: self.dump_command_line = self.create_temp_file("dump_command_line.py", bh@118: dump_command_line_py) bh@118: self.command_line_file = self.temp_file_name("command_line") bh@118: self.root_command = [sys.executable, self.dump_command_line, bh@118: self.command_line_file] bh@118: bh@118: def check_command_line(self, args): bh@118: self.checkFileContents(self.command_line_file, repr(args)) bh@118: bh@118: def test_build(self): bh@118: """Tests the PBuilder.build method. bh@118: The test checks whether the build method creates the binary_dir bh@118: and then checks the arguments with which the root command is bh@118: called. The test is a little too strict because it expects a bh@118: specific order of the arguments even though the order of some of bh@118: the arguments doesn't matter. bh@118: bh@118: A more thorough test of the build method is implicity done by bh@118: the packager tests. bh@118: """ bh@118: binary_dir_name = self.temp_file_name("binary") bh@118: if os.path.exists(binary_dir_name): bh@118: os.rmdir(binary_dir_name) bh@118: # sanity check: the binary directory must not exist yet. bh@118: self.failIf(os.path.exists(binary_dir_name)) bh@118: bh@118: builder = PBuilder("my_pbuilderrc", self.root_command) bh@118: builder.build("my_dsc_file", binary_dir_name, "the_logfile") bh@118: self.check_command_line(['/usr/sbin/pbuilder', 'build', bh@118: '--configfile', 'my_pbuilderrc', bh@118: '--logfile', 'the_logfile', bh@118: '--buildresult', binary_dir_name, bh@118: 'my_dsc_file']) bh@118: self.failUnless(os.path.isdir(binary_dir_name)) bh@119: bh@119: def test_run_script(self): bh@119: builder = PBuilder("my_pbuilderrc", self.root_command) bh@119: builder.run_script("my_script", logfile="the_logfile") bh@119: self.check_command_line(['/usr/sbin/pbuilder', 'execute', bh@119: '--configfile', 'my_pbuilderrc', bh@119: '--logfile', 'the_logfile', bh@119: 'my_script']) bh@119: bh@119: def test_run_script_with_bindmounts(self): bh@119: builder = PBuilder("my_pbuilderrc", self.root_command) bh@119: builder.run_script("my_script", logfile="the_logfile", bh@119: bindmounts=("/home/builder/foo", bh@119: "/home/builder/treepkg")) bh@119: self.check_command_line(['/usr/sbin/pbuilder', 'execute', bh@119: '--configfile', 'my_pbuilderrc', bh@119: '--logfile', 'the_logfile', bh@119: '--bindmounts', '/home/builder/foo', bh@119: '--bindmounts', '/home/builder/treepkg', bh@119: 'my_script'])