Merge lp:~jml/launchpad/dont-print-in-tests into lp:launchpad

Proposed by Jonathan Lange
Status: Merged
Merged at revision: 12154
Proposed branch: lp:~jml/launchpad/dont-print-in-tests
Merge into: lp:launchpad
Diff against target: 358 lines (+60/-31)
12 files modified
lib/canonical/buildd/pottery/generate_translation_templates.py (+8/-4)
lib/canonical/buildd/tests/test_generate_translation_templates.py (+8/-5)
lib/canonical/librarian/smoketest.py (+10/-7)
lib/canonical/librarian/tests/test_smoketest.py (+8/-4)
lib/canonical/testing/tests/test_parallel.py (+2/-3)
lib/lp/bugs/browser/tests/test_bugtask.py (+0/-1)
lib/lp/bugs/doc/checkwatches-cli-switches.txt (+5/-1)
lib/lp/codehosting/codeimport/tests/test_worker.py (+5/-1)
lib/lp/soyuz/doc/queuebuilder.txt (+2/-2)
lib/lp/soyuz/scripts/buildd.py (+0/-2)
lib/lp/testing/__init__.py (+9/-0)
lib/lp_sitecustomize.py (+3/-1)
To merge this branch: bzr merge lp:~jml/launchpad/dont-print-in-tests
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) code Approve
Review via email: mp+44672@code.launchpad.net

Commit message

[r=jelmer][ui=none][no-qa] Fix some tests to not print stuff

Description of the change

This branch fixes a bunch of tests to not print stuff to stdout / stderr during the test run.

It doesn't fix all of them, because bug #694152 makes it really hard to do so and because I have absolutely no idea what's going on with the 'lazr.smtptest' log handler.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

As discussed on IRC, r=me for this change without the call to patch().

14:59 < jelmer> jml: How hard would it be to avoid the patch() call in
                test_translationtemplatesbuildmanager.py ?
15:00 < jml> jelmer: good question.
15:00 < jml> I think I'd need to change some stuff to not do "print "
15:03 < jml> jelmer: I think I'd have to change lib/canonical/buildd/debian.py
15:03 < jml> jelmer: I really didn't want to do that
15:05 < jml> brb
15:10 < jml> back
15:55 < jelmer> re
15:58 < jelmer> jml: I think that should be doable.
15:59 < jelmer> jml: My worry is that "eating" all of the stdout output might hide some
                useful messages printed out by other bits of the code.
