Rev 2997: Use normalize_log to more accurately test blackbox log output (Kent Gibson) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Nov 15 08:49:10 GMT 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 2997
revision-id: pqm at pqm.ubuntu.com-20071115084907-6bzfegb0kf5e2zte
parent: pqm at pqm.ubuntu.com-20071114233259-pdmdsqafctzx6bjs
parent: ian.clatworthy at internode.on.net-20071115074438-33inxrb538wffpow
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2007-11-15 08:49:07 +0000
message:
  Use normalize_log to more accurately test blackbox log output (Kent Gibson)
modified:
  bzrlib/tests/blackbox/test_log.py test_log.py-20060112090212-78f6ea560c868e24
  bzrlib/tests/test_log.py       testlog.py-20050728115707-1a514809d7d49309
    ------------------------------------------------------------
    revno: 2996.1.1
    merged: ian.clatworthy at internode.on.net-20071115074438-33inxrb538wffpow
    parent: pqm at pqm.ubuntu.com-20071114233259-pdmdsqafctzx6bjs
    parent: warthog618 at gmail.com-20071112140335-d4g28jx86jlz8uzx
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: ianc-integration
    timestamp: Thu 2007-11-15 17:44:38 +1000
    message:
      Use normalize_log to more accurately test blackbox log output (Kent Gibson)
    ------------------------------------------------------------
    revno: 2978.6.2
    merged: warthog618 at gmail.com-20071112140335-d4g28jx86jlz8uzx
    parent: warthog618 at gmail.com-20071112135616-1bvp2zhekdvy0j23
    committer: Kent Gibson <warthog618 at gmail.com>
    branch nick: bzr.kg
    timestamp: Mon 2007-11-12 23:03:35 +0900
    message:
      When comparing logs using assertEqualDiff, pass the igenerated log first then the expected log so the output reflects what is additional in or missing from the generated log.
    ------------------------------------------------------------
    revno: 2978.6.1
    merged: warthog618 at gmail.com-20071112135616-1bvp2zhekdvy0j23
    parent: pqm at pqm.ubuntu.com-20071109195036-5o5bwu0a01uniqwg
    committer: Kent Gibson <warthog618 at gmail.com>
    branch nick: bzr.kg
    timestamp: Mon 2007-11-12 22:56:16 +0900
    message:
      Use normalize_log to more accurately test blackbox log output.
=== modified file 'bzrlib/tests/blackbox/test_log.py'
--- a/bzrlib/tests/blackbox/test_log.py	2007-11-14 06:06:41 +0000
+++ b/bzrlib/tests/blackbox/test_log.py	2007-11-15 07:44:38 +0000
@@ -23,6 +23,9 @@
 import bzrlib
 from bzrlib.tests.blackbox import ExternalBase
 from bzrlib.tests import TestCaseInTempDir, TestCaseWithTransport
+from bzrlib.tests.test_log import (
+    normalize_log,
+    )
 
 
 class TestLog(ExternalBase):
@@ -188,135 +191,96 @@
     def test_merges_are_indented_by_level(self):
         self._prepare()
         out,err = self.run_bzr('log')
