diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/git/test_index.py | 33 | ||||
-rw-r--r-- | test/testlib/helper.py | 13 |
2 files changed, 44 insertions, 2 deletions
diff --git a/test/git/test_index.py b/test/git/test_index.py index a2689f99..7d3f13cd 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -14,10 +14,10 @@ import glob import shutil from stat import * -class TestTree(TestBase): +class TestIndex(TestBase): def __init__(self, *args): - super(TestTree, self).__init__(*args) + super(TestIndex, self).__init__(*args) self._reset_progress() def _assert_fprogress(self, entries): @@ -498,3 +498,32 @@ class TestTree(TestBase): open(fake_symlink_path,'rb').read() == link_target else: assert S_ISLNK(os.lstat(fake_symlink_path)[ST_MODE]) + + # TEST RENAMING + def assert_mv_rval(rval): + for source, dest in rval: + assert not os.path.exists(source) and os.path.exists(dest) + # END for each renamed item + # END move assertion utility + + self.failUnlessRaises(ValueError, index.move, ['just_one_path']) + # file onto existing file + files = ['AUTHORS', 'LICENSE'] + self.failUnlessRaises(GitCommandError, index.move, files) + + # again, with force + assert_mv_rval(index.move(files, force=True)) + + # files into directory - dry run + paths = ['LICENSE', 'VERSION', 'doc'] + rval = index.move(paths, dry_run=True) + assert len(rval) == 2 + assert os.path.exists(paths[0]) + + # again, no dry run + rval = index.move(paths) + assert_mv_rval(rval) + + # dir into dir + rval = index.move(['doc', 'test']) + assert_mv_rval(rval) diff --git a/test/testlib/helper.py b/test/testlib/helper.py index da4a4207..ba748a15 100644 --- a/test/testlib/helper.py +++ b/test/testlib/helper.py @@ -90,6 +90,7 @@ def with_bare_rw_repo(func): def bare_repo_creator(self): repo_dir = tempfile.mktemp("bare_repo") rw_repo = self.rorepo.clone(repo_dir, shared=True, bare=True) + prev_cwd = os.getcwd() try: return func(self, rw_repo) finally: @@ -106,6 +107,9 @@ def with_rw_repo(working_tree_ref): out the working tree at the given working_tree_ref. This repository type is more costly due to the working copy checkout. + + To make working with relative paths easier, the cwd will be set to the working + dir of the repository. """ assert isinstance(working_tree_ref, basestring), "Decorator requires ref name for working tree checkout" def argument_passer(func): @@ -116,9 +120,12 @@ def with_rw_repo(working_tree_ref): rw_repo.head.commit = working_tree_ref rw_repo.head.reference.checkout() + prev_cwd = os.getcwd() + os.chdir(rw_repo.working_dir) try: return func(self, rw_repo) finally: + os.chdir(prev_cwd) rw_repo.git.clear_cache() shutil.rmtree(repo_dir, onerror=_rmtree_onerror) # END cleanup @@ -148,6 +155,8 @@ def with_rw_and_rw_remote_repo(working_tree_ref): def case(self, rw_repo, rw_remote_repo) This setup allows you to test push and pull scenarios and hooks nicely. + + See working dir info in with_rw_repo """ assert isinstance(working_tree_ref, basestring), "Decorator requires ref name for working tree checkout" def argument_passer(func): @@ -192,9 +201,13 @@ def with_rw_and_rw_remote_repo(working_tree_ref): else: raise AssertionError('Please start a git-daemon to run this test, execute: git-daemon "%s"'%tempfile.gettempdir()) + # adjust working dir + prev_cwd = os.getcwd() + os.chdir(rw_repo.working_dir) try: return func(self, rw_repo, rw_remote_repo) finally: + os.chdir(prev_cwd) rw_repo.git.clear_cache() rw_remote_repo.git.clear_cache() shutil.rmtree(repo_dir, onerror=_rmtree_onerror) |