comparison test/test_builder.py @ 170:bfcb2bbf9a52

Move the pbuilder initialization code from bin/initpbuilder.py to treepkg/builder.py to make it work again and add some tests.
author Bernhard Herzog <bh@intevation.de>
date Mon, 23 Jun 2008 13:21:08 +0000
parents 68d829cac3ff
children c0ea6cbb0fd2
comparison
equal deleted inserted replaced
169:261b75d7b972 170:bfcb2bbf9a52
8 """Tests for treepkg.builder""" 8 """Tests for treepkg.builder"""
9 9
10 import sys 10 import sys
11 import os 11 import os
12 import unittest 12 import unittest
13 import StringIO
13 14
14 from treepkg.builder import PBuilder 15 from treepkg.builder import PBuilder
15 from treepkg.run import call 16 from treepkg.run import call
16 17
17 from filesupport import FileTestMixin 18 from filesupport import FileTestMixin
39 def check_command_line(self, args): 40 def check_command_line(self, args):
40 self.checkFileContents(self.command_line_file, repr(args)) 41 self.checkFileContents(self.command_line_file, repr(args))
41 42
42 43
43 class TestPBuilder(PBuilderTests): 44 class TestPBuilder(PBuilderTests):
45
46 def test_init_pbuilder(self):
47 """Tests the PBuilder.init_pbuilder method."""
48 basedir = self.create_temp_dir(self.id())
49 pbuilderrc = os.path.join(basedir, "pbuilderrc")
50 builder = PBuilder(pbuilderrc, self.root_command)
51 old_stdout = sys.stdout
52 sys.stdout = captured_stdout = StringIO.StringIO()
53 try:
54 builder.init_pbuilder(distribution="etch",
55 mirrorsite="http://example.com/debian",
56 extramirrors=None)
57 finally:
58 sys.stdout = old_stdout
59
60 # check whether the necessary directories were created
61 missing = [dirname for dirname in ["base", "build", "result",
62 "aptcache", "extra-pkg"]
63 if not os.path.isdir(os.path.join(basedir, dirname))]
64 if missing:
65 self.fail("init_pbuilder did not create these directories: %s"
66 % " ".join(missing))
67
68 # check the pbuilderrc. This test is a little too strict
69 # because it checks the exact contents of the file. Instread it
70 # should normalize the contents in some way and check that.
71 pbuilderrc_contents = (
72 "# This file was automatically generated by initpbuilder.py.\n"
73 "# for the possible settings see \"man pbuilderrc\"\n"
74 "\n"
75 "BASETGZ=%(basedir)s/base/base.tgz\n"
76 "BUILDPLACE=%(basedir)s/build\n"
77 "USEPROC=yes\n"
78 "USEDEVPTS=yes\n"
79 "BUILDRESULT=%(basedir)s/result\n"
80 "DISTRIBUTION=etch\n"
81 "APTCACHE=%(basedir)s/base/aptcache\n"
82 "APTCACHEHARDLINK=yes\n"
83 "REMOVEPACKAGES=lilo\n"
84 "MIRRORSITE=\"http://example.com/debian\"\n"
85 "OTHERMIRROR=\"deb file://%(basedir)s/extra-pkg ./\"\n"
86 "BINDMOUNTS=\"%(basedir)s/extra-pkg\"\n"
87 "PKGNAME_LOGFILE=yes\n" % locals())
88 self.checkFileContents(pbuilderrc, pbuilderrc_contents)
89
90 # The Packages file is empty for now.
91 self.checkFileContents(os.path.join(basedir, "extra-pkg", "Packages"),
92 "")
93 # check the text written to stdout. This test is a little too
94 # strict because it checks the exact output.
95 self.assertEquals(captured_stdout.getvalue(),
96 "creating directory: '%(basedir_repr)s/base'\n"
97 "creating directory: '%(basedir_repr)s/build'\n"
98 "creating directory: '%(basedir_repr)s/result'\n"
99 "creating directory: '%(basedir_repr)s/aptcache'\n"
100 "creating directory: '%(basedir_repr)s/extra-pkg'\n"
101 "creating pbuilderrc: '%(basedir_repr)s/pbuilderrc'\n"
102 "turning the extra-pkg dir into a debian archive\n"
103 "running pbuilder create\n"
104 % dict(basedir_repr=repr(basedir)[1:-1]))
105
106 def test_init_pbuilder_run_twice(self):
107 """Tests whether PBuilder.init_pbuilder prints an error when run twice.
108 """
109 basedir = self.create_temp_dir(self.id())
110
111 # run it once
112 pbuilderrc = os.path.join(basedir, "pbuilderrc")
113 builder = PBuilder(pbuilderrc, self.root_command)
114 old_stdout = sys.stdout
115 sys.stdout = captured_stdout = StringIO.StringIO()
116 try:
117 builder.init_pbuilder(distribution="etch",
118 mirrorsite="http://example.com/debian",
119 extramirrors=None)
120 finally:
121 sys.stdout = old_stdout
122
123 # running it again should not modify anything in the directory
124 # (which we don't check currently), it should print an error
125 # message and exit with exit code 1.
126 old_stderr = sys.stderr
127 sys.stderr = captured_stderr = StringIO.StringIO()
128 try:
129 try:
130 builder.init_pbuilder(distribution="etch",
131 mirrorsite="http://example.com/debian",
132 extramirrors=None)
133 except SystemExit, exc:
134 self.assertEquals(exc.code, 1)
135 finally:
136 sys.stderr = old_stderr
137 self.assertEquals("pbuilderrc %r already exists.\n"
138 % os.path.join(basedir, "pbuilderrc"),
139 captured_stderr.getvalue())
140
44 141
45 def test_build(self): 142 def test_build(self):
46 """Tests the PBuilder.build method. 143 """Tests the PBuilder.build method.
47 The test checks whether the build method creates the binary_dir 144 The test checks whether the build method creates the binary_dir
48 and then checks the arguments with which the root command is 145 and then checks the arguments with which the root command is
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)