Rev 4859: Add a 'make_standard_commit' helper, to remove more code duplication. 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:28:36 GMT 2009


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

------------------------------------------------------------
revno: 4859
revision-id: john at arbash-meinel.com-20091203192823-vlimgnggpjd5drst
parent: john at arbash-meinel.com-20091203191608-n1lkjhs2x22u63du
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0b4-test-log-cleanups
timestamp: Thu 2009-12-03 13:28:23 -0600
message:
  Add a 'make_standard_commit' helper, to remove more code duplication.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_log.py'
--- a/bzrlib/tests/test_log.py	2009-12-03 19:16:08 +0000
+++ b/bzrlib/tests/test_log.py	2009-12-03 19:28:23 +0000
@@ -58,6 +58,23 @@
             log_content = normalize_log(log_content)
         self.assertEqualDiff(result, log_content)
 
+    def make_standard_commit(self, branch_nick, **kwargs):
+        wt = self.make_branch_and_tree('.')
+        wt.lock_write()
+        self.addCleanup(wt.unlock)
+        self.build_tree(['a'])
+        wt.add(['a'])
+        wt.branch.nick = branch_nick
+        kwargs = dict(kwargs)
+        kwargs.setdefault('message', 'add a')
+        kwargs.setdefault('timestamp', 1132711707)
+        kwargs.setdefault('timezone', 36000)
+        kwargs.setdefault('committer', 'Lorem Ipsum <test at example.com>')
+        kwargs.setdefault('authors', ['John Doe <jdoe at example.com>'])
+        wt.commit(**kwargs)
+        return wt
+        
+
 
 class LogCatcher(log.LogFormatter):
     """Pull log messages into a list rather than displaying them.
@@ -645,14 +662,9 @@
         """Log includes the author name if it's set in
         the revision properties
         """
-        wt = self.make_branch_and_tree('.')
-        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>'])
+        wt = self.make_standard_commit('test_author_log',
+            authors=['John Doe <jdoe at example.com>',
+                     'Jane Rey <jrey at example.com>'])
         self.assertFormatterResult("""\
 ------------------------------------------------------------
 revno: 1
@@ -661,7 +673,7 @@
 branch nick: test_author_log
 timestamp: Wed 2005-11-23 12:08:27 +1000
 message:
-  initial
+  add a
 """,
         wt.branch, log.LongLogFormatter, utf8=False)
 
@@ -669,13 +681,7 @@
         """Log includes the custom properties returned by the registered
         handlers.
         """
-        wt = self.make_branch_and_tree('.')
-        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>'])
+        wt = self.make_standard_commit('test_properties_in_log')
         def trivial_custom_prop_handler(revision):
             return {'test_prop':'test_value'}
 
@@ -692,7 +698,7 @@
 branch nick: test_properties_in_log
 timestamp: Wed 2005-11-23 12:08:27 +1000
 message:
-  initial
+  add a
 """,
             wt.branch, log.LongLogFormatter, utf8=False)
 
@@ -700,13 +706,7 @@
         """Log includes the custom properties returned by the registered
         handlers.
         """
-        wt = self.make_branch_and_tree('.')
-        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>'])
+        wt = self.make_standard_commit('test_properties_in_short_log')
         def trivial_custom_prop_handler(revision):
             return {'test_prop':'test_value'}
 
@@ -716,7 +716,7 @@
         self.assertFormatterResult("""\
     1 John Doe\t2005-11-23
       test_prop: test_value
-      initial
+      add a
 
 """,
             wt.branch, log.ShortLogFormatter)
@@ -725,36 +725,21 @@
         """Log includes the custom properties returned by the registered
         handlers.
         """
-        wt = self.make_branch_and_tree('.')
-        wt.commit(message='initial',
-                  timestamp=1132711707,
-                  timezone=36000,
-                  committer='Lorem Ipsum <test at example.com>',
-                  authors=['John Doe <jdoe at example.com>'],
-                  revprops={'first_prop':'first_value'})
+        wt = self.make_standard_commit('error_in_properties_handler',
+            revprops={'first_prop':'first_value'})
         sio = StringIO()
         formatter = log.LongLogFormatter(to_file=sio)
-        try:
-            def trivial_custom_prop_handler(revision):
-                raise StandardError("a test error")
+        def trivial_custom_prop_handler(revision):
+            raise StandardError("a test error")
 
-            log.properties_handler_registry.register(
-                'trivial_custom_prop_handler',
-                trivial_custom_prop_handler)
-            self.assertRaises(StandardError, log.show_log, wt.branch, formatter,)
-        finally:
-            log.properties_handler_registry.remove(
-                'trivial_custom_prop_handler')
+        log.properties_handler_registry.register(
+            'trivial_custom_prop_handler',
+            trivial_custom_prop_handler)
+        self.assertRaises(StandardError, log.show_log, wt.branch, formatter,)
 
     def test_properties_handler_bad_argument(self):
-        wt = self.make_branch_and_tree('.')
-        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>'],
-                  revprops={'a_prop':'test_value'})
+        wt = self.make_standard_commit('bad_argument',
+              revprops={'a_prop':'test_value'})
         sio = StringIO()
         formatter = log.LongLogFormatter(to_file=sio)
         def bad_argument_prop_handler(revision):
@@ -780,19 +765,12 @@
 
         bug #4676
         """
-        wt = self.make_branch_and_tree('.')
-        self.build_tree(['a'])
-        wt.add('a')
-        wt.branch.nick = 'test_verbose_log'
-        wt.commit(message='add a',
-                  timestamp=1132711707,
-                  timezone=36000,
-                  committer='Lorem Ipsum <test at example.com>')
+        wt = self.make_standard_commit('test_long_verbose_log', authors=[])
         self.assertFormatterResult("""\
 ------------------------------------------------------------
 revno: 1
 committer: Lorem Ipsum <test at example.com>
-branch nick: test_verbose_log
+branch nick: test_long_verbose_log
 timestamp: Wed 2005-11-23 12:08:27 +1000
 message:
   add a
@@ -879,13 +857,7 @@
         """Log includes the author name if it's set in
         the revision properties
         """
-        wt = self.make_branch_and_tree('.')
-        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>'])
+        wt = self.make_standard_commit('test_author_log')
         self.assertFormatterResult("""\
 ------------------------------------------------------------
 revno: 1
@@ -894,7 +866,7 @@
 branch nick: test_author_log
 timestamp: Wed 2005-11-23 12:08:27 +1000
 message:
-  initial
+  add a
 """,
             wt.branch, log.LongLogFormatter,
             formatter_kwargs=dict(levels=1))
@@ -903,13 +875,7 @@
         """Log includes the custom properties returned by the registered
         handlers.
         """
-        wt = self.make_branch_and_tree('.')
-        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>'])
+        wt = self.make_standard_commit('test_properties_in_log')
         def trivial_custom_prop_handler(revision):
             return {'test_prop':'test_value'}
 
@@ -925,7 +891,7 @@
 branch nick: test_properties_in_log
 timestamp: Wed 2005-11-23 12:08:27 +1000
 message:
-  initial
+  add a
 """,
             wt.branch, log.LongLogFormatter,
             formatter_kwargs=dict(levels=1))



More information about the bazaar-commits mailing list