Rev 4858: Start cleaning up test_log. in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b4-test-log-cleanups

John Arbash Meinel john at arbash-meinel.com
Thu Dec 3 19:16:22 GMT 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b4-test-log-cleanups

------------------------------------------------------------
revno: 4858
revision-id: john at arbash-meinel.com-20091203191608-n1lkjhs2x22u63du
parent: pqm at pqm.ubuntu.com-20091203050805-s70sybyrsrbbs10c
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0b4-test-log-cleanups
timestamp: Thu 2009-12-03 13:16:08 -0600
message:
  Start cleaning up test_log.
  
  Lots of tests were close to copy&paste of other tests, but changing one or
  two variables. Try to factor out most of that into a helper function
  that runs show_log on the given set, and asserts the value is correct.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_log.py'
--- a/bzrlib/tests/test_log.py	2009-08-19 01:44:41 +0000
+++ b/bzrlib/tests/test_log.py	2009-12-03 19:16:08 +0000
@@ -40,6 +40,24 @@
             log.properties_handler_registry = self.properties_handler_registry
         self.addCleanup(restore)
 
+    def assertFormatterResult(self, result, branch, formatter_class,
+                              formatter_kwargs=None, show_log_kwargs=None,
+                              normalize=False, utf8=True):
+        if utf8:
+            logfile = self.make_utf8_encoded_stringio()
+        else:
+            logfile = StringIO()
+        if formatter_kwargs is None:
+            formatter_kwargs = {}
+        formatter = formatter_class(to_file=logfile, **formatter_kwargs)
+        if show_log_kwargs is None:
+            show_log_kwargs = {}
+        log.show_log(branch, formatter, **show_log_kwargs)
+        log_content = logfile.getvalue()
+        if normalize:
+            log_content = normalize_log(log_content)
+        self.assertEqualDiff(result, log_content)
+
 
 class LogCatcher(log.LogFormatter):
     """Pull log messages into a list rather than displaying them.
@@ -242,15 +260,12 @@
     return ''.join(lines)
 
 
-class TestShortLogFormatter(tests.TestCaseWithTransport):
+class TestShortLogFormatter(TestCaseWithoutPropsHandler):
 
     def test_trailing_newlines(self):
         wt = self.make_branch_and_tree('.')
         b = make_commits_with_trailing_newlines(wt)
-        sio = self.make_utf8_encoded_stringio()
-        lf = log.ShortLogFormatter(to_file=sio)
-        log.show_log(b, lf)
-        self.assertEqualDiff("""\
+        self.assertFormatterResult("""\
     3 Joe Foo\t2005-11-21
       single line with trailing newline
 
@@ -263,7 +278,7 @@
       simple log message
 
 """,
-                             sio.getvalue())
+            b, log.ShortLogFormatter)
 
     def _prepare_tree_with_merges(self, with_tags=False):
         wt = self.make_branch_and_memory_tree('.')
@@ -293,10 +308,7 @@
 
     def test_short_log_with_merges(self):
         wt = self._prepare_tree_with_merges()
-        logfile = self.make_utf8_encoded_stringio()
-        formatter = log.ShortLogFormatter(to_file=logfile)
-        log.show_log(wt.branch, formatter)
-        self.assertEqualDiff("""\
+        self.assertFormatterResult("""\
     2 Joe Foo\t2005-11-22 [merge]
       rev-2
 
@@ -304,15 +316,11 @@
       rev-1
 
 """,
-                             logfile.getvalue())
+            wt.branch, log.ShortLogFormatter)
 
     def test_short_log_with_merges_and_advice(self):
         wt = self._prepare_tree_with_merges()
-        logfile = self.make_utf8_encoded_stringio()
-        formatter = log.ShortLogFormatter(to_file=logfile,
-            show_advice=True)
-        log.show_log(wt.branch, formatter)
-        self.assertEqualDiff("""\
+        self.assertFormatterResult("""\
     2 Joe Foo\t2005-11-22 [merge]
       rev-2
 
@@ -321,7 +329,8 @@
 
 Use --include-merges or -n0 to see merged revisions.
 """,
-                             logfile.getvalue())
+            wt.branch, log.ShortLogFormatter,
+            formatter_kwargs=dict(show_advice=True))
 
     def test_short_log_with_merges_and_range(self):
         wt = self.make_branch_and_memory_tree('.')
