Rev 624: Add tests of RevisionView that it can handle broken file-info properties. in http://bazaar.launchpad.net/%7Ejameinel/bzr-gtk/sanitize_commit_messages

John Arbash Meinel john at arbash-meinel.com
Thu Nov 13 07:02:30 GMT 2008


At http://bazaar.launchpad.net/%7Ejameinel/bzr-gtk/sanitize_commit_messages

------------------------------------------------------------
revno: 624
revision-id: john at arbash-meinel.com-20081113065541-o9a9ygeu0v1n2rsb
parent: john at arbash-meinel.com-20081113054835-8s7xth55j7kcexl3
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: sanitize_commit_messages
timestamp: Thu 2008-11-13 00:55:41 -0600
message:
  Add tests of RevisionView that it can handle broken file-info properties.
-------------- next part --------------
=== modified file 'revisionview.py'
--- a/revisionview.py	2008-07-11 15:46:32 +0000
+++ b/revisionview.py	2008-11-13 06:55:41 +0000
@@ -22,6 +22,7 @@
 import gobject
 import webbrowser
 
+from bzrlib import trace
 from bzrlib.osutils import format_date
 from bzrlib.util.bencode import bdecode
 from bzrlib.testament import Testament
@@ -422,10 +423,15 @@
         self._add_parents_or_children(revision.parent_ids,
                                       self.parents_widgets,
                                       self.parents_table)
-        
+
         file_info = revision.properties.get('file-info', None)
         if file_info is not None:
-            file_info = bdecode(file_info.encode('UTF-8'))
+            try:
+                file_info = bdecode(file_info.encode('UTF-8'))
+            except ValueError:
+                trace.note('Invalid per-file info for revision:%s, value: %r',
+                           revision.revision_id, file_info)
+                file_info = None
 
         if file_info:
             if self._file_id is None:

=== modified file 'tests/__init__.py'
--- a/tests/__init__.py	2008-06-29 22:44:42 +0000
+++ b/tests/__init__.py	2008-11-13 06:55:41 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2007 Jelmer Vernooij <jelmer at samba.org>
+# Copyright (C) 2007, 2008 Jelmer Vernooij <jelmer at samba.org>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -27,9 +27,10 @@
     testmod_names = [
         'test_commit',
         'test_diff',
+        'test_history',
         'test_linegraph',
         'test_preferences',
-        'test_history',
+        'test_revisionview',
         ]
 
     result.addTest(loader.loadTestsFromModuleNames(["%s.%s" % (__name__, i) for i in testmod_names]))

=== modified file 'tests/test_commit.py'
--- a/tests/test_commit.py	2008-11-13 05:48:35 +0000
+++ b/tests/test_commit.py	2008-11-13 06:55:41 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2007 John Arbash Meinel <john at arbash-meinel.com>
+# Copyright (C) 2007, 2008 John Arbash Meinel <john at arbash-meinel.com>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

=== added file 'tests/test_revisionview.py'
--- a/tests/test_revisionview.py	1970-01-01 00:00:00 +0000
+++ b/tests/test_revisionview.py	2008-11-13 06:55:41 +0000
@@ -0,0 +1,92 @@
+# Copyright (C) 2007, 2008 John Arbash Meinel <john at arbash-meinel.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Test the RevisionView functionality."""
+
+import os
+
+import gtk
+
+from bzrlib import (
+    tests,
+    revision,
+    )
+from bzrlib.util import bencode
+
+from bzrlib.plugins.gtk import revisionview
+
+
+class TestPendingRevisions(tests.TestCaseWithMemoryTransport):
+
+    def assertBufferText(self, text, buffer):
+        """Check the text stored in the buffer."""
+        self.assertEqual(text, buffer.get_text(buffer.get_start_iter(),
+                                               buffer.get_end_iter()))
+
+    def test_create_view(self):
+        builder = self.make_branch_builder('test')
+        builder.build_snapshot('A', None,
+            [('add', ('', 'root-id', 'directory', None))])
+        b = builder.get_branch()
+
+        rv = revisionview.RevisionView(b)
+        rev = b.repository.get_revision('A')
+        rv.set_revision(rev)
+        self.assertEqual(rev.committer, rv.committer.get_text())
+        self.assertFalse(rv.author.get_property('visible'))
+        self.assertFalse(rv.author_label.get_property('visible'))
+        self.assertFalse(rv.file_info_box.get_property('visible'))
+
+    def test_create_view_with_file_info(self):
+        tree = self.make_branch_and_memory_tree('test')
+        file_info = bencode.bencode([{'file_id':'root-id', 'path':'',
+                                      'message':'test-message\n'}])
+        tree.lock_write()
+        try:
+            tree.add([''], ['root-id'])
+            tree.commit('test', rev_id='A', revprops={'file-info': file_info})
+        finally:
+            tree.unlock()
+        b = tree.branch
+
+        rv = revisionview.RevisionView(b)
+        rev = b.repository.get_revision('A')
+        rv.set_revision(rev)
+
+        self.assertEqual(rev.committer, rv.committer.get_text())
+        self.assertTrue(rv.file_info_box.get_property('visible'))
+        self.assertBufferText('\ntest-message\n', rv.file_info_buffer)
+
+    def test_create_view_with_broken_file_info(self):
+        tree = self.make_branch_and_memory_tree('test')
+        # This should be 'message13:'
+        file_info = 'ld7:file_id7:root-id7:message11:test-message\n4:path0:ee'
+        tree.lock_write()
+        try:
+            tree.add([''], ['root-id'])
+            tree.commit('test', rev_id='A', revprops={'file-info': file_info})
+        finally:
+            tree.unlock()
+        b = tree.branch
+
+        rv = revisionview.RevisionView(b)
+        rev = b.repository.get_revision('A')
+        rv.set_revision(rev)
+
+        self.assertEqual(rev.committer, rv.committer.get_text())
+        self.assertFalse(rv.file_info_box.get_property('visible'))
+        log = self._get_log(True)
+        self.assertContainsRe(log, 'Invalid per-file info for revision:A')



More information about the bazaar-commits mailing list