15:59 < jml> jelmer: ok. I'll give it a go.
16:00 < jelmer> jml: If you like, I'd be happy to +1 the changes without the patch()
                call for now?

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/buildd/pottery/generate_translation_templates.py'
2--- lib/canonical/buildd/pottery/generate_translation_templates.py 2010-05-19 10:27:26 +0000
3+++ lib/canonical/buildd/pottery/generate_translation_templates.py 2010-12-30 15:05:26 +0000
4@@ -19,7 +19,7 @@
5 class GenerateTranslationTemplates:
6 """Script to generate translation templates from a branch."""
7
8- def __init__(self, branch_spec, result_name, work_dir):
9+ def __init__(self, branch_spec, result_name, work_dir, log_file=None):
10 """Prepare to generate templates for a branch.
11
12 :param branch_spec: Either a branch URL or the path of a local
13@@ -29,17 +29,21 @@
14 :param result_name: The name of the result tarball. Should end in
15 .tar.gz.
16 :param work_dir: The directory to work in. Must exist.
17+ :param log_file: File-like object to log to. If None, defaults to
18+ stderr.
19 """
20 self.work_dir = work_dir
21 self.branch_spec = branch_spec
22 self.result_name = result_name
23- self.logger = self._setupLogger()
24+ self.logger = self._setupLogger(log_file)
25
26- def _setupLogger(self):
27+ def _setupLogger(self, log_file):
28 """Sets up and returns a logger."""
29+ if log_file is None:
30+ log_file = sys.stderr
31 logger = logging.getLogger("generate-templates")
32 logger.setLevel(logging.DEBUG)
33- ch = logging.StreamHandler()
34+ ch = logging.StreamHandler(log_file)
35 ch.setLevel(logging.DEBUG)
36 logger.addHandler(ch)
37 return logger
38
39=== modified file 'lib/canonical/buildd/tests/test_generate_translation_templates.py'
40--- lib/canonical/buildd/tests/test_generate_translation_templates.py 2010-04-28 05:40:02 +0000
41+++ lib/canonical/buildd/tests/test_generate_translation_templates.py 2010-12-30 15:05:26 +0000
42@@ -2,6 +2,7 @@
43 # GNU Affero General Public License version 3 (see the file LICENSE).
44
45 import os
46+from StringIO import StringIO
47 from unittest import TestLoader
48 import tarfile
49
50@@ -28,7 +29,8 @@
51 branch_url = 'lp://~my/translation/branch'
52
53 generator = GenerateTranslationTemplates(
54- branch_url, self.result_name, self.makeTemporaryDirectory())
55+ branch_url, self.result_name, self.makeTemporaryDirectory(),
56+ log_file=StringIO())
57 generator._checkout = FakeMethod()
58 generator._getBranch()
59
60@@ -41,7 +43,8 @@
61 branch_dir = '/home/me/branch'
62
63 generator = GenerateTranslationTemplates(
64- branch_dir, self.result_name, self.makeTemporaryDirectory())
65+ branch_dir, self.result_name, self.makeTemporaryDirectory(),
66+ log_file=StringIO())
67 generator._checkout = FakeMethod()
68 generator._getBranch()
69
70@@ -50,7 +53,7 @@
71
72 def _createBranch(self, content_map=None):
73 """Create a working branch.
74-
75+
76 :param content_map: optional dict mapping file names to file contents.
77 Each of these files with their contents will be written to the
78 branch.
79@@ -77,7 +80,7 @@
80
81 generator = GenerateTranslationTemplates(
82 branch.getInternalBzrUrl(), self.result_name,
83- self.makeTemporaryDirectory())
84+ self.makeTemporaryDirectory(), log_file=StringIO())
85 generator.branch_dir = self.makeTemporaryDirectory()
86 generator._getBranch()
87
88@@ -96,7 +99,7 @@
89 tar.close()
90
91 generator = GenerateTranslationTemplates(
92- branchdir, self.result_name, workdir)
93+ branchdir, self.result_name, workdir, log_file=StringIO())
94 generator._getBranch()
95 generator._makeTarball(potnames)
96 tar = tarfile.open(os.path.join(workdir, self.result_name), 'r|*')
97
98=== modified file 'lib/canonical/librarian/smoketest.py'
99--- lib/canonical/librarian/smoketest.py 2010-12-07 15:13:27 +0000
100+++ lib/canonical/librarian/smoketest.py 2010-12-30 15:05:26 +0000
101@@ -8,6 +8,7 @@
102
103 from cStringIO import StringIO
104 import datetime
105+import sys
106 import urllib
107
108 from zope.component import getUtility
109@@ -46,19 +47,21 @@
110 return data
111
112
113-def do_smoketest(restricted_client, regular_client):
114- print 'adding a private file to the librarian...'
115+def do_smoketest(restricted_client, regular_client, output=None):
116+ if output is None:
117+ output = sys.stdout
118+ output.write('adding a private file to the librarian...\n')
119 private_url = store_file(restricted_client)
120- print 'retrieving private file from', private_url
121+ output.write('retrieving private file from %s\n' % (private_url,))
122 if read_file(private_url) != FILE_DATA:
123- print 'ERROR: data fetched does not match data written'
124+ output.write('ERROR: data fetched does not match data written\n')
125 return 1
126
127- print 'adding a public file to the librarian...'
128+ output.write('adding a public file to the librarian...\n')
129 public_url = store_file(regular_client)
130- print 'retrieving public file from', public_url
131+ output.write('retrieving public file from %s\n' % (public_url,))
132 if read_file(public_url) != FILE_DATA:
133- print 'ERROR: data fetched does not match data written'
134+ output.write('ERROR: data fetched does not match data written\n')
135 return 1
136
137 return 0
138
139=== modified file 'lib/canonical/librarian/tests/test_smoketest.py'
140--- lib/canonical/librarian/tests/test_smoketest.py 2010-12-07 15:13:27 +0000
141+++ lib/canonical/librarian/tests/test_smoketest.py 2010-12-30 15:05:26 +0000
142@@ -79,7 +79,8 @@
143 # exit code to signal success).
144 with fake_urllib(GoodUrllib()):
145 self.assertEquals(
146- do_smoketest(self.fake_librarian, self.fake_librarian),
147+ do_smoketest(self.fake_librarian, self.fake_librarian,
148+ output=StringIO()),
149 0)
150
151 def test_bad_data(self):
152@@ -87,7 +88,8 @@
153 # (which will be used as the processes exit code to signal an error).
154 with fake_urllib(BadUrllib()):
155 self.assertEquals(
156- do_smoketest(self.fake_librarian, self.fake_librarian),
157+ do_smoketest(self.fake_librarian, self.fake_librarian,
158+ output=StringIO()),
159 1)
160
161 def test_exception(self):
162@@ -96,7 +98,8 @@
163 # code to signal an error).
164 with fake_urllib(ErrorUrllib()):
165 self.assertEquals(
166- do_smoketest(self.fake_librarian, self.fake_librarian),
167+ do_smoketest(self.fake_librarian, self.fake_librarian,
168+ output=StringIO()),
169 1)
170
171 def test_explosive_errors(self):
172@@ -106,4 +109,5 @@
173 with fake_urllib(ExplosiveUrllib(exception)):
174 self.assertRaises(
175 exception,
176- do_smoketest, self.fake_librarian, self.fake_librarian)
177+ do_smoketest, self.fake_librarian, self.fake_librarian,
178+ output=StringIO())
179
180=== modified file 'lib/canonical/testing/tests/test_parallel.py'
181--- lib/canonical/testing/tests/test_parallel.py 2010-10-26 15:47:24 +0000
182+++ lib/canonical/testing/tests/test_parallel.py 2010-12-30 15:05:26 +0000
183@@ -22,7 +22,6 @@
184 find_load_list,
185 find_tests,
186 ListTestCase,
187- main,
188 prepare_argv,
189 )
190
191@@ -103,13 +102,13 @@
192 self.assertEqual(
193 ['bin/test', '-vt', 'filter', '--list-tests', '--subunit'],
194 args['args'])
195- return {'stdin': StringIO(), 'stdout': StringIO(u"""
196+ return {'stdin': StringIO(), 'stdout': StringIO(u"""\
197 test: quux
198 successful: quux
199 test: glom
200 successful: glom
201 """)}
202- popen = self.useFixture(PopenFixture(inject_testlist))
203+ self.useFixture(PopenFixture(inject_testlist))
204 self.assertEqual(
205 ['quux', 'glom'],
206 find_tests(['bin/test', '-vt', 'filter', '--parallel']))
207
208=== modified file 'lib/lp/bugs/browser/tests/test_bugtask.py'
209--- lib/lp/bugs/browser/tests/test_bugtask.py 2010-12-20 13:44:10 +0000
210+++ lib/lp/bugs/browser/tests/test_bugtask.py 2010-12-30 15:05:26 +0000
211@@ -547,7 +547,6 @@
212 current_request=True)
213 contents = view.render()
214 help_link = find_tag_by_id(contents, 'getting-started-help')
215- print help_link
216 self.assertIs(None, help_link)
217
218
219
220=== modified file 'lib/lp/bugs/doc/checkwatches-cli-switches.txt'
221--- lib/lp/bugs/doc/checkwatches-cli-switches.txt 2010-12-22 20:55:25 +0000
222+++ lib/lp/bugs/doc/checkwatches-cli-switches.txt 2010-12-30 15:05:26 +0000
223@@ -52,8 +52,10 @@
224 ... def __init__(self, name, dbuser=None, test_args=None):
225 ... super(TestCheckWatchesCronScript, self).__init__(
226 ... name, dbuser, test_args)
227+ ... self.txn = ZopelessTransactionManager
228+ ...
229+ ... def handle_options(self):
230 ... self.logger = FakeLogger()
231- ... self.txn = ZopelessTransactionManager
232
233 >>> def run_cronscript_with_args(args):
234 ... # It may seem a bit weird to do ths rather than letting the
235@@ -70,6 +72,7 @@
236 >>> run_cronscript_with_args([
237 ... '--bug-tracker=mozilla.org', '--bug-tracker=debbugs', '-v',
238 ... '--batch-size=10'])
239+ DEBUG Enabled by DEFAULT section
240 DEBUG Using a global batch size of 10
241 DEBUG No watches to update on https://bugzilla.mozilla.org/
242 DEBUG No watches to update on http://bugs.debian.org
243@@ -101,6 +104,7 @@
244 >>> LaunchpadZopelessLayer.switchDbUser(config.checkwatches.dbuser)
245
246 >>> run_cronscript_with_args(['-vvt', 'savannah', '--reset'])
247+ DEBUG Enabled by DEFAULT section
248 INFO Resetting 5 bug watches for bug tracker 'savannah'
249 INFO Updating 5 watches on bug tracker 'savannah'
250 WARNING ExternalBugtracker for BugTrackerType 'SAVANE' is not known.
251
252=== modified file 'lib/lp/codehosting/codeimport/tests/test_worker.py'
253--- lib/lp/codehosting/codeimport/tests/test_worker.py 2010-12-20 03:21:03 +0000
254+++ lib/lp/codehosting/codeimport/tests/test_worker.py 2010-12-30 15:05:26 +0000
255@@ -27,6 +27,7 @@
256 NotBranchError,
257 )
258 from bzrlib.tests import TestCaseWithTransport
259+from bzrlib import trace
260 from bzrlib.transport import get_transport
261 from bzrlib.upgrade import upgrade
262 from bzrlib.urlutils import (
263@@ -132,7 +133,10 @@
264 """Tests for `BazaarBranchStore`."""
265
266 def setUp(self):
267- super(TestBazaarBranchStore, self).setUp()
268+ WorkerTest.setUp(self)
269+ # XXX: JonathanLange 2010-12-24 bug=694140: Avoid spurious "No
270+ # handlers for logger 'bzr'" messages.
271+ trace._bzr_logger = logging.getLogger('bzr')
272 self.temp_dir = self.makeTemporaryDirectory()
273 self.arbitrary_branch_id = 10
274
275
276=== modified file 'lib/lp/soyuz/doc/queuebuilder.txt'
277--- lib/lp/soyuz/doc/queuebuilder.txt 2010-10-18 22:24:59 +0000
278+++ lib/lp/soyuz/doc/queuebuilder.txt 2010-12-30 15:05:26 +0000
279@@ -30,8 +30,8 @@
280 user designed for this kind of access is 'fiera', see
281 test_system_documentation.py for more information.
282
283- >>> import logging
284- >>> logger = logging.getLogger()
285+ >>> from lp.services.log.logger import DevNullLogger
286+ >>> logger = DevNullLogger()
287
288 Now that we have satisfied all of the needs for QueueBuilder, let's
289 instantiate it.
290
291=== modified file 'lib/lp/soyuz/scripts/buildd.py'
292--- lib/lp/soyuz/scripts/buildd.py 2010-11-02 21:44:42 +0000
293+++ lib/lp/soyuz/scripts/buildd.py 2010-12-30 15:05:26 +0000
294@@ -8,7 +8,6 @@
295 __all__ = [
296 'QueueBuilder',
297 'RetryDepwait',
298- 'SlaveScanner',
299 ]
300
301 from zope.component import getUtility
302@@ -18,7 +17,6 @@
303 from lp.archivepublisher.debversion import Version
304 from lp.archivepublisher.utils import process_in_batches
305 from lp.buildmaster.enums import BuildStatus
306-from lp.buildmaster.interfaces.builder import IBuilderSet
307 from lp.registry.interfaces.distribution import IDistributionSet
308 from lp.registry.interfaces.series import SeriesStatus
309 from lp.services.scripts.base import (
310
311=== modified file 'lib/lp/testing/__init__.py'
312--- lib/lp/testing/__init__.py 2010-12-17 23:59:00 +0000
313+++ lib/lp/testing/__init__.py 2010-12-30 15:05:26 +0000
314@@ -57,6 +57,7 @@
315 isclass,
316 ismethod,
317 )
318+import logging
319 import os
320 from pprint import pformat
321 import re
322@@ -71,6 +72,7 @@
323 BzrDir,
324 format_registry,
325 )
326+from bzrlib import trace
327 from bzrlib.transport import get_transport
328 import fixtures
329 import pytz
330@@ -567,6 +569,13 @@
331 self.factory = LaunchpadObjectFactory()
332 self.direct_database_server = False
333 self._use_bzr_branch_called = False
334+ # XXX: JonathanLange 2010-12-24 bug=694140: Because of Launchpad's
335+ # messing with global log state (see
336+ # canonical.launchpad.scripts.logger), trace._bzr_logger does not
337+ # necessarily equal logging.getLogger('bzr'), so we have to explicitly
338+ # make it so in order to avoid "No handlers for "bzr" logger'
339+ # messages.
340+ trace._bzr_logger = logging.getLogger('bzr')
341
342 def getUserBrowser(self, url=None, user=None, password='test'):
343 """Return a Browser logged in as a fresh user, maybe opened at `url`.
344
345=== modified file 'lib/lp_sitecustomize.py'
346--- lib/lp_sitecustomize.py 2010-12-17 13:11:38 +0000
347+++ lib/lp_sitecustomize.py 2010-12-30 15:05:26 +0000
348@@ -51,7 +51,9 @@
349
350 def silence_bzr_logger():
351 """Install the NullHandler on the bzr logger to silence logs."""
352- logging.getLogger('bzr').addHandler(NullHandler())
353+ bzr_logger = logging.getLogger('bzr')
354+ bzr_logger.addHandler(NullHandler())
355+ bzr_logger.propagate = False
356
357
358 def silence_zcml_logger():