@@ -347,11 +356,7 @@
         wt.commit('rev-3b', rev_id='rev-3b',
                   timestamp=1132586800, timezone=36000,
                   committer='Joe Foo <joe at foo.com>')
-        logfile = self.make_utf8_encoded_stringio()
-        formatter = log.ShortLogFormatter(to_file=logfile)
-        log.show_log(wt.branch, formatter,
-            start_revision=2, end_revision=3)
-        self.assertEqualDiff("""\
+        self.assertFormatterResult("""\
     3 Joe Foo\t2005-11-22 [merge]
       rev-3b
 
@@ -359,14 +364,12 @@
       rev-2b
 
 """,
-                             logfile.getvalue())
+            wt.branch, log.ShortLogFormatter,
+            show_log_kwargs=dict(start_revision=2, end_revision=3))
 
     def test_short_log_with_tags(self):
         wt = self._prepare_tree_with_merges(with_tags=True)
-        logfile = self.make_utf8_encoded_stringio()
-        formatter = log.ShortLogFormatter(to_file=logfile)
-        log.show_log(wt.branch, formatter)
-        self.assertEqualDiff("""\
+        self.assertFormatterResult("""\
     3 Jane Foo\t2005-11-22 {v1.0, v1.0rc1}
       rev-3
 
@@ -377,7 +380,7 @@
       rev-1
 
 """,
-                             logfile.getvalue())
+            wt.branch, log.ShortLogFormatter)
 
     def test_short_log_single_merge_revision(self):
         wt = self.make_branch_and_memory_tree('.')
@@ -395,21 +398,18 @@
         wt.commit('rev-2', rev_id='rev-2b',
                   timestamp=1132586800, timezone=36000,
                   committer='Joe Foo <joe at foo.com>')
-        logfile = self.make_utf8_encoded_stringio()
-        formatter = log.ShortLogFormatter(to_file=logfile)
         revspec = revisionspec.RevisionSpec.from_string('1.1.1')
-        wtb = wt.branch
-        rev = revspec.in_history(wtb)
-        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
-        self.assertEqualDiff("""\
+        rev = revspec.in_history(wt.branch)
+        self.assertFormatterResult("""\
       1.1.1 Joe Foo\t2005-11-22
             rev-merged
 
 """,
-                             logfile.getvalue())
-
-
-class TestShortLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
+            wt.branch, log.ShortLogFormatter,
+            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
+
+
+class TestShortLogFormatterWithMergeRevisions(TestCaseWithoutPropsHandler):
 
     def test_short_merge_revs_log_with_merges(self):
         wt = self.make_branch_and_memory_tree('.')
@@ -427,13 +427,10 @@
         wt.commit('rev-2', rev_id='rev-2b',
                   timestamp=1132586800, timezone=36000,
                   committer='Joe Foo <joe at foo.com>')
-        logfile = self.make_utf8_encoded_stringio()
-        formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
-        log.show_log(wt.branch, formatter)
         # Note that the 1.1.1 indenting is in fact correct given that
         # the revision numbers are right justified within 5 characters
         # for mainline revnos and 9 characters for dotted revnos.
-        self.assertEqualDiff("""\
+        self.assertFormatterResult("""\
     2 Joe Foo\t2005-11-22 [merge]
       rev-2
 
@@ -444,7 +441,8 @@
       rev-1
 
 """,
-                             logfile.getvalue())
+            wt.branch, log.ShortLogFormatter,
+            formatter_kwargs=dict(levels=0))
 
     def test_short_merge_revs_log_single_merge_revision(self):
         wt = self.make_branch_and_memory_tree('.')
