summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2010-11-15 19:03:53 +0100
committerSebastian Thiel <byronimo@gmail.com>2010-11-15 19:03:53 +0100
commit624556eae1c292a1dc283d9dca1557e28abe8ee3 (patch)
treea90ef1572044f113d3dae587f67f6ca51593ba07 /test
parentf97653aa06cf84bcf160be3786b6fce49ef52961 (diff)
downloadgitpython-624556eae1c292a1dc283d9dca1557e28abe8ee3.tar.gz
Optimized test-decorators, by completely removing with_bare_rw_repo, which was mainly copy-paste from with_rw_repo, what a shame
Diffstat (limited to 'test')
-rw-r--r--test/git/test_base.py2
-rw-r--r--test/git/test_commit.py2
-rw-r--r--test/git/test_remote.py2
-rw-r--r--test/git/test_repo.py2
-rw-r--r--test/git/test_submodule.py2
-rw-r--r--test/git/test_tree.py2
-rw-r--r--test/testlib/helper.py53
7 files changed, 22 insertions, 43 deletions
diff --git a/test/git/test_base.py b/test/git/test_base.py
index db13feae..25d1e4e9 100644
--- a/test/git/test_base.py
+++ b/test/git/test_base.py
@@ -83,7 +83,7 @@ class TestBase(TestBase):
# objects must be resolved to shas so they compare equal
assert self.rorepo.head.reference.object == self.rorepo.active_branch.object
- @with_bare_rw_repo
+ @with_rw_repo('HEAD', bare=True)
def test_with_bare_rw_repo(self, bare_rw_repo):
assert bare_rw_repo.config_reader("repository").getboolean("core", "bare")
assert os.path.isfile(os.path.join(bare_rw_repo.git_dir,'HEAD'))
diff --git a/test/git/test_commit.py b/test/git/test_commit.py
index 2692938f..c3ce5c92 100644
--- a/test/git/test_commit.py
+++ b/test/git/test_commit.py
@@ -237,7 +237,7 @@ class TestCommit(TestBase):
name_rev = self.rorepo.head.commit.name_rev
assert isinstance(name_rev, basestring)
- @with_bare_rw_repo
+ @with_rw_repo('HEAD', bare=True)
def test_serialization(self, rwrepo):
# create all commits of our repo
assert_commit_serialization(rwrepo, '0.1.6')
diff --git a/test/git/test_remote.py b/test/git/test_remote.py
index 1db4bc32..c52f907e 100644
--- a/test/git/test_remote.py
+++ b/test/git/test_remote.py
@@ -422,7 +422,7 @@ class TestRemote(TestBase):
origin = rw_repo.remote('origin')
assert origin == rw_repo.remotes.origin
- @with_bare_rw_repo
+ @with_rw_repo('HEAD', bare=True)
def test_creation_and_removal(self, bare_rw_repo):
new_name = "test_new_one"
arg_list = (new_name, "git@server:hello.git")
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index 063b5dff..3a59f05e 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -558,7 +558,7 @@ class TestRepo(TestBase):
def test_submodules(self):
assert len(self.rorepo.submodules) == 1 # non-recursive
- assert len(self.rorepo.list_submodules(recursive=True)) == 2
+ assert len(list(self.rorepo.iter_submodules())) == 2
assert isinstance(self.rorepo.submodule("lib/git/ext/gitdb"), Submodule)
self.failUnlessRaises(ValueError, self.rorepo.submodule, "doesn't exist")
diff --git a/test/git/test_submodule.py b/test/git/test_submodule.py
index 2ca0b269..ac179c22 100644
--- a/test/git/test_submodule.py
+++ b/test/git/test_submodule.py
@@ -105,7 +105,7 @@ class TestSubmodule(TestBase):
def test_base_rw(self, rwrepo):
self._do_base_tests(rwrepo)
- @with_bare_rw_repo
+ @with_rw_repo(k_subm_current, bare=True)
def test_base_bare(self, rwrepo):
self._do_base_tests(rwrepo)
diff --git a/test/git/test_tree.py b/test/git/test_tree.py
index d08999bd..18688424 100644
--- a/test/git/test_tree.py
+++ b/test/git/test_tree.py
@@ -102,6 +102,8 @@ class TestTree(TestBase):
assert isinstance(obj, (Blob, Tree))
all_items.append(obj)
# END for each object
+ assert all_items == root.list_traverse()
+
# limit recursion level to 0 - should be same as default iteration
assert all_items
assert 'CHANGES' in root
diff --git a/test/testlib/helper.py b/test/testlib/helper.py
index b5b6fad7..c79ecaa1 100644
--- a/test/testlib/helper.py
+++ b/test/testlib/helper.py
@@ -14,6 +14,11 @@ import cStringIO
GIT_REPO = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
+__all__ = (
+ 'fixture_path', 'fixture', 'absolute_project_path', 'StringProcessAdapter',
+ 'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase', 'GIT_REPO'
+ )
+
#{ Routines
def fixture_path(name):
@@ -58,41 +63,7 @@ def _rmtree_onerror(osremove, fullpath, exec_info):
os.chmod(fullpath, 0777)
os.remove(fullpath)
-def with_bare_rw_repo(func):
- """
- Decorator providing a specially made read-write repository to the test case
- decorated with it. The test case requires the following signature::
- def case(self, rw_repo)
-
- The rwrepo will be a bare clone or the types rorepo. Once the method finishes,
- it will be removed completely.
-
- Use this if you want to make purely index based adjustments, change refs, create
- heads, generally operations that do not need a working tree."""
- def bare_repo_creator(self):
- repo_dir = tempfile.mktemp("bare_repo_%s" % func.__name__)
- rw_repo = self.rorepo.clone(repo_dir, shared=True, bare=True)
- prev_cwd = os.getcwd()
- try:
- try:
- return func(self, rw_repo)
- except:
- # assure we keep the repo for debugging
- print >> sys.stderr, "Keeping bare repo after failure: %s" % repo_dir
- repo_dir = None
- raise
- # END handle exceptions
- finally:
- rw_repo.git.clear_cache()
- if repo_dir is not None:
- shutil.rmtree(repo_dir, onerror=_rmtree_onerror)
- # END remove repo dir
- # END cleanup
- # END bare repo creator
- bare_repo_creator.__name__ = func.__name__
- return bare_repo_creator
-
-def with_rw_repo(working_tree_ref):
+def with_rw_repo(working_tree_ref, bare=False):
"""
Same as with_bare_repo, but clones the rorepo as non-bare repository, checking
out the working tree at the given working_tree_ref.
@@ -105,11 +76,17 @@ def with_rw_repo(working_tree_ref):
assert isinstance(working_tree_ref, basestring), "Decorator requires ref name for working tree checkout"
def argument_passer(func):
def repo_creator(self):
- repo_dir = tempfile.mktemp("non_bare_%s" % func.__name__)
- rw_repo = self.rorepo.clone(repo_dir, shared=True, bare=False, n=True)
+ prefix = 'non_'
+ if bare:
+ prefix = ''
+ #END handle prefix
+ repo_dir = tempfile.mktemp("%sbare_%s" % (prefix, func.__name__))
+ rw_repo = self.rorepo.clone(repo_dir, shared=True, bare=bare, n=True)
rw_repo.head.commit = rw_repo.commit(working_tree_ref)
- rw_repo.head.reference.checkout()
+ if not bare:
+ rw_repo.head.reference.checkout()
+ # END handle checkout
prev_cwd = os.getcwd()
os.chdir(rw_repo.working_dir)