Rev 4757: (Jelmer) Add infrastructure for testing foreign branch in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Mon Oct 19 11:59:23 BST 2009


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

------------------------------------------------------------
revno: 4757 [merge]
revision-id: pqm at pqm.ubuntu.com-20091019105916-6z2jo34eqr6s0008
parent: pqm at pqm.ubuntu.com-20091017222307-4x6xk4tkcp25q2ac
parent: jelmer at samba.org-20091011013123-zbcruv13w8q2h6r5
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2009-10-19 11:59:16 +0100
message:
  (Jelmer) Add infrastructure for testing foreign branch
  	implementations.
added:
  bzrlib/tests/per_foreign_vcs/  foreign-20090804140647-lrnof6q71eti9buc-1
  bzrlib/tests/per_foreign_vcs/__init__.py __init__.py-20090804140647-lrnof6q71eti9buc-2
  bzrlib/tests/per_foreign_vcs/test_branch.py test_branch.py-20090804140930-7hsx6rgekjy0yzjx-1
modified:
  bzrlib/foreign.py              foreign.py-20081112170002-olsxmandkk8qyfuq-1
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
=== modified file 'bzrlib/foreign.py'
--- a/bzrlib/foreign.py	2009-10-06 14:40:37 +0000
+++ b/bzrlib/foreign.py	2009-10-11 01:31:23 +0000
@@ -36,7 +36,7 @@
 """)
 
 class VcsMapping(object):
-    """Describes the mapping between the semantics of Bazaar and a foreign vcs.
+    """Describes the mapping between the semantics of Bazaar and a foreign VCS.
 
     """
     # Whether this is an experimental mapping that is still open to changes.
@@ -122,6 +122,8 @@
 class ForeignVcs(object):
     """A foreign version control system."""
 
+    branch_format = None
+
     def __init__(self, mapping_registry):
         self.mapping_registry = mapping_registry
 

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2009-10-14 08:51:44 +0000
+++ b/bzrlib/tests/__init__.py	2009-10-19 10:59:16 +0000
@@ -3679,6 +3679,7 @@
         'bzrlib.tests.commands',
         'bzrlib.tests.per_branch',
         'bzrlib.tests.per_bzrdir',
+        'bzrlib.tests.per_foreign_vcs',
         'bzrlib.tests.per_interrepository',
         'bzrlib.tests.per_intertree',
         'bzrlib.tests.per_inventory',