-        # the log will look something like:
-#        self.assertEqual("""\
-#------------------------------------------------------------
-#revno: 2
-#committer: Robert Collins <foo at example.com>
-#branch nick: parent
-#timestamp: Tue 2006-03-28 22:31:40 +1100
-#message:
-#  merge branch 1
-#    ------------------------------------------------------------
-#    revno: 1.1.2  
-#    committer: Robert Collins <foo at example.com>
-#    branch nick: child
-#    timestamp: Tue 2006-03-28 22:31:40 +1100
-#    message:
-#      merge branch 2
-#        ------------------------------------------------------------
-#        revno: 1.1.1.1
-#        committer: Robert Collins <foo at example.com>
-#        branch nick: smallerchild
-#        timestamp: Tue 2006-03-28 22:31:40 +1100
-#        message:
-#          branch 2
-#    ------------------------------------------------------------
-#    revno: 1.1.1
-#    committer: Robert Collins <foo at example.com>
-#    branch nick: child
-#    timestamp: Tue 2006-03-28 22:31:40 +1100
-#    message:
-#      branch 1
-#------------------------------------------------------------
-#revno: 1
-#committer: Robert Collins <foo at example.com>
-#branch nick: parent
-#timestamp: Tue 2006-03-28 22:31:39 +1100
-#message:
-#  first post
-#""", out)
-        # but we dont have a nice pattern matcher hooked up yet, so:
-        # we check for the indenting of the commit message and the 
-        # revision numbers 
-        self.assertTrue('revno: 2' in out)
-        self.assertTrue('  merge branch 1' in out)
-        self.assertTrue('    revno: 1.1.2' in out)
-        self.assertTrue('      merge branch 2' in out)
-        self.assertTrue('        revno: 1.1.1.1' in out)
-        self.assertTrue('          branch 2' in out)
-        self.assertTrue('    revno: 1.1.1' in out)
-        self.assertTrue('      branch 1' in out)
-        self.assertTrue('revno: 1\n' in out)
-        self.assertTrue('  first post' in out)
         self.assertEqual('', err)
+        log = normalize_log(out)
+        self.assertEqualDiff(log, """\
+------------------------------------------------------------
+revno: 2
+committer: Lorem Ipsum <test at example.com>
+branch nick: parent
+timestamp: Just now
+message:
+  merge branch 1
+    ------------------------------------------------------------
+    revno: 1.1.2
+    committer: Lorem Ipsum <test at example.com>
+    branch nick: child
+    timestamp: Just now
+    message:
+      merge branch 2
+        ------------------------------------------------------------
+        revno: 1.1.1.1.1
+        committer: Lorem Ipsum <test at example.com>
+        branch nick: smallerchild
+        timestamp: Just now
+        message:
+          branch 2
+    ------------------------------------------------------------
+    revno: 1.1.1
+    committer: Lorem Ipsum <test at example.com>
+    branch nick: child
+    timestamp: Just now
+    message:
+      branch 1
+------------------------------------------------------------
+revno: 1
+committer: Lorem Ipsum <test at example.com>
+branch nick: parent
+timestamp: Just now
+message:
+  first post
+""")
 
     def test_merges_single_merge_rev(self):
         self._prepare()
         out,err = self.run_bzr('log -r1.1.2')
-        # the log will look something like:
-#        self.assertEqual("""\
-#------------------------------------------------------------
-#revno: 1.1.2  
-#committer: Robert Collins <foo at example.com>
-#branch nick: child
-#timestamp: Tue 2006-03-28 22:31:40 +1100
-#message:
-#  merge branch 2
-#    ------------------------------------------------------------
-#    revno: 1.1.1.1
-#    committer: Robert Collins <foo at example.com>
-#    branch nick: smallerchild
-#    timestamp: Tue 2006-03-28 22:31:40 +1100
-#    message:
-#      branch 2
-#""", out)
-        # but we dont have a nice pattern matcher hooked up yet, so:
-        # we check for the indenting of the commit message and the 
-        # revision numbers 
-        self.assertTrue('revno: 2' not in out)
-        self.assertTrue('  merge branch 1' not in out)
-        self.assertTrue('revno: 1.1.2' in out)
-        self.assertTrue('  merge branch 2' in out)
-        self.assertTrue('    revno: 1.1.1.1' in out)
-        self.assertTrue('      branch 2' in out)
-        self.assertTrue('revno: 1.1.1\n' not in out)
-        self.assertTrue('  branch 1' not in out)
-        self.assertTrue('revno: 1\n' not in out)
-        self.assertTrue('  first post' not in out)
         self.assertEqual('', err)
