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