=== added directory 'bzrlib/tests/per_foreign_vcs'
=== added file 'bzrlib/tests/per_foreign_vcs/__init__.py'
--- a/bzrlib/tests/per_foreign_vcs/__init__.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/per_foreign_vcs/__init__.py	2009-10-11 01:02:28 +0000
@@ -0,0 +1,47 @@
+# 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 foreign branch implementations.
+
+"""
+
+from bzrlib import (
+    foreign,
+    tests,
+    )
+
+
+def vcs_scenarios():
+    scenarios = []
+    for name, vcs in foreign.foreign_vcs_registry.iteritems():
+        scenarios.append((vcs.__class__.__name__, {
+            "branch_factory": vcs.branch_format.get_foreign_tests_branch_factory(),
+            "branch_format": vcs.branch_format,
+            }))
+    return scenarios
+
+
+def load_tests(standard_tests, module, loader):
+    result = loader.suiteClass()
+    per_vcs_mod_names = [
+        'branch',
+        ]
+    sub_tests = loader.loadTestsFromModuleNames(
+        ['bzrlib.tests.per_foreign_vcs.test_' + name
+         for name in per_vcs_mod_names])
+    tests.multiply_tests(sub_tests, vcs_scenarios(), result)
+    return result

=== added file 'bzrlib/tests/per_foreign_vcs/test_branch.py'
--- a/bzrlib/tests/per_foreign_vcs/test_branch.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/per_foreign_vcs/test_branch.py	2009-10-11 01:20:37 +0000
@@ -0,0 +1,151 @@
+# 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 Branch implementations that use foreign VCS'es."""
+
+
+from bzrlib.errors import (
+    UnstackableBranchFormat,
+    )
+from bzrlib.revision import (
+    NULL_REVISION,
+    )
+from bzrlib.tests import (
+    TestCase,
+    TestCaseWithTransport,
+    )
+
+
+class ForeignBranchFactory(object):
+    """Factory of branches for ForeignBranchTests."""
+
+    def make_empty_branch(self, transport):
+        """Create an empty branch with no commits in it."""
+        raise NotImplementedError(self.make_empty_branch)
+
+    def make_branch(self, transport):
+        """Create *some* branch, may be empty or not."""
+        return self.make_empty_branch(transport)
+
+
+class ForeignBranchTests(TestCaseWithTransport):
+    """Basic tests for foreign branch implementations.
+    
+    These tests mainly make sure that the implementation covers the required 
+    bits of the API and returns reasonable values. 
+    """
+    branch_factory = None # Set to an instance of ForeignBranchFactory by scenario
+
+    def make_empty_branch(self):
+        return self.branch_factory.make_empty_branch(self.get_transport())
+
+    def make_branch(self):
+        return self.branch_factory.make_branch(self.get_transport())
+
+    def test_set_parent(self):
+        """Test that setting the parent works."""
+        branch = self.make_branch()
+        branch.set_parent("foobar")
+
+    def test_break_lock(self):
+        """Test that break_lock() works, even if it is a no-op."""
+        branch = self.make_branch()
+        branch.break_lock()
+
+    def test_set_push_location(self):
+        """Test that setting the push location works."""
+        branch = self.make_branch()
+        branch.set_push_location("http://bar/bloe")
+
+    def test_repr_type(self):
+        branch = self.make_branch()
+        self.assertIsInstance(repr(branch), str)
+
+    def test_get_parent(self):
+        """Test that getting the parent location works, and returns None."""
+        # TODO: Allow this to be non-None when foreign branches add support 
+        #       for storing this URL.
+        branch = self.make_branch()
+        self.assertIs(None, branch.get_parent())
+
+    def test_get_push_location(self):
+        """Test that getting the push location works, and returns None."""
+        # TODO: Allow this to be non-None when foreign branches add support 
+        #       for storing this URL.
+        branch = self.make_branch()
+        self.assertIs(None, branch.get_push_location())
+
+    def test_attributes(self):
+        """Check that various required attributes are present."""
+        branch = self.make_branch()
+        self.assertIsNot(None, getattr(branch, "repository", None))
+        self.assertIsNot(None, getattr(branch, "mapping", None))
+        self.assertIsNot(None, getattr(branch, "_format", None))
+        self.assertIsNot(None, getattr(branch, "base", None))
+
+    def test__get_nick(self):
+        """Make sure _get_nick is implemented and returns a string."""
+        branch = self.make_branch()
+        self.assertIsInstance(branch._get_nick(local=False), str)
+        self.assertIsInstance(branch._get_nick(local=True), str)
+
+    def test_null_revid_revno(self):
+        """null: should return revno 0."""
+        branch = self.make_branch()
+        self.assertEquals(0, branch.revision_id_to_revno(NULL_REVISION))
+
+    def test_get_stacked_on_url(self):
+        """Test that get_stacked_on_url() behaves as expected.
+
+        Inter-Format stacking doesn't work yet, so all foreign implementations
+        should raise UnstackableBranchFormat at the moment.
+        """
+        branch = self.make_branch()
+        self.assertRaises(UnstackableBranchFormat, 
+                          branch.get_stacked_on_url)
+
+    def test_get_physical_lock_status(self):
+        branch = self.make_branch()
+        self.assertFalse(branch.get_physical_lock_status())
+
+    def test_last_revision_empty_branch(self):
+        branch = self.make_empty_branch()
+        self.assertEquals(NULL_REVISION, branch.last_revision())
+        self.assertEquals(0, branch.revno())
+        self.assertEquals((0, NULL_REVISION), branch.last_revision_info())
+
+
+class ForeignBranchFormatTests(TestCase):
+    """Basic tests for foreign branch format objects."""
+
+    branch_format = None # Set to a BranchFormat instance by adapter
+
+    def test_initialize(self):
+        """Test this format is not initializable.
+        
+        Remote branches may be initializable on their own, but none currently
+        support living in .bzr/branch.
+        """
+        self.assertRaises(NotImplementedError, self.branch_format.initialize, None)
+
+    def test_get_format_description_type(self):
+        self.assertIsInstance(self.branch_format.get_format_description(), str)
+
+    def test_network_name(self):
+        self.assertIsInstance(self.branch_format.network_name(), str)
+
+




More information about the bazaar-commits mailing list