Rev 2496: Fix some display leaks in tests. in file:///v/home/vila/src/experimental/reuse.transports/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri May 25 18:47:12 BST 2007


At file:///v/home/vila/src/experimental/reuse.transports/

------------------------------------------------------------
revno: 2496
revision-id: v.ladeuil+lp at free.fr-20070525174710-y23iej03rnb2su18
parent: v.ladeuil+lp at free.fr-20070525171252-hsooebpkqtb3j6ef
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: reuse.transports
timestamp: Fri 2007-05-25 19:47:10 +0200
message:
  Fix some display leaks in tests.
  
  * bzrlib/tests/commands/test_cat.py:
  (TestCat.setUp): Redirect stdout as cat uses it directly (via
  several indirections which ending in Tree.print_file).
  
  * bzrlib/builtins.py (cmd_missing): 
  Fix some PEP8 issues. Use self.outf instead of 'print'.
modified:
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/commands/test_cat.py test_cat.py-20070525170351-vg2apsfb5j413913-1
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2007-05-15 17:40:32 +0000
+++ b/bzrlib/builtins.py	2007-05-25 17:47:10 +0000
@@ -2954,10 +2954,10 @@
     _see_also = ['merge', 'pull']
     takes_args = ['other_branch?']
     takes_options = [Option('reverse', 'Reverse the order of revisions'),
-                     Option('mine-only', 
+                     Option('mine-only',
                             'Display changes in the local branch only'),
-                     Option('theirs-only', 
-                            'Display changes in the remote branch only'), 
+                     Option('theirs-only',
+                            'Display changes in the remote branch only'),
                      'log-format',
                      'show-ids',
                      'verbose'
@@ -2966,7 +2966,8 @@
 
     @display_command
     def run(self, other_branch=None, reverse=False, mine_only=False,
-            theirs_only=False, log_format=None, long=False, short=False, line=False, 
+            theirs_only=False, log_format=None, long=False, short=False,
+            line=False,
             show_ids=False, verbose=False):
         from bzrlib.missing import find_unmerged, iter_log_data
         from bzrlib.log import log_formatter
@@ -2975,10 +2976,11 @@
         if other_branch is None:
             other_branch = parent
             if other_branch is None:
-                raise errors.BzrCommandError("No peer location known or specified.")
+                raise errors.BzrCommandError("No peer location known"
+                                             +" or specified.")
             display_url = urlutils.unescape_for_display(parent,
                                                         self.outf.encoding)
-            print "Using last location: " + display_url
+            self.outf.write("Using last location: " + display_url)
 
         remote_branch = Branch.open(other_branch)
         if remote_branch.base == local_branch.base:
@@ -2987,10 +2989,11 @@
         try:
             remote_branch.lock_read()
             try:
-                local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
-                if (log_format is None):
-                    log_format = log.log_formatter_registry.get_default(
-                        local_branch)
+                local_extra, remote_extra = find_unmerged(local_branch,
+                                                          remote_branch)
+                if log_format is None:
+                    registry = log.log_formatter_registry
+                    log_format = registry.get_default(local_branch)
                 lf = log_format(to_file=self.outf,
                                 show_ids=show_ids,
                                 show_timezone='original')
@@ -2998,8 +3001,10 @@
                     local_extra.reverse()
                     remote_extra.reverse()
                 if local_extra and not theirs_only:
-                    print "You have %d extra revision(s):" % len(local_extra)
-                    for data in iter_log_data(local_extra, local_branch.repository,
+                    self.outf.write("You have %d extra revision(s):" %
+                                    len(local_extra))
+                    for data in iter_log_data(local_extra,
+                                              local_branch.repository,
                                               verbose):
                         lf.show(*data)
                     printed_local = True
@@ -3007,14 +3012,16 @@
                     printed_local = False
                 if remote_extra and not mine_only:
                     if printed_local is True:
-                        print "\n\n"
-                    print "You are missing %d revision(s):" % len(remote_extra)
-                    for data in iter_log_data(remote_extra, remote_branch.repository, 
+                        self.outf.write("\n\n")
+                    self.outf.write("You are missing %d revision(s):" %
+                                    len(remote_extra))
+                    for data in iter_log_data(remote_extra,
+                                              remote_branch.repository,
                                               verbose):
                         lf.show(*data)
                 if not remote_extra and not local_extra:
                     status_code = 0
-                    print "Branches are up to date."
+                    self.outf.write("Branches are up to date.")
                 else:
                     status_code = 1
             finally:

=== modified file 'bzrlib/tests/commands/test_cat.py'
--- a/bzrlib/tests/commands/test_cat.py	2007-05-25 17:12:52 +0000
+++ b/bzrlib/tests/commands/test_cat.py	2007-05-25 17:47:10 +0000
@@ -14,12 +14,26 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+import sys
 
 from bzrlib.builtins import cmd_cat
+from bzrlib.tests import StringIOWrapper
 from bzrlib.tests.TransportUtil import TestCaseWithConnectionHookedTransport
 
 class TestCat(TestCaseWithConnectionHookedTransport):
 
+    def setUp(self):
+        super(TestCat, self).setUp()
+
+        def restore_stdout():
+            sys.stdout = self._stdout_orig
+
+        # Redirect sys.stdout as this is what cat uses
+        self.outf = StringIOWrapper()
+        self._stdout_orig = sys.stdout
+        sys.stdout = self.outf
+        self.addCleanup(restore_stdout)
+
     def test_cat(self):
         wt1 = self.make_branch_and_tree('branch')
         file('branch/foo', 'wb').write('foo')
@@ -29,4 +43,5 @@
         cmd = cmd_cat()
         cmd.run(self.get_url() + '/branch/foo')
         self.assertEquals(1, len(self.connections))
+        self.assertEquals('foo', self.outf.getvalue())
 



More information about the bazaar-commits mailing list