@@ -462,18 +460,16 @@
         wt.commit('rev-2', rev_id='rev-2b',
                   timestamp=1132586800, timezone=36000,
                   committer='Joe Foo <joe at foo.com>')
-        logfile = self.make_utf8_encoded_stringio()
-        formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
         revspec = revisionspec.RevisionSpec.from_string('1.1.1')
-        wtb = wt.branch
-        rev = revspec.in_history(wtb)
-        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
-        self.assertEqualDiff("""\
+        rev = revspec.in_history(wt.branch)
+        self.assertFormatterResult("""\
       1.1.1 Joe Foo\t2005-11-22
             rev-merged
 
 """,
-                             logfile.getvalue())
+            wt.branch, log.ShortLogFormatter,
+            formatter_kwargs=dict(levels=0),
+            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
 
 
 class TestLongLogFormatter(TestCaseWithoutPropsHandler):
@@ -484,22 +480,14 @@
         bug #4676
         """
         wt = self.make_branch_and_tree('.')
-        b = wt.branch
         self.build_tree(['a'])
         wt.add('a')
-        # XXX: why does a longer nick show up?
-        b.nick = 'test_verbose_log'
+        wt.branch.nick = 'test_verbose_log'
         wt.commit(message='add a',
                   timestamp=1132711707,
                   timezone=36000,
                   committer='Lorem Ipsum <test at example.com>')
-        logfile = file('out.tmp', 'w+')
-        formatter = log.LongLogFormatter(to_file=logfile)
-        log.show_log(b, formatter, verbose=True)
-        logfile.flush()
-        logfile.seek(0)
-        log_contents = logfile.read()
-        self.assertEqualDiff('''\
+        self.assertFormatterResult('''\
 ------------------------------------------------------------
 revno: 1
 committer: Lorem Ipsum <test at example.com>
@@ -510,7 +498,9 @@
 added:
   a
 ''',
-                             log_contents)
+            wt.branch, log.LongLogFormatter,
+            show_log_kwargs=dict(verbose=True),
+            utf8=False)
 
     def test_merges_are_indented_by_level(self):
         wt = self.make_branch_and_tree('parent')
@@ -526,12 +516,7 @@
         os.chdir('../parent')
         self.run_bzr('merge ../child')
         wt.commit('merge branch 1')
-        b = wt.branch
-        sio = self.make_utf8_encoded_stringio()
-        lf = log.LongLogFormatter(to_file=sio, levels=0)
-        log.show_log(b, lf, verbose=True)
-        the_log = normalize_log(sio.getvalue())
-        self.assertEqualDiff("""\
+        self.assertFormatterResult("""\
 ------------------------------------------------------------
 revno: 2 [merge]
 committer: Lorem Ipsum <test at example.com>
@@ -568,7 +553,10 @@
 message:
   first post
 """,
-                             the_log)
+            wt.branch, log.LongLogFormatter,
+            formatter_kwargs=dict(levels=0),
+            show_log_kwargs=dict(verbose=True),
+            normalize=True)
 
     def test_verbose_merge_revisions_contain_deltas(self):
         wt = self.make_branch_and_tree('parent')
@@ -583,12 +571,7 @@
         os.chdir('parent')
         self.run_bzr('merge ../child')
         wt.commit('merge branch 1')
-        b = wt.branch
-        sio = self.make_utf8_encoded_stringio()
-        lf = log.LongLogFormatter(to_file=sio, levels=0)
-        log.show_log(b, lf, verbose=True)
-        the_log = normalize_log(sio.getvalue())
-        self.assertEqualDiff("""\
+        self.assertFormatterResult("""\
 ------------------------------------------------------------
 revno: 2 [merge]
 committer: Lorem Ipsum <test at example.com>
@@ -622,15 +605,15 @@
   f1
   f2
 """,
-                             the_log)
+            wt.branch, log.LongLogFormatter,
+            formatter_kwargs=dict(levels=0),
+            show_log_kwargs=dict(verbose=True),
+            normalize=True)
 
     def test_trailing_newlines(self):
         wt = self.make_branch_and_tree('.')
         b = make_commits_with_trailing_newlines(wt)
-        sio = self.make_utf8_encoded_stringio()
-        lf = log.LongLogFormatter(to_file=sio)
-        log.show_log(b, lf)
-        self.assertEqualDiff("""\
+        self.assertFormatterResult("""\
 ------------------------------------------------------------
 revno: 3
 committer: Joe Foo <joe at foo.com>
@@ -656,27 +639,21 @@
 message:
   simple log message
 """,
-                             sio.getvalue())
+        b, log.LongLogFormatter)
 
     def test_author_in_log(self):
         """Log includes the author name if it's set in
         the revision properties
         """
         wt = self.make_branch_and_tree('.')
-        b = wt.branch
-        self.build_tree(['a'])
-        wt.add('a')
-        b.nick = 'test_author_log'
-        wt.commit(message='add a',
+        wt.branch.nick = 'test_author_log'
+        wt.commit(message='initial',
                   timestamp=1132711707,
                   timezone=36000,
                   committer='Lorem Ipsum <test at example.com>',
                   authors=['John Doe <jdoe at example.com>',
                            'Jane Rey <jrey at example.com>'])
-        sio = StringIO()
-        formatter = log.LongLogFormatter(to_file=sio)
-        log.show_log(b, formatter)
-        self.assertEqualDiff('''\
+        self.assertFormatterResult("""\
 ------------------------------------------------------------
 revno: 1
 author: John Doe <jdoe at example.com>, Jane Rey <jrey at example.com>
@@ -684,38 +661,29 @@
 branch nick: test_author_log
 timestamp: Wed 2005-11-23 12:08:27 +1000
 message:
-  add a
-''',
-                             sio.getvalue())
+  initial
+""",
+        wt.branch, log.LongLogFormatter, utf8=False)
 
     def test_properties_in_log(self):
         """Log includes the custom properties returned by the registered
         handlers.
         """
         wt = self.make_branch_and_tree('.')
-        b = wt.branch
-        self.build_tree(['a'])
-        wt.add('a')
-        b.nick = 'test_properties_in_log'
-        wt.commit(message='add a',
+        wt.branch.nick = 'test_properties_in_log'
+        wt.commit(message='initial',
                   timestamp=1132711707,
                   timezone=36000,
                   committer='Lorem Ipsum <test at example.com>',
                   authors=['John Doe <jdoe at example.com>'])
-        sio = StringIO()
-        formatter = log.LongLogFormatter(to_file=sio)
-        try:
-            def trivial_custom_prop_handler(revision):
-                return {'test_prop':'test_value'}
+        def trivial_custom_prop_handler(revision):
+            return {'test_prop':'test_value'}
 
-            log.properties_handler_registry.register(
-                'trivial_custom_prop_handler',
-                trivial_custom_prop_handler)
-            log.show_log(b, formatter)
-        finally:
-            log.properties_handler_registry.remove(
-                'trivial_custom_prop_handler')
-            self.assertEqualDiff('''\
+        # Cleaned up in setUp()
+        log.properties_handler_registry.register(
+            'trivial_custom_prop_handler',
+            trivial_custom_prop_handler)
+        self.assertFormatterResult("""\
 ------------------------------------------------------------
 revno: 1
 test_prop: test_value
@@ -724,55 +692,41 @@
 branch nick: test_properties_in_log
 timestamp: Wed 2005-11-23 12:08:27 +1000
 message:
-  add a
-''',
-                                 sio.getvalue())
+  initial
+""",
+            wt.branch, log.LongLogFormatter, utf8=False)
 
     def test_properties_in_short_log(self):
         """Log includes the custom properties returned by the registered
         handlers.
         """
         wt = self.make_branch_and_tree('.')
-        b = wt.branch
-        self.build_tree(['a'])
-        wt.add('a')
-        b.nick = 'test_properties_in_short_log'
-        wt.commit(message='add a',
+        wt.branch.nick = 'test_properties_in_short_log'
+        wt.commit(message='initial',
                   timestamp=1132711707,
                   timezone=36000,
                   committer='Lorem Ipsum <test at example.com>',
                   authors=['John Doe <jdoe at example.com>'])
-        sio = StringIO()
-        formatter = log.ShortLogFormatter(to_file=sio)
-        try:
-            def trivial_custom_prop_handler(revision):
-                return {'test_prop':'test_value'}
+        def trivial_custom_prop_handler(revision):
+            return {'test_prop':'test_value'}
 
-            log.properties_handler_registry.register(
-                'trivial_custom_prop_handler',
-                trivial_custom_prop_handler)
-            log.show_log(b, formatter)
-        finally:
-            log.properties_handler_registry.remove(
-                'trivial_custom_prop_handler')
-            self.assertEqualDiff('''\
+        log.properties_handler_registry.register(
+            'trivial_custom_prop_handler',
+            trivial_custom_prop_handler)
+        self.assertFormatterResult("""\
     1 John Doe\t2005-11-23
       test_prop: test_value
-      add a
+      initial
 
-''',
-                                 sio.getvalue())
+""",
+            wt.branch, log.ShortLogFormatter)
 
     def test_error_in_properties_handler(self):
         """Log includes the custom properties returned by the registered
         handlers.
         """
         wt = self.make_branch_and_tree('.')
-        b = wt.branch
-        self.build_tree(['a'])
-        wt.add('a')
-        b.nick = 'test_author_log'
-        wt.commit(message='add a',
+        wt.commit(message='initial',
                   timestamp=1132711707,
                   timezone=36000,
                   committer='Lorem Ipsum <test at example.com>',
@@ -787,18 +741,15 @@
             log.properties_handler_registry.register(
                 'trivial_custom_prop_handler',
                 trivial_custom_prop_handler)
-            self.assertRaises(StandardError, log.show_log, b, formatter,)
+            self.assertRaises(StandardError, log.show_log, wt.branch, formatter,)
         finally:
             log.properties_handler_registry.remove(
                 'trivial_custom_prop_handler')
 
     def test_properties_handler_bad_argument(self):
         wt = self.make_branch_and_tree('.')
-        b = wt.branch
-        self.build_tree(['a'])
-        wt.add('a')
-        b.nick = 'test_author_log'
-        wt.commit(message='add a',
+        wt.branch.nick = 'test_author_log'
+        wt.commit(message='initial',
                   timestamp=1132711707,
                   timezone=36000,
                   committer='Lorem Ipsum <test at example.com>',
@@ -806,24 +757,20 @@
                   revprops={'a_prop':'test_value'})
         sio = StringIO()
         formatter = log.LongLogFormatter(to_file=sio)
-        try:
-            def bad_argument_prop_handler(revision):
-                return {'custom_prop_name':revision.properties['a_prop']}
-
-            log.properties_handler_registry.register(
-                'bad_argument_prop_handler',
-                bad_argument_prop_handler)
-
-            self.assertRaises(AttributeError, formatter.show_properties,
-                              'a revision', '')
-
-            revision = b.repository.get_revision(b.last_revision())
-            formatter.show_properties(revision, '')
-            self.assertEqualDiff('''custom_prop_name: test_value\n''',
-                                 sio.getvalue())
-        finally:
-            log.properties_handler_registry.remove(
-                'bad_argument_prop_handler')
+        def bad_argument_prop_handler(revision):
+            return {'custom_prop_name':revision.properties['a_prop']}
+
+        log.properties_handler_registry.register(
+            'bad_argument_prop_handler',
+            bad_argument_prop_handler)
+
+        self.assertRaises(AttributeError, formatter.show_properties,
+                          'a revision', '')
+
+        revision = wt.branch.repository.get_revision(wt.branch.last_revision())
+        formatter.show_properties(revision, '')
+        self.assertEqualDiff('''custom_prop_name: test_value\n''',
+                             sio.getvalue())
 
 
 class TestLongLogFormatterWithoutMergeRevisions(TestCaseWithoutPropsHandler):
@@ -834,22 +781,14 @@
         bug #4676
         """
         wt = self.make_branch_and_tree('.')
-        b = wt.branch
         self.build_tree(['a'])
         wt.add('a')
-        # XXX: why does a longer nick show up?
-        b.nick = 'test_verbose_log'
+        wt.branch.nick = 'test_verbose_log'
         wt.commit(message='add a',
                   timestamp=1132711707,
                   timezone=36000,
                   committer='Lorem Ipsum <test at example.com>')
-        logfile = file('out.tmp', 'w+')
-        formatter = log.LongLogFormatter(to_file=logfile, levels=1)
-        log.show_log(b, formatter, verbose=True)
-        logfile.flush()
-        logfile.seek(0)
-        log_contents = logfile.read()
-        self.assertEqualDiff('''\
+        self.assertFormatterResult("""\
 ------------------------------------------------------------
 revno: 1
 committer: Lorem Ipsum <test at example.com>
@@ -859,28 +798,24 @@
   add a
 added:
   a
-''',
-                             log_contents)
+""",
+            wt.branch, log.LongLogFormatter,
+            formatter_kwargs=dict(levels=1),
+            show_log_kwargs=dict(verbose=True),
+            utf8=False)
 
     def test_long_verbose_contain_deltas(self):
         wt = self.make_branch_and_tree('parent')
         self.build_tree(['parent/f1', 'parent/f2'])
         wt.add(['f1','f2'])
         wt.commit('first post')
-        self.run_bzr('branch parent child')
+        child_wt = wt.bzrdir.sprout('child').open_workingtree()
         os.unlink('child/f1')
-        file('child/f2', 'wb').write('hello\n')
-        self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
-            'child'])
-        os.chdir('parent')
-        self.run_bzr('merge ../child')
+        self.build_tree_contents([('child/f2', 'hello\n')])
+        child_wt.commit('removed f1 and modified f2')
+        wt.merge_from_branch(child_wt.branch)
         wt.commit('merge branch 1')
-        b = wt.branch
-        sio = self.make_utf8_encoded_stringio()
-        lf = log.LongLogFormatter(to_file=sio, levels=1)
-        log.show_log(b, lf, verbose=True)
-        the_log = normalize_log(sio.getvalue())
-        self.assertEqualDiff("""\
+        self.assertFormatterResult("""\
 ------------------------------------------------------------
 revno: 2 [merge]
 committer: Lorem Ipsum <test at example.com>
@@ -903,15 +838,15 @@
   f1
   f2
 """,
-                             the_log)
+            wt.branch, log.LongLogFormatter,
+            formatter_kwargs=dict(levels=1),
+            show_log_kwargs=dict(verbose=True),
+            normalize=True)
 
     def test_long_trailing_newlines(self):
         wt = self.make_branch_and_tree('.')
         b = make_commits_with_trailing_newlines(wt)
-        sio = self.make_utf8_encoded_stringio()
-        lf = log.LongLogFormatter(to_file=sio, levels=1)
-        log.show_log(b, lf)
-        self.assertEqualDiff("""\
+        self.assertFormatterResult("""\
 ------------------------------------------------------------
 revno: 3
 committer: Joe Foo <joe at foo.com>
@@ -937,26 +872,21 @@
 message:
   simple log message
 """,
-                             sio.getvalue())
+        b, log.LongLogFormatter,
+        formatter_kwargs=dict(levels=1))
 
     def test_long_author_in_log(self):
         """Log includes the author name if it's set in
         the revision properties
         """
         wt = self.make_branch_and_tree('.')
-        b = wt.branch
-        self.build_tree(['a'])
-        wt.add('a')
-        b.nick = 'test_author_log'
-        wt.commit(message='add a',
+        wt.branch.nick = 'test_author_log'
+        wt.commit(message='initial',
                   timestamp=1132711707,
                   timezone=36000,
                   committer='Lorem Ipsum <test at example.com>',
                   authors=['John Doe <jdoe at example.com>'])
-        sio = StringIO()
-        formatter = log.LongLogFormatter(to_file=sio, levels=1)
-        log.show_log(b, formatter)
-        self.assertEqualDiff('''\
+        self.assertFormatterResult("""\
 ------------------------------------------------------------
 revno: 1
 author: John Doe <jdoe at example.com>
@@ -964,38 +894,29 @@
 branch nick: test_author_log
 timestamp: Wed 2005-11-23 12:08:27 +1000
 message:
-  add a
-''',
-                             sio.getvalue())
+  initial
+""",
+            wt.branch, log.LongLogFormatter,
+            formatter_kwargs=dict(levels=1))
 
     def test_long_properties_in_log(self):
         """Log includes the custom properties returned by the registered
         handlers.
         """
         wt = self.make_branch_and_tree('.')
-        b = wt.branch
-        self.build_tree(['a'])
-        wt.add('a')
-        b.nick = 'test_properties_in_log'
-        wt.commit(message='add a',
+        wt.branch.nick = 'test_properties_in_log'
+        wt.commit(message='initial',
                   timestamp=1132711707,
                   timezone=36000,
                   committer='Lorem Ipsum <test at example.com>',
                   authors=['John Doe <jdoe at example.com>'])
-        sio = StringIO()
-        formatter = log.LongLogFormatter(to_file=sio, levels=1)
-        try:
-            def trivial_custom_prop_handler(revision):
-                return {'test_prop':'test_value'}
+        def trivial_custom_prop_handler(revision):
+            return {'test_prop':'test_value'}
 
-            log.properties_handler_registry.register(
-                'trivial_custom_prop_handler',
-                trivial_custom_prop_handler)
-            log.show_log(b, formatter)
-        finally:
-            log.properties_handler_registry.remove(
-                'trivial_custom_prop_handler')
-            self.assertEqualDiff('''\
+        log.properties_handler_registry.register(
+            'trivial_custom_prop_handler',
+            trivial_custom_prop_handler)
+        self.assertFormatterResult("""\
 ------------------------------------------------------------
 revno: 1
 test_prop: test_value
@@ -1004,9 +925,10 @@
 branch nick: test_properties_in_log
 timestamp: Wed 2005-11-23 12:08:27 +1000
 message:
-  add a
-''',
-                                 sio.getvalue())
+  initial
+""",
+            wt.branch, log.LongLogFormatter,
+            formatter_kwargs=dict(levels=1))
 
 
 class TestLineLogFormatter(tests.TestCaseWithTransport):
@@ -1025,14 +947,11 @@
                   timestamp=1132711707,
                   timezone=36000,
                   committer='Line-Log-Formatter Tester <test at line.log>')
-        logfile = file('out.tmp', 'w+')
+        logfile = StringIO()
         formatter = log.LineLogFormatter(to_file=logfile)
         log.show_log(b, formatter)
-        logfile.flush()
-        logfile.seek(0)
-        log_contents = logfile.read()
         self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
-                             log_contents)
+                             logfile.getvalue())
 
     def test_trailing_newlines(self):
         wt = self.make_branch_and_tree('.')
@@ -1114,14 +1033,11 @@
                   timestamp=1132711707,
                   timezone=36000,
                   committer='Line-Log-Formatter Tester <test at line.log>')
-        logfile = file('out.tmp', 'w+')
+        logfile = StringIO()
         formatter = log.LineLogFormatter(to_file=logfile, levels=0)
         log.show_log(b, formatter)
-        logfile.flush()
-        logfile.seek(0)
-        log_contents = logfile.read()
         self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
-                             log_contents)
+                             logfile.getvalue())
 
     def test_line_merge_revs_log_single_merge_revision(self):
         wt = self.make_branch_and_memory_tree('.')



More information about the bazaar-commits mailing list