# HG changeset patch # User Bernhard Herzog # Date 1211309236 0 # Node ID 9d59ed0e311620aea94442b2d63d4ab8acb1fe7e # Parent 4bb029560721fcd90217b9bc9bbc269d670254bf Add test/test_builder.py with tests for treepkg.builder diff -r 4bb029560721 -r 9d59ed0e3116 test/test_builder.py --- /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 +# +# 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))