Mercurial > treepkg
diff test/test_builder.py @ 118:9d59ed0e3116
Add test/test_builder.py with tests for treepkg.builder
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Tue, 20 May 2008 18:47:16 +0000 |
parents | |
children | 92116333ef77 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test_builder.py Tue May 20 18:47:16 2008 +0000 @@ -0,0 +1,62 @@ +# 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))