Add function for changing svn revision properties.
[jelmer/subvertpy.git] / tests / __init__.py
index 6ac9a860c7914d7bb745c055115ed784aef8daed..01d79da287216de0c7687433f139953d6e29d6f9 100644 (file)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-import svn.repos
+"""Tests for the bzr-svn plugin."""
+
 import os
 import bzrlib
 from bzrlib import osutils
 from bzrlib.bzrdir import BzrDir
-from bzrlib.tests import TestCaseInTempDir
+from bzrlib.tests import TestCaseInTempDir, TestSkipped
 from bzrlib.trace import mutter
+from bzrlib.workingtree import WorkingTree
 
 RENAMES = False
 
 import svn.repos, svn.wc
+from bzrlib.plugins.svn.errors import NoCheckoutSupport
 
 class TestCaseWithSubversionRepository(TestCaseInTempDir):
     """A test case that provides the ability to build Subversion 
@@ -39,7 +42,7 @@ class TestCaseWithSubversionRepository(TestCaseInTempDir):
     def log_message_func(self, items, pool):
         return self.next_message
 
-    def make_repository(self, relpath):
+    def make_repository(self, relpath, allow_revprop_changes=True):
         """Create a repository.
 
         :return: Handle to the repository.
@@ -47,13 +50,12 @@ class TestCaseWithSubversionRepository(TestCaseInTempDir):
         abspath = os.path.join(self.test_dir, relpath)
         repos_url = "file://%s" % abspath
 
-        repos = svn.repos.create(abspath, '', '', None, None)
-
-        revprop_hook = os.path.join(abspath, "hooks", "pre-revprop-change")
-
-        open(revprop_hook, 'w').write("#!/bin/sh")
+        svn.repos.create(abspath, '', '', None, None)
 
-        os.chmod(revprop_hook, os.stat(revprop_hook).st_mode | 0111)
+        if allow_revprop_changes:
+            revprop_hook = os.path.join(abspath, "hooks", "pre-revprop-change")
+            open(revprop_hook, 'w').write("#!/bin/sh")
+            os.chmod(revprop_hook, os.stat(revprop_hook).st_mode | 0111)
 
         return repos_url
 
@@ -76,7 +78,11 @@ class TestCaseWithSubversionRepository(TestCaseInTempDir):
 
         repos_url = self.make_repository(repos_path)
 
-        return self.open_local_bzrdir(repos_url, relpath)
+        try:
+            return self.open_local_bzrdir(repos_url, relpath)
+        except NoCheckoutSupport:
+            raise TestSkipped('No Checkout Support')
+
 
     def make_checkout(self, repos_url, relpath):
         rev = svn.core.svn_opt_revision_t()
@@ -85,6 +91,35 @@ class TestCaseWithSubversionRepository(TestCaseInTempDir):
         svn.client.checkout2(repos_url, relpath, 
                 rev, rev, True, False, self.client_ctx)
 
+    @staticmethod
+    def create_checkout(branch, path, revision_id=None, lightweight=False):
+        try:
+            return branch.create_checkout(path, revision_id=revision_id,
+                                          lightweight=lightweight)
+        except NoCheckoutSupport:
+            raise TestSkipped('No Checkout Support')
+
+    @staticmethod
+    def open_checkout(url):
+        try:
+            return WorkingTree.open(url)
+        except NoCheckoutSupport:
+           raise TestSkipped('No Checkout Support')
+
+    @staticmethod
+    def open_checkout_bzrdir(url):
+        try:
+            return BzrDir.open(url)
+        except NoCheckoutSupport:
+           raise TestSkipped('No Checkout Support')
+
+    @staticmethod
+    def create_branch_convenience(url):
+        try:
+            return BzrDir.create_branch_convenience(url)
+        except NoCheckoutSupport:
+           raise TestSkipped('No Checkout Support')
+
     def client_set_prop(self, path, name, value):
         if value is None:
             value = ""
@@ -119,8 +154,9 @@ class TestCaseWithSubversionRepository(TestCaseInTempDir):
         olddir = os.path.abspath('.')
         self.next_message = message
         os.chdir(dir)
-        info = svn.client.commit3(["."], recursive, False, self.client_ctx)
+        info = svn.client.commit2(["."], recursive, False, self.client_ctx)
         os.chdir(olddir)
+        assert info is not None
         return (info.revision, info.date, info.author)
 
     def client_add(self, relpath, recursive=True):
@@ -130,6 +166,27 @@ class TestCaseWithSubversionRepository(TestCaseInTempDir):
         """
         svn.client.add3(relpath, recursive, False, False, self.client_ctx)
 
+    def revnum_to_opt_rev(self, revnum):
+        rev = svn.core.svn_opt_revision_t()
+        if revnum is None:
+            rev.kind = svn.core.svn_opt_revision_head
+        else:
+            rev.kind = svn.core.svn_opt_revision_number
+            rev.value.number = revnum
+        return rev
+
+    def client_log(self, path, start_revnum=None, stop_revnum=None):
+        ret = {}
+        def rcvr(orig_paths, rev, author, date, message, pool):
+            ret[rev] = (orig_paths, author, date, message)
+        svn.client.log([path], self.revnum_to_opt_rev(start_revnum),
+                       self.revnum_to_opt_rev(stop_revnum),
+                       True,
+                       True,
+                       rcvr,
+                       self.client_ctx)
+        return ret
+
     def client_delete(self, relpath):
         """Remove specified files from working copy.
 
@@ -180,14 +237,16 @@ class TestCaseWithSubversionRepository(TestCaseInTempDir):
 
         return BzrDir.open("svn+%s" % repos_url)
 
-    def make_client(self, repospath, clientpath):
+    def make_client(self, repospath, clientpath, allow_revprop_changes=True):
         """Create a repository and a checkout. Return the checkout.
 
         :param relpath: Optional relpath to check out if not the full 
             repository.
+        :param clientpath: Path to checkout
         :return: Repository URL.
         """
-        repos_url = self.make_repository(repospath)
+        repos_url = self.make_repository(repospath, 
+            allow_revprop_changes=allow_revprop_changes)
         self.make_checkout(repos_url, clientpath)
         return repos_url
 
@@ -209,7 +268,7 @@ class TestCaseWithSubversionRepository(TestCaseInTempDir):
 
 
 def test_suite():
-    from unittest import TestSuite, TestLoader
+    from unittest import TestSuite
     
     from bzrlib.tests import TestUtil
 
@@ -222,17 +281,22 @@ def test_suite():
             'test_branchprops', 
             'test_checkout',
             'test_commit',
+            'test_config',
             'test_convert',
             'test_errors',
+            'test_fetch',
             'test_fileids', 
             'test_logwalker',
+            'test_push',
             'test_radir',
             'test_repos', 
+            'test_revids',
             'test_scheme', 
             'test_transport',
             'test_tree',
             'test_upgrade',
-            'test_workingtree']
+            'test_workingtree',
+            'test_blackbox']
     suite.addTest(loader.loadTestsFromModuleNames(["%s.%s" % (__name__, i) for i in testmod_names]))
 
     return suite