You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by rd...@apache.org on 2010/05/30 20:17:58 UTC
svn commit: r949551 - in
/subversion/trunk/subversion/bindings/swig/python/tests: client.py utils.py
Author: rdonch
Date: Sun May 30 18:17:57 2010
New Revision: 949551
URL: http://svn.apache.org/viewvc?rev=949551&view=rev
Log:
Move temporary dir creation/cleanup code from r879456 into its own module,
and add a function for repository creation.
* subversion/bindings/swig/python/tests/utils.py: New file.
* subversion/bindings/swig/python/tests/client.py:
(SubversionClientTestCase.allocate_temp_dir): Remove.
(SubversionClientTestCase.setUp),
(SubversionClientTestCase.tearDown),
(SubversionClientTestCase.test_checkout),
(SubversionClientTestCase.test_url_from_path),
(SubversionClientTestCase.test_uuid_from_path),
(SubversionClientTestCase.test_info_file),
(SubversionClientTestCase.test_merge_peg3): Defer all temporary directory
creation and cleanup to utils.Temper.
Added:
subversion/trunk/subversion/bindings/swig/python/tests/utils.py (with props)
Modified:
subversion/trunk/subversion/bindings/swig/python/tests/client.py
Modified: subversion/trunk/subversion/bindings/swig/python/tests/client.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/tests/client.py?rev=949551&r1=949550&r2=949551&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/tests/client.py (original)
+++ subversion/trunk/subversion/bindings/swig/python/tests/client.py Sun May 30 18:17:57 2010
@@ -18,7 +18,7 @@
# under the License.
#
#
-import unittest, os, weakref, tempfile, setup_path
+import unittest, os, weakref, setup_path, utils
from svn import core, client, wc
@@ -70,19 +70,13 @@ class SubversionClientTestCase(unittest.
self.client_ctx.auth_baton = core.svn_auth_open(providers)
- self.cleanup_dirs = []
+ self.temper = utils.Temper()
def tearDown(self):
# We have to free client_ctx first, since it may be holding handles
# to WC DBs
del self.client_ctx
- for directory in self.cleanup_dirs:
- core.svn_io_remove_dir(directory)
-
- def allocate_temp_dir(self, suffix = ""):
- temp_dir_name = core.svn_dirent_internal_style(tempfile.mkdtemp(suffix))
- self.cleanup_dirs.append(temp_dir_name)
- return temp_dir_name
+ self.temper.cleanup()
def testBatonPlay(self):
"""Test playing with C batons"""
@@ -165,7 +159,7 @@ class SubversionClientTestCase(unittest.
rev = core.svn_opt_revision_t()
rev.kind = core.svn_opt_revision_head
- path = self.allocate_temp_dir('-checkout')
+ path = self.temper.alloc_empty_dir('-checkout')
self.assertRaises(ValueError, client.checkout2,
REPOS_URL, path, None, None, True, True,
@@ -257,7 +251,7 @@ class SubversionClientTestCase(unittest.
rev = core.svn_opt_revision_t()
rev.kind = core.svn_opt_revision_head
- path = self.allocate_temp_dir('-url_from_path')
+ path = self.temper.alloc_empty_dir('-url_from_path')
client.checkout2(REPOS_URL, path, rev, rev, True, True,
self.client_ctx)
@@ -269,7 +263,7 @@ class SubversionClientTestCase(unittest.
rev = core.svn_opt_revision_t()
rev.kind = core.svn_opt_revision_head
- path = self.allocate_temp_dir('-uuid_from_path')
+ path = self.temper.alloc_empty_dir('-uuid_from_path')
client.checkout2(REPOS_URL, path, rev, rev, True, True,
self.client_ctx)
@@ -294,7 +288,7 @@ class SubversionClientTestCase(unittest.
# in the repository.
rev = core.svn_opt_revision_t()
rev.kind = core.svn_opt_revision_head
- wc_path = self.allocate_temp_dir('-info_file')
+ wc_path = self.temper.alloc_empty_dir('-info_file')
client.checkout2(REPOS_URL, wc_path, rev, rev, True, True,
self.client_ctx)
@@ -344,7 +338,7 @@ class SubversionClientTestCase(unittest.
"""Test svn_client_merge_peg3."""
head = core.svn_opt_revision_t()
head.kind = core.svn_opt_revision_head
- wc_path = self.allocate_temp_dir('-merge_peg3')
+ wc_path = self.temper.alloc_empty_dir('-merge_peg3')
client.checkout3(REPOS_URL, wc_path, head, head, core.svn_depth_infinity,
True, False, self.client_ctx)
Added: subversion/trunk/subversion/bindings/swig/python/tests/utils.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/tests/utils.py?rev=949551&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/tests/utils.py (added)
+++ subversion/trunk/subversion/bindings/swig/python/tests/utils.py Sun May 30 18:17:57 2010
@@ -0,0 +1,69 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+import tempfile, urllib
+from svn import core, repos
+
+try:
+ from io import StringIO
+except ImportError:
+ from StringIO import StringIO
+
+class Temper(object):
+ """Class to simplify allocation and cleanup of dummy Subversion
+ structures, such as repositories and working copies."""
+
+ def __init__(self):
+ self._cleanup_list = []
+
+ def __del__(self):
+ self.cleanup()
+
+ def cleanup(self):
+ """Destroy everything that was allocated so far."""
+ for (target, clean_func) in self._cleanup_list:
+ clean_func(target)
+ self._cleanup_list = []
+
+ def alloc_empty_dir(self, suffix = ""):
+ """Create an empty temporary directory. Returns its full path
+ in canonical internal form."""
+ temp_dir_name = core.svn_dirent_internal_style(tempfile.mkdtemp(suffix))
+ self._cleanup_list.append((temp_dir_name, core.svn_io_remove_dir))
+ return temp_dir_name
+
+ def alloc_repo(self, suffix = ""):
+ """Creates an empty repository. Returns a tuple of its handle, path and
+ file: URI in canonical internal form."""
+ temp_path = tempfile.mkdtemp(suffix)
+ repo_path = core.svn_dirent_internal_style(temp_path)
+ repo_uri = core.svn_uri_canonicalize(Temper._file_uri_for_path(temp_path))
+ handle = repos.create(repo_path, None, None, None, None)
+ self._cleanup_list.append((repo_path, repos.svn_repos_delete))
+ return (handle, repo_path, repo_uri)
+
+ @classmethod
+ def _file_uri_for_path(cls, path):
+ uri_path = urllib.pathname2url(path)
+
+ # pathname2url claims to return the path part of the URI, but on Windows
+ # it returns both the authority and path parts for no reason, which
+ # means we have to trim the leading slashes to "normalize" the result.
+ return 'file:///' + uri_path.lstrip('/')
Propchange: subversion/trunk/subversion/bindings/swig/python/tests/utils.py
------------------------------------------------------------------------------
svn:eol-style = native