comparison 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
comparison
equal deleted inserted replaced
117:4bb029560721 118:9d59ed0e3116
1 # Copyright (C) 2007, 2008 by Intevation GmbH
2 # Authors:
3 # Bernhard Herzog <bh@intevation.de>
4 #
5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with the software for details.
7
8 """Tests for treepkg.builder"""
9
10 import sys
11 import os
12 import unittest
13
14 from treepkg.builder import PBuilder
15
16 from filesupport import FileTestMixin
17
18 # helper program to dump the command line arguments into a file so that
19 # test cases can check them.
20 dump_command_line_py = """
21 import sys
22 open(sys.argv[1], 'w').write(repr(sys.argv[2:]))
23 """
24
25
26 class TestPBuilder(unittest.TestCase, FileTestMixin):
27
28 def setUp(self):
29 self.dump_command_line = self.create_temp_file("dump_command_line.py",
30 dump_command_line_py)
31 self.command_line_file = self.temp_file_name("command_line")
32 self.root_command = [sys.executable, self.dump_command_line,
33 self.command_line_file]
34
35 def check_command_line(self, args):
36 self.checkFileContents(self.command_line_file, repr(args))
37
38 def test_build(self):
39 """Tests the PBuilder.build method.
40 The test checks whether the build method creates the binary_dir
41 and then checks the arguments with which the root command is
42 called. The test is a little too strict because it expects a
43 specific order of the arguments even though the order of some of
44 the arguments doesn't matter.
45
46 A more thorough test of the build method is implicity done by
47 the packager tests.
48 """
49 binary_dir_name = self.temp_file_name("binary")
50 if os.path.exists(binary_dir_name):
51 os.rmdir(binary_dir_name)
52 # sanity check: the binary directory must not exist yet.
53 self.failIf(os.path.exists(binary_dir_name))
54
55 builder = PBuilder("my_pbuilderrc", self.root_command)
56 builder.build("my_dsc_file", binary_dir_name, "the_logfile")
57 self.check_command_line(['/usr/sbin/pbuilder', 'build',
58 '--configfile', 'my_pbuilderrc',
59 '--logfile', 'the_logfile',
60 '--buildresult', binary_dir_name,
61 'my_dsc_file'])
62 self.failUnless(os.path.isdir(binary_dir_name))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)