Mercurial > treepkg
view test/test_builder.py @ 120:007d7f2aa184
Extend/Modify FileTestMixin.create_files:
- Make it possible to specify the permissions of the files
- Remove the file hierarchy if it already exists
- Create the base directory and its parents if it doesn't exist
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Wed, 21 May 2008 16:46:16 +0000 |
parents | 92116333ef77 |
children | 890bb70920d6 |
line wrap: on
line source
# Copyright (C) 2007, 2008 by Intevation GmbH # Authors: # Bernhard Herzog <bh@intevation.de> # # This program is free software under the GPL (>=v2) # Read the file COPYING coming with the software for details. """Tests for treepkg.builder""" import sys import os import unittest from treepkg.builder import PBuilder from filesupport import FileTestMixin # helper program to dump the command line arguments into a file so that # test cases can check them. dump_command_line_py = """ import sys open(sys.argv[1], 'w').write(repr(sys.argv[2:])) """ class TestPBuilder(unittest.TestCase, FileTestMixin): def setUp(self): self.dump_command_line = self.create_temp_file("dump_command_line.py", dump_command_line_py) self.command_line_file = self.temp_file_name("command_line") self.root_command = [sys.executable, self.dump_command_line, self.command_line_file] def check_command_line(self, args): self.checkFileContents(self.command_line_file, repr(args)) def test_build(self): """Tests the PBuilder.build method. The test checks whether the build method creates the binary_dir and then checks the arguments with which the root command is called. The test is a little too strict because it expects a specific order of the arguments even though the order of some of the arguments doesn't matter. A more thorough test of the build method is implicity done by the packager tests. """ binary_dir_name = self.temp_file_name("binary") if os.path.exists(binary_dir_name): os.rmdir(binary_dir_name) # sanity check: the binary directory must not exist yet. self.failIf(os.path.exists(binary_dir_name)) builder = PBuilder("my_pbuilderrc", self.root_command) builder.build("my_dsc_file", binary_dir_name, "the_logfile") 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)) def test_run_script(self): builder = PBuilder("my_pbuilderrc", self.root_command) builder.run_script("my_script", logfile="the_logfile") self.check_command_line(['/usr/sbin/pbuilder', 'execute', '--configfile', 'my_pbuilderrc', '--logfile', 'the_logfile', 'my_script']) def test_run_script_with_bindmounts(self): builder = PBuilder("my_pbuilderrc", self.root_command) builder.run_script("my_script", logfile="the_logfile", bindmounts=("/home/builder/foo", "/home/builder/treepkg")) self.check_command_line(['/usr/sbin/pbuilder', 'execute', '--configfile', 'my_pbuilderrc', '--logfile', 'the_logfile', '--bindmounts', '/home/builder/foo', '--bindmounts', '/home/builder/treepkg', 'my_script'])