Rev 4833: (Jelmer) Add basic tests for foreign repositories. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Nov 27 23:21:39 GMT 2009


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

------------------------------------------------------------
revno: 4833 [merge]
revision-id: pqm at pqm.ubuntu.com-20091127232136-bkm3vrye2wt4odbw
parent: pqm at pqm.ubuntu.com-20091127112712-52xu8dywjwc1utjs
parent: jelmer at samba.org-20091127032507-77b0783pzwtfoq4m
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2009-11-27 23:21:36 +0000
message:
  (Jelmer) Add basic tests for foreign repositories.
added:
  bzrlib/tests/per_foreign_vcs/test_repository.py test_repository.py-20091014092330-i5ymtg1r2o8quut9-1
modified:
  bzrlib/foreign.py              foreign.py-20081112170002-olsxmandkk8qyfuq-1
  bzrlib/tests/per_foreign_vcs/__init__.py __init__.py-20090804140647-lrnof6q71eti9buc-2
  bzrlib/tests/per_intertree/__init__.py __init__.py-20060724101752-09ysswo1a92uqyoz-3
  bzrlib/tree.py                 tree.py-20050309040759-9d5f2496be663e77
=== modified file 'bzrlib/foreign.py'
--- a/bzrlib/foreign.py	2009-10-20 10:43:50 +0000
+++ b/bzrlib/foreign.py	2009-10-27 21:54:26 +0000
@@ -124,6 +124,8 @@
 
     branch_format = None
 
+    repository_format = None
+
     def __init__(self, mapping_registry, abbreviation=None):
         """Create a new foreign vcs instance.
 

=== modified file 'bzrlib/tests/per_foreign_vcs/__init__.py'
--- a/bzrlib/tests/per_foreign_vcs/__init__.py	2009-10-11 01:02:28 +0000
+++ b/bzrlib/tests/per_foreign_vcs/__init__.py	2009-11-12 22:57:55 +0000
@@ -30,7 +30,9 @@
     for name, vcs in foreign.foreign_vcs_registry.iteritems():
         scenarios.append((vcs.__class__.__name__, {
             "branch_factory": vcs.branch_format.get_foreign_tests_branch_factory(),
+            "repository_factory": vcs.repository_format.get_foreign_tests_repository_factory(),
             "branch_format": vcs.branch_format,
+            "repository_format": vcs.repository_format,
             }))
     return scenarios
 
@@ -39,6 +41,7 @@
     result = loader.suiteClass()
     per_vcs_mod_names = [
         'branch',
+        'repository',
         ]
     sub_tests = loader.loadTestsFromModuleNames(
         ['bzrlib.tests.per_foreign_vcs.test_' + name

=== added file 'bzrlib/tests/per_foreign_vcs/test_repository.py'
--- a/bzrlib/tests/per_foreign_vcs/test_repository.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/per_foreign_vcs/test_repository.py	2009-11-27 03:25:07 +0000
@@ -0,0 +1,88 @@
+# Copyright (C) 2009 Canonical Ltd
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+"""Tests specific to Repository implementations that use foreign VCS'es."""
+
+
+from bzrlib.tests import (
+    TestCase,
+    TestCaseWithTransport,
+    )
+
+
+class TestRepositoryFormat(TestCase):
+
+    def test_format_string(self):
+        self.assertRaises(NotImplementedError,
+            self.repository_format.get_format_string)
+
+    def test_network_name(self):
+        self.assertIsInstance(self.repository_format.network_name(),
+            str)
+
+    def test_format_description(self):
+        self.assertIsInstance(self.repository_format.get_format_description(),
+            str)
+
+
+class ForeignRepositoryFactory(object):
+    """Factory of repository for ForeignRepositoryTests."""
+
+    def make_repository(self, transport):
+        """Create a new, valid, repository. May or may not contain
+        data."""
+        raise NotImplementedError(self.make_repository)
+
+
+class ForeignRepositoryTests(TestCaseWithTransport):
+    """Basic tests for foreign repository implementations.
+
+    These tests mainly make sure that the implementation covers the required
+    bits of the API and returns semi-reasonable values, that are
+    at least of the expected types and in the expected ranges.
+    """
+
+    # XXX: Some of these tests could be moved into a common testcase for
+    # both native and foreign repositories.
+
+    repository_factory = None # Set to an instance of ForeignRepositoryFactory by the scenario
+
+    def make_repository(self):
+        return self.repository_factory.make_repository(self.get_transport())
+
+    def test_make_working_trees(self):
+        """Test that Repository.make_working_trees() returns a boolean."""
+        repo = self.make_repository()
+        self.assertIsInstance(repo.make_working_trees(), bool)
+
+    def test_get_physical_lock_status(self):
+        """Test that a new repository is not locked by default."""
+        repo = self.make_repository()
+        self.assertFalse(repo.get_physical_lock_status())
+
+    def test_is_shared(self):
+        """Test that is_shared() returns a bool."""
+        repo = self.make_repository()
+        self.assertIsInstance(repo.is_shared(), bool)
+
+    def test_gather_stats(self):
+        """Test that gather_stats() will at least return a dictionary
+        with the required keys."""
+        repo = self.make_repository()
+        stats = repo.gather_stats()
+        self.assertIsInstance(stats, dict)
+        self.assertTrue(stats.has_key("revisions"))

=== modified file 'bzrlib/tests/per_intertree/__init__.py'
--- a/bzrlib/tests/per_intertree/__init__.py	2009-07-10 07:14:02 +0000
+++ b/bzrlib/tests/per_intertree/__init__.py	2009-11-12 23:10:43 +0000
@@ -163,7 +163,8 @@
                  optimiser._matching_from_tree_format,
                  optimiser._matching_to_tree_format,
                  optimiser.make_source_parent_tree_python_dirstate))
-        else:
+        elif (optimiser._matching_from_tree_format is not None and 
+              optimiser._matching_to_tree_format is not None):
             test_intertree_permutations.append(
                 (optimiser.__name__,
                  optimiser,

=== modified file 'bzrlib/tree.py'
--- a/bzrlib/tree.py	2009-11-26 01:42:06 +0000
+++ b/bzrlib/tree.py	2009-11-27 23:21:36 +0000
@@ -851,6 +851,12 @@
     will pass through to InterTree as appropriate.
     """
 
+    # Formats that will be used to test this InterTree. If both are
+    # None, this InterTree will not be tested (e.g. because a complex
+    # setup is required)
+    _matching_from_tree_format = None
+    _matching_to_tree_format = None
+
     _optimisers = []
 
     def _changes_from_entries(self, source_entry, target_entry,




More information about the bazaar-commits mailing list