From 46c9a0df4403266a320059eaa66e7dce7b3d9ac4 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 5 Nov 2009 20:09:35 +0100 Subject: cmd: added clear_cache method now used by test repo decorators to be sure persistent commands are killed before trying to remove the directory. Unfortunately, it still claims someone has opened the file. handle.exe does not show anyone, so what is happening here ? Is it just a windows odity ? If nothing helps I could just keep the temp data, but lets do some more testing first --- test/testlib/helper.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test/testlib/helper.py') diff --git a/test/testlib/helper.py b/test/testlib/helper.py index 27c2b3d9..5599f05e 100644 --- a/test/testlib/helper.py +++ b/test/testlib/helper.py @@ -82,6 +82,7 @@ def with_bare_rw_repo(func): try: return func(self, rw_repo) finally: + rw_repo.git.clear_cache() shutil.rmtree(repo_dir) # END cleanup # END bare repo creator @@ -107,6 +108,7 @@ def with_rw_repo(working_tree_ref): try: return func(self, rw_repo) finally: + rw_repo.git.clear_cache() shutil.rmtree(repo_dir) # END cleanup # END rw repo creator @@ -179,6 +181,8 @@ def with_rw_and_rw_remote_repo(working_tree_ref): try: return func(self, rw_repo, rw_remote_repo) finally: + rw_repo.git.clear_cache() + rw_remote_repo.git.clear_cache() shutil.rmtree(repo_dir) shutil.rmtree(remote_repo_dir) # END cleanup -- cgit v1.2.3 From 555b0efc2c19aa8cf7c548b4097bd20a73f572ca Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 5 Nov 2009 21:20:10 +0100 Subject: repo.clone: Added plenty of special handling to allow drive letters to work as expected. Its quite terrible to see a two-line method inflate to 20 as there is no git-daemon on windows, some tests will not work. The error message has been adjusted to be more precise for the poor people trying to run the tests on windows ( including myself ) --- test/testlib/helper.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/testlib/helper.py') diff --git a/test/testlib/helper.py b/test/testlib/helper.py index 5599f05e..e9a15d5c 100644 --- a/test/testlib/helper.py +++ b/test/testlib/helper.py @@ -176,7 +176,10 @@ def with_rw_and_rw_remote_repo(working_tree_ref): rw_repo.git.ls_remote(d_remote) except GitCommandError,e: print str(e) - raise AssertionError('Please start a git-daemon to run this test, execute: git-daemon "%s"'%tempfile.gettempdir()) + if os.name == 'nt': + raise AssertionError('git-daemon needs to run this test, but windows does not have one. Otherwise, run: git-daemon "%s"'%tempfile.gettempdir()) + else: + raise AssertionError('Please start a git-daemon to run this test, execute: git-daemon "%s"'%tempfile.gettempdir()) try: return func(self, rw_repo, rw_remote_repo) -- cgit v1.2.3 From 179a1dcc65366a70369917d87d00b558a6d0c04d Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 5 Nov 2009 22:24:01 +0100 Subject: helper: repo creation functions now handle errors on windows during os.remove by changing the mode to 777 and delete the file again. Otherwise the whole operation would fail on read-only files. Why is windows as it is ? Why does it do that to me ? --- test/testlib/helper.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'test/testlib/helper.py') diff --git a/test/testlib/helper.py b/test/testlib/helper.py index e9a15d5c..25b183a3 100644 --- a/test/testlib/helper.py +++ b/test/testlib/helper.py @@ -63,7 +63,18 @@ class ListProcessAdapter(object): poll = wait - + +def _rmtree_onerror(osremove, fullpath, exec_info): + """ + Handle the case on windows that read-only files cannot be deleted by + os.remove by setting it to mode 777, then retry deletion. + """ + if os.name != 'nt' or osremove is not os.remove: + raise + + 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 @@ -83,7 +94,7 @@ def with_bare_rw_repo(func): return func(self, rw_repo) finally: rw_repo.git.clear_cache() - shutil.rmtree(repo_dir) + shutil.rmtree(repo_dir, onerror=_rmtree_onerror) # END cleanup # END bare repo creator bare_repo_creator.__name__ = func.__name__ @@ -109,7 +120,7 @@ def with_rw_repo(working_tree_ref): return func(self, rw_repo) finally: rw_repo.git.clear_cache() - shutil.rmtree(repo_dir) + shutil.rmtree(repo_dir, onerror=_rmtree_onerror) # END cleanup # END rw repo creator repo_creator.__name__ = func.__name__ @@ -186,8 +197,8 @@ def with_rw_and_rw_remote_repo(working_tree_ref): finally: rw_repo.git.clear_cache() rw_remote_repo.git.clear_cache() - shutil.rmtree(repo_dir) - shutil.rmtree(remote_repo_dir) + shutil.rmtree(repo_dir, onerror=_rmtree_onerror) + shutil.rmtree(remote_repo_dir, onerror=_rmtree_onerror) # END cleanup # END bare repo creator remote_repo_creator.__name__ = func.__name__ -- cgit v1.2.3 From d2ff5822dbefa1c9c8177cbf9f0879c5cf4efc5c Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 6 Nov 2009 10:34:32 +0100 Subject: Index tests adopted to windows - especially the symlink test needed adjustment, but it works as expected even on systems that do not support symlinks --- test/testlib/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/testlib/helper.py') diff --git a/test/testlib/helper.py b/test/testlib/helper.py index 25b183a3..e33961a7 100644 --- a/test/testlib/helper.py +++ b/test/testlib/helper.py @@ -17,7 +17,7 @@ def fixture_path(name): return os.path.join(test_dir, "fixtures", name) def fixture(name): - return open(fixture_path(name)).read() + return open(fixture_path(name), 'rb').read() def absolute_project_path(): return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) -- cgit v1.2.3