Mercurial > treepkg
comparison test/test_builder.py @ 121:890bb70920d6
Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
installation of extra packages that should be available in the pbuilder
chroot. Also add corresponding tests.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Wed, 21 May 2008 16:47:34 +0000 |
parents | 92116333ef77 |
children | 6e34fc4ebe39 |
comparison
equal
deleted
inserted
replaced
120:007d7f2aa184 | 121:890bb70920d6 |
---|---|
10 import sys | 10 import sys |
11 import os | 11 import os |
12 import unittest | 12 import unittest |
13 | 13 |
14 from treepkg.builder import PBuilder | 14 from treepkg.builder import PBuilder |
15 from treepkg.run import call | |
15 | 16 |
16 from filesupport import FileTestMixin | 17 from filesupport import FileTestMixin |
17 | 18 |
18 # helper program to dump the command line arguments into a file so that | 19 # helper program to dump the command line arguments into a file so that |
19 # test cases can check them. | 20 # test cases can check them. |
20 dump_command_line_py = """ | 21 dump_command_line_py = """ |
21 import sys | 22 import sys |
22 open(sys.argv[1], 'w').write(repr(sys.argv[2:])) | 23 open(sys.argv[1], 'w').write(repr(sys.argv[2:])) |
23 """ | 24 """ |
24 | 25 |
25 | 26 class PBuilderTests(unittest.TestCase, FileTestMixin): |
26 class TestPBuilder(unittest.TestCase, FileTestMixin): | |
27 | 27 |
28 def setUp(self): | 28 def setUp(self): |
29 self.dump_command_line = self.create_temp_file("dump_command_line.py", | 29 self.dump_command_line = self.create_temp_file("dump_command_line.py", |
30 dump_command_line_py) | 30 dump_command_line_py) |
31 self.command_line_file = self.temp_file_name("command_line") | 31 self.command_line_file = self.temp_file_name("command_line") |
32 self.root_command = [sys.executable, self.dump_command_line, | 32 self.root_command = [sys.executable, self.dump_command_line, |
33 self.command_line_file] | 33 self.command_line_file] |
34 | 34 |
35 def check_command_line(self, args): | 35 def check_command_line(self, args): |
36 self.checkFileContents(self.command_line_file, repr(args)) | 36 self.checkFileContents(self.command_line_file, repr(args)) |
37 | |
38 | |
39 class TestPBuilder(PBuilderTests): | |
37 | 40 |
38 def test_build(self): | 41 def test_build(self): |
39 """Tests the PBuilder.build method. | 42 """Tests the PBuilder.build method. |
40 The test checks whether the build method creates the binary_dir | 43 The test checks whether the build method creates the binary_dir |
41 and then checks the arguments with which the root command is | 44 and then checks the arguments with which the root command is |
78 '--configfile', 'my_pbuilderrc', | 81 '--configfile', 'my_pbuilderrc', |
79 '--logfile', 'the_logfile', | 82 '--logfile', 'the_logfile', |
80 '--bindmounts', '/home/builder/foo', | 83 '--bindmounts', '/home/builder/foo', |
81 '--bindmounts', '/home/builder/treepkg', | 84 '--bindmounts', '/home/builder/treepkg', |
82 'my_script']) | 85 'my_script']) |
86 | |
87 | |
88 class TestPBuilderWithBinaryPackage(PBuilderTests): | |
89 | |
90 minimal_package = [ | |
91 ("debian", | |
92 [("control", """\ | |
93 Source: minimal | |
94 Section: utils | |
95 Priority: optional | |
96 Maintainer: Bernhard Herzog <bh@intevation.de> | |
97 Standards-Version: 3.7.2.2 | |
98 Build-Depends: debhelper | |
99 | |
100 Package: minimal | |
101 Architecture: any | |
102 Depends: ${shlibs:Depends} | |
103 Description: Minimal package for test purposes | |
104 """), | |
105 ("rules", 0755, """\ | |
106 #!/usr/bin/make -f | |
107 | |
108 build: build-stamp | |
109 build-stamp: | |
110 dh_testdir | |
111 touch build-stamp | |
112 | |
113 clean: | |
114 dh_testdir | |
115 dh_testroot | |
116 rm -f build-stamp | |
117 dh_clean | |
118 | |
119 # Build architecture-dependent files here. | |
120 binary-arch: | |
121 dh_testdir | |
122 dh_testroot | |
123 dh_installdocs README | |
124 dh_installchangelogs | |
125 dh_fixperms | |
126 dh_installdeb | |
127 dh_gencontrol | |
128 dh_md5sums | |
129 dh_builddeb | |
130 | |
131 binary: binary-arch | |
132 .PHONY: build build-stamp clean binary-arch binary | |
133 """), | |
134 ("changelog", """\ | |
135 minimal (1.0-1) unstable; urgency=low | |
136 | |
137 * Newly packaged | |
138 | |
139 -- Bernhard Herzog <bh@intevation.de> Wed, 21 May 2008 16:10:29 +0200 | |
140 """)]), | |
141 ("README", """\ | |
142 This is a minimal debian package for test purposes | |
143 """), | |
144 ] | |
145 | |
146 pbuilder_files = [("pbuilderrc", ""), | |
147 ("extra-pkg", [])] | |
148 | |
149 def setUp(self): | |
150 PBuilderTests.setUp(self) | |
151 self.temp_base_dir = self.create_temp_dir(self.id()) | |
152 self.minimal_packge_dir = os.path.join(self.temp_base_dir, | |
153 "minimal-1.0") | |
154 self.create_files(self.minimal_packge_dir, self.minimal_package) | |
155 call(["dpkg-buildpackage", "-rfakeroot", "-b", "-uc"], | |
156 cwd=self.minimal_packge_dir, suppress_output=True) | |
157 self.minimal_package_deb = os.path.join(self.temp_base_dir, | |
158 "minimal_1.0-1_i386.deb") | |
159 self.pbuilder_basedir = os.path.join(self.temp_base_dir, "pbuilder") | |
160 self.create_files(self.pbuilder_basedir, self.pbuilder_files) | |
161 self.extra_pkg_dir = os.path.join(self.pbuilder_basedir, "extra-pkg") | |
162 self.pbuilderrc = os.path.join(self.pbuilder_basedir, "pbuilderrc") | |
163 | |
164 def test_add_binaries_to_extra_pkg(self): | |
165 """Tests the PBuilder.add_binaries_to_extra_pkg method""" | |
166 builder = PBuilder(self.pbuilderrc, self.root_command) | |
167 # sanity check: the extra-pkg directory should be empty now | |
168 self.assertEquals(os.listdir(self.extra_pkg_dir), []) | |
169 | |
170 builder.add_binaries_to_extra_pkg([self.minimal_package_deb]) | |
171 | |
172 self.assertEquals(sorted(os.listdir(self.extra_pkg_dir)), | |
173 ["Packages", "minimal_1.0-1_i386.deb"]) | |
174 self.check_command_line(['/usr/sbin/pbuilder', 'update', | |
175 '--configfile', self.pbuilderrc]) |