Rev 2828: TestCase.apply_redirected no longer implicitly sends output into the test log in http://sourcefrog.net/bzr/test-cleanup

Martin Pool mbp at sourcefrog.net
Mon Sep 17 05:33:25 BST 2007


At http://sourcefrog.net/bzr/test-cleanup

------------------------------------------------------------
revno: 2828
revision-id: mbp at sourcefrog.net-20070917043324-kktpudx7xu7pn30j
parent: mbp at sourcefrog.net-20070917033315-xdp5bb3pu60e7b1o
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: test-cleanup
timestamp: Mon 2007-09-17 14:33:24 +1000
message:
  TestCase.apply_redirected no longer implicitly sends output into the test log
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
  bzrlib/tests/test_smart_add.py test_smart_add.py-20050824235919-c60dcdb0c8e999ce
  doc/developers/HACKING.txt     HACKING-20050805200004-2a5dc975d870f78c
=== modified file 'NEWS'
--- a/NEWS	2007-09-16 19:29:00 +0000
+++ b/NEWS	2007-09-17 04:33:24 +0000
@@ -57,6 +57,10 @@
 
   TESTING:
 
+   * ``TestCase.apply_redirected`` no longer implicitly logs into the test 
+     log file; parameters must be given for stdio and stderr.
+     (Martin Pool)
+
 
 bzr 0.91rc2 2007-09-11
 ======================

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2007-09-05 08:18:57 +0000
+++ b/bzrlib/tests/__init__.py	2007-09-17 04:33:24 +0000
@@ -1643,20 +1643,20 @@
         """Call callable with redirected std io pipes.
 
         Returns the return code."""
+        # XXX: It's not a good pattern to mix kwargs passed through to the
+        # callable with kwargs taken by this method.
         if not callable(a_callable):
             raise ValueError("a_callable must be callable.")
         if stdin is None:
             stdin = StringIO("")
         if stdout is None:
-            if getattr(self, "_log_file", None) is not None:
-                stdout = self._log_file
-            else:
-                stdout = StringIO()
+            warnings.warn("apply_redirected(stdout=None) is no longer supported",
+                stacklevel=2)
+            stdout = StringIO()
         if stderr is None:
-            if getattr(self, "_log_file", None is not None):
-                stderr = self._log_file
-            else:
-                stderr = StringIO()
+            warnings.warn("apply_redirected(stderr=None) is no longer supported",
+                stacklevel=2)
+            stderr = StringIO()
         real_stdin = sys.stdin
         real_stdout = sys.stdout
         real_stderr = sys.stderr

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2007-09-03 04:35:49 +0000
+++ b/bzrlib/tests/test_selftest.py	2007-09-17 04:33:24 +0000
@@ -1548,14 +1548,16 @@
 class TestSelftest(TestCase):
     """Tests of bzrlib.tests.selftest."""
 
-    def test_selftest_benchmark_parameter_invokes_test_suite__benchmark__(self):
+    def test_selftest_calls_factory(self):
         factory_called = []
         def factory():
             factory_called.append(True)
             return TestSuite()
         out = StringIO()
         err = StringIO()
-        self.apply_redirected(out, err, None, bzrlib.tests.selftest, 
+        self.apply_redirected(stdin=StringIO(""),
+            stdout=out, stderr=err,
+            a_callable=bzrlib.tests.selftest,
             test_suite_factory=factory)
         self.assertEqual([True], factory_called)
 

=== modified file 'bzrlib/tests/test_smart_add.py'
--- a/bzrlib/tests/test_smart_add.py	2007-07-04 08:46:22 +0000
+++ b/bzrlib/tests/test_smart_add.py	2007-09-17 04:33:24 +0000
@@ -157,8 +157,9 @@
         from bzrlib.mutabletree import _FastPath
         inv = Inventory()
         stdout = StringIO()
+        stderr = StringIO()
         action = AddAction(to_file=stdout, should_print=bool(output))
 
-        self.apply_redirected(None, stdout, None, action, inv, None,
+        self.apply_redirected(None, stdout, stderr, action, inv, None,
             _FastPath('path'), 'file')
         self.assertEqual(stdout.getvalue(), output)

=== modified file 'doc/developers/HACKING.txt'
--- a/doc/developers/HACKING.txt	2007-09-17 03:33:00 +0000
+++ b/doc/developers/HACKING.txt	2007-09-17 04:33:24 +0000
@@ -539,10 +539,6 @@
  * bzrlib trace calls are redirected into the test log for the duration
    of the tests.
 
- * apply_redirected has the special case that if you don't give stdout and
-   stderr files, the content will go into the test log.  Is this used, or
-   useful?
-
 Logging from tests serves multiple purposes:
 
  * If the test fails, the log may give useful information to the
@@ -599,6 +595,9 @@
 keep_log=True.  For these users, we can have a separate routine that
 returns just the trace output.
 
+Should the logs in fact be kept only for successful tests?  What do we
+want to keep in each case?
+
 
 Essential Domain Classes
 ########################




More information about the bazaar-commits mailing list