+        log = normalize_log(out)
+        self.assertEqualDiff(log, """\
+------------------------------------------------------------
+revno: 1.1.2
+committer: Lorem Ipsum <test at example.com>
+branch nick: child
+timestamp: Just now
+message:
+  merge branch 2
+    ------------------------------------------------------------
+    revno: 1.1.1.1.1
+    committer: Lorem Ipsum <test at example.com>
+    branch nick: smallerchild
+    timestamp: Just now
+    message:
+      branch 2
+""")
 
     def test_merges_partial_range(self):
         self._prepare()
         out,err = self.run_bzr('log -r1.1.1..1.1.2')
-        # the log will look something like:
-#        self.assertEqual("""\
-#------------------------------------------------------------
-#revno: 1.1.2  
-#committer: Robert Collins <foo at example.com>
-#branch nick: child
-#timestamp: Tue 2006-03-28 22:31:40 +1100
-#message:
-#  merge branch 2
-#    ------------------------------------------------------------
-#    revno: 1.1.1.1
-#    committer: Robert Collins <foo at example.com>
-#    branch nick: smallerchild
-#    timestamp: Tue 2006-03-28 22:31:40 +1100
-#    message:
-#      branch 2
-#------------------------------------------------------------
-#revno: 1.1.1
-#committer: Robert Collins <foo at example.com>
-#branch nick: child
-#timestamp: Tue 2006-03-28 22:31:40 +1100
-#message:
-#  branch 1
-#""", out)
-        # but we dont have a nice pattern matcher hooked up yet, so:
-        # we check for the indenting of the commit message and the 
-        # revision numbers 
-        self.assertTrue('revno: 2' not in out)
-        self.assertTrue('  merge branch 1' not in out)
-        self.assertTrue('revno: 1.1.2' in out)
-        self.assertTrue('  merge branch 2' in out)
-        self.assertTrue('    revno: 1.1.1.1' in out)
-        self.assertTrue('      branch 2' in out)
-        self.assertTrue('revno: 1.1.1' in out)
-        self.assertTrue('  branch 1' in out)
-        self.assertTrue('revno: 1\n' not in out)
-        self.assertTrue('  first post' not in out)
         self.assertEqual('', err)
+        log = normalize_log(out)
+        self.assertEqualDiff(log, """\
+------------------------------------------------------------
+revno: 1.1.2
+committer: Lorem Ipsum <test at example.com>
+branch nick: child
+timestamp: Just now
+message:
+  merge branch 2
+    ------------------------------------------------------------
+    revno: 1.1.1.1.1
+    committer: Lorem Ipsum <test at example.com>
+    branch nick: smallerchild
+    timestamp: Just now
+    message:
+      branch 2
+------------------------------------------------------------
+revno: 1.1.1
+committer: Lorem Ipsum <test at example.com>
+branch nick: child
+timestamp: Just now
+message:
+  branch 1
+""")
 
     def test_merges_nonsupporting_formatter(self):
         self._prepare()

=== modified file 'bzrlib/tests/test_log.py'
--- a/bzrlib/tests/test_log.py	2007-10-16 16:02:01 +0000
+++ b/bzrlib/tests/test_log.py	2007-11-12 14:03:35 +0000
@@ -219,6 +219,23 @@
     return b
 
 
+def normalize_log(log):
+    """Replaces the variable lines of logs with fixed lines"""
+    author = 'author: Dolor Sit <test at example.com>'
+    committer = 'committer: Lorem Ipsum <test at example.com>'
+    lines = log.splitlines(True)
+    for idx,line in enumerate(lines):
+        stripped_line = line.lstrip()
+        indent = ' ' * (len(line) - len(stripped_line))
+        if stripped_line.startswith('author:'):
+            lines[idx] = indent + author + '\n'
+        elif stripped_line.startswith('committer:'):
+            lines[idx] = indent + committer + '\n'
+        elif stripped_line.startswith('timestamp:'):
+            lines[idx] = indent + 'timestamp: Just now\n'
+    return ''.join(lines)
+
+
 class TestShortLogFormatter(TestCaseWithTransport):
 
     def test_trailing_newlines(self):
@@ -227,7 +244,7 @@
         sio = self.make_utf8_encoded_stringio()
         lf = ShortLogFormatter(to_file=sio)
         show_log(b, lf)
-        self.assertEquals(sio.getvalue(), """\
+        self.assertEqualDiff(sio.getvalue(), """\
     3 Joe Foo\t2005-11-21
       single line with trailing newline
 
@@ -244,22 +261,6 @@
 
 class TestLongLogFormatter(TestCaseWithTransport):
 
-    def normalize_log(self,log):
-        """Replaces the variable lines of logs with fixed lines"""
-        author = 'author: Dolor Sit <test at example.com>'
-        committer = 'committer: Lorem Ipsum <test at example.com>'
-        lines = log.splitlines(True)
-        for idx,line in enumerate(lines):
-            stripped_line = line.lstrip()
-            indent = ' ' * (len(line) - len(stripped_line))
-            if stripped_line.startswith('author:'):
-                lines[idx] = indent + author + '\n'
-            elif stripped_line.startswith('committer:'):
-                lines[idx] = indent + committer + '\n'
-            elif stripped_line.startswith('timestamp:'):
-                lines[idx] = indent + 'timestamp: Just now\n'
-        return ''.join(lines)
-
     def test_verbose_log(self):
         """Verbose log includes changed files
         
@@ -311,8 +312,8 @@
         sio = self.make_utf8_encoded_stringio()
         lf = LongLogFormatter(to_file=sio)
         show_log(b, lf, verbose=True)
-        log = self.normalize_log(sio.getvalue())
-        self.assertEqualDiff("""\
+        log = normalize_log(sio.getvalue())
+        self.assertEqualDiff(log, """\
 ------------------------------------------------------------
 revno: 2
 committer: Lorem Ipsum <test at example.com>
@@ -348,7 +349,7 @@
 timestamp: Just now
 message:
   first post
-""", log)
+""")
 
     def test_verbose_merge_revisions_contain_deltas(self):
         wt = self.make_branch_and_tree('parent')
@@ -367,8 +368,8 @@
         sio = self.make_utf8_encoded_stringio()
         lf = LongLogFormatter(to_file=sio)
         show_log(b, lf, verbose=True)
-        log = self.normalize_log(sio.getvalue())
-        self.assertEqualDiff("""\
+        log = normalize_log(sio.getvalue())
+        self.assertEqualDiff(log, """\
 ------------------------------------------------------------
 revno: 2
 committer: Lorem Ipsum <test at example.com>
@@ -401,7 +402,7 @@
 added:
   f1
   f2
-""", log)
+""")
 
     def test_trailing_newlines(self):
         wt = self.make_branch_and_tree('.')
@@ -488,7 +489,8 @@
         logfile.flush()
         logfile.seek(0)
         log_contents = logfile.read()
-        self.assertEqualDiff(log_contents, '1: Line-Log-Formatte... 2005-11-23 add a\n')
+        self.assertEqualDiff(log_contents,
+            '1: Line-Log-Formatte... 2005-11-23 add a\n')
 
     def test_short_log_with_merges(self):
         wt = self.make_branch_and_memory_tree('.')
@@ -510,14 +512,14 @@
             formatter = ShortLogFormatter(to_file=logfile)
             show_log(wt.branch, formatter)
             logfile.flush()
-            self.assertEqualDiff("""\
+            self.assertEqualDiff(logfile.getvalue(), """\
     2 Joe Foo\t2005-11-22 [merge]
       rev-2
 
     1 Joe Foo\t2005-11-22
       rev-1
 
-""", logfile.getvalue())
+""")
         finally:
             wt.unlock()
 




More information about the bazaar-commits mailing list