| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 434505f commit 137ee6e
14 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1013,6 +1013,10 @@ def clear_cache(self): | |||
| 1013 | 1013 | Currently persistent commands will be interrupted. | |
| 1014 | 1014 | ||
| 1015 | 1015 | :return: self""" | |
| 1016 | + for cmd in (self.cat_file_all, self.cat_file_header): | ||
| 1017 | + if cmd: | ||
| 1018 | + cmd.__del__() | ||
| 1019 | + | ||
| 1016 | 1020 | self.cat_file_all = None | |
| 1017 | 1021 | self.cat_file_header = None | |
| 1018 | 1022 | return self | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,15 +4,16 @@ | |||
| 4 | 4 | # This module is part of GitPython and is released under | |
| 5 | 5 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php | |
| 6 | 6 | from __future__ import print_function | |
| 7 | + | ||
| 7 | 8 | import os | |
| 8 | 9 | from unittest import TestCase | |
| 9 | 10 | import time | |
| 10 | 11 | import tempfile | |
| 11 | - import shutil | ||
| 12 | 12 | import io | |
| 13 | 13 | import logging | |
| 14 | 14 | ||
| 15 | 15 | from git import Repo, Remote, GitCommandError, Git | |
| 16 | + from git.util import rmtree | ||
| 16 | 17 | from git.compat import string_types, is_win | |
| 17 | 18 | import textwrap | |
| 18 | 19 | ||
@@ -23,7 +24,8 @@ | |||
| 23 | 24 | ||
| 24 | 25 | __all__ = ( | |
| 25 | 26 | 'fixture_path', 'fixture', 'absolute_project_path', 'StringProcessAdapter', | |
| 26 | - 'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase', 'GIT_REPO', 'GIT_DAEMON_PORT' | ||
| 27 | + 'with_rw_directory', 'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase', | ||
| 28 | + 'GIT_REPO', 'GIT_DAEMON_PORT' | ||
| 27 | 29 | ) | |
| 28 | 30 | ||
| 29 | 31 | log = logging.getLogger('git.util') | |
@@ -79,16 +81,31 @@ def _mktemp(*args): | |||
| 79 | 81 | return tdir | |
| 80 | 82 | ||
| 81 | 83 | ||
| 82 | - def _rmtree_onerror(osremove, fullpath, exec_info): | ||
| 83 | - """ | ||
| 84 | - Handle the case on windows that read-only files cannot be deleted by | ||
| 85 | - os.remove by setting it to mode 777, then retry deletion. | ||
| 86 | - """ | ||
| 87 | - if is_win or osremove is not os.remove: | ||
| 88 | - raise | ||
| 84 | + def with_rw_directory(func): | ||
| 85 | + """Create a temporary directory which can be written to, remove it if the | ||
| 86 | + test succeeds, but leave it otherwise to aid additional debugging""" | ||
| 89 | 87 | ||
| 90 | - os.chmod(fullpath, 0o777) | ||
| 91 | - os.remove(fullpath) | ||
| 88 | + def wrapper(self): | ||
| 89 | + path = tempfile.mktemp(prefix=func.__name__) | ||
| 90 | + os.mkdir(path) | ||
| 91 | + keep = False | ||
| 92 | + try: | ||
| 93 | + try: | ||
| 94 | + return func(self, path) | ||
| 95 | + except Exception: | ||
| 96 | + log.info.write("Test %s.%s failed, output is at %r\n", | ||
| 97 | + type(self).__name__, func.__name__, path) | ||
| 98 | + keep = True | ||
| 99 | + raise | ||
| 100 | + finally: | ||
| 101 | + # Need to collect here to be sure all handles have been closed. It appears | ||
| 102 | + # a windows-only issue. In fact things should be deleted, as well as | ||
| 103 | + # memory maps closed, once objects go out of scope. For some reason | ||
| 104 | + # though this is not the case here unless we collect explicitly. | ||
| 105 | + import gc | ||
| 106 | + gc.collect() | ||
| 107 | + if not keep: | ||
| 108 | + rmtree(path) | ||
| 92 | 109 | ||
| 93 | 110 | ||
| 94 | 111 | def with_rw_repo(working_tree_ref, bare=False): | |
@@ -129,8 +146,11 @@ def repo_creator(self): | |||
| 129 | 146 | finally: | |
| 130 | 147 | os.chdir(prev_cwd) | |
| 131 | 148 | rw_repo.git.clear_cache() | |
| 149 | + rw_repo = None | ||
| 150 | + import gc | ||
| 151 | + gc.collect() | ||
| 132 | 152 | if repo_dir is not None: | |
| 133 | - shutil.rmtree(repo_dir, onerror=_rmtree_onerror) | ||
| 153 | + rmtree(repo_dir) | ||
| 134 | 154 | # END rm test repo if possible | |
| 135 | 155 | # END cleanup | |
| 136 | 156 | # END rw repo creator | |
@@ -279,14 +299,15 @@ def remote_repo_creator(self): | |||
| 279 | 299 | if gd is not None: | |
| 280 | 300 | gd.proc.kill() | |
| 281 | 301 | ||
| 282 | - import gc | ||
| 283 | - gc.collect() | ||
| 284 | 302 | rw_repo.git.clear_cache() | |
| 285 | 303 | rw_remote_repo.git.clear_cache() | |
| 304 | + rw_repo = rw_remote_repo = None | ||
| 305 | + import gc | ||
| 306 | + gc.collect() | ||
| 286 | 307 | if repo_dir: | |
| 287 | - shutil.rmtree(repo_dir, onerror=_rmtree_onerror) | ||
| 308 | + rmtree(repo_dir) | ||
| 288 | 309 | if remote_repo_dir: | |
| 289 | - shutil.rmtree(remote_repo_dir, onerror=_rmtree_onerror) | ||
| 310 | + rmtree(remote_repo_dir) | ||
| 290 | 311 | ||
| 291 | 312 | if gd is not None: | |
| 292 | 313 | gd.proc.wait() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,6 @@ | |||
| 4 | 4 | TestBase | |
| 5 | 5 | ) | |
| 6 | 6 | from gitdb.test.lib import skip_on_travis_ci | |
| 7 | - import shutil | ||
| 8 | 7 | import tempfile | |
| 9 | 8 | import logging | |
| 10 | 9 | ||
@@ -16,6 +15,7 @@ | |||
| 16 | 15 | from git import ( | |
| 17 | 16 | Repo | |
| 18 | 17 | ) | |
| 18 | + from git.util import rmtree | ||
| 19 | 19 | ||
| 20 | 20 | #{ Invvariants | |
| 21 | 21 | k_env_git_repo = "GIT_PYTHON_TEST_GIT_REPO_BASE" | |
@@ -86,7 +86,7 @@ def setUp(self): | |||
| 86 | 86 | def tearDown(self): | |
| 87 | 87 | super(TestBigRepoRW, self).tearDown() | |
| 88 | 88 | if self.gitrwrepo is not None: | |
| 89 | - shutil.rmtree(self.gitrwrepo.working_dir) | ||
| 89 | + rmtree(self.gitrwrepo.working_dir) | ||
| 90 | 90 | self.gitrwrepo.git.clear_cache() | |
| 91 | 91 | self.gitrwrepo = None | |
| 92 | 92 | self.puregitrwrepo.git.clear_cache() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,7 @@ | |||
| 19 | 19 | Actor, | |
| 20 | 20 | ) | |
| 21 | 21 | from gitdb import IStream | |
| 22 | - from gitdb.test.lib import with_rw_directory | ||
| 22 | + from git.test.lib import with_rw_directory | ||
| 23 | 23 | from git.compat import ( | |
| 24 | 24 | string_types, | |
| 25 | 25 | text_type | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ | |||
| 9 | 9 | fixture_path, | |
| 10 | 10 | assert_equal, | |
| 11 | 11 | ) | |
| 12 | - from gitdb.test.lib import with_rw_directory | ||
| 12 | + from git.test.lib import with_rw_directory | ||
| 13 | 13 | from git import ( | |
| 14 | 14 | GitConfigParser | |
| 15 | 15 | ) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ) | |
| 17 | 17 | ||
| 18 | - from gitdb.test.lib import with_rw_directory | ||
| 18 | + from git.test.lib import with_rw_directory | ||
| 19 | 19 | ||
| 20 | 20 | from git import ( | |
| 21 | 21 | Repo, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ | |||
| 7 | 7 | import os | |
| 8 | 8 | ||
| 9 | 9 | from git.test.lib import TestBase | |
| 10 | - from gitdb.test.lib import with_rw_directory | ||
| 10 | + from git.test.lib.helper import with_rw_directory | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | class Tutorials(TestBase): | |
@@ -210,7 +210,7 @@ def test_references_and_objects(self, rw_dir): | |||
| 210 | 210 | master = head.reference # retrieve the reference the head points to | |
| 211 | 211 | master.commit # from here you use it as any other reference | |
| 212 | 212 | # ![3-test_references_and_objects] | |
| 213 | - | ||
| 213 | + # | ||
| 214 | 214 | # [4-test_references_and_objects] | |
| 215 | 215 | log = master.log() | |
| 216 | 216 | log[0] # first (i.e. oldest) reflog entry | |
@@ -448,6 +448,8 @@ def test_references_and_objects(self, rw_dir): | |||
| 448 | 448 | git.for_each_ref() # '-' becomes '_' when calling it | |
| 449 | 449 | # ![31-test_references_and_objects] | |
| 450 | 450 | ||
| 451 | + repo.git.clear_cache() | ||
| 452 | + | ||
| 451 | 453 | def test_submodules(self): | |
| 452 | 454 | # [1-test_submodules] | |
| 453 | 455 | repo = self.rorepo | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,7 @@ | |||
| 24 | 24 | Repo, | |
| 25 | 25 | cmd | |
| 26 | 26 | ) | |
| 27 | - from gitdb.test.lib import with_rw_directory | ||
| 27 | + from git.test.lib import with_rw_directory | ||
| 28 | 28 | ||
| 29 | 29 | from git.compat import PY3, is_darwin | |
| 30 | 30 | ||
@@ -174,7 +174,7 @@ def test_insert_after_kwarg_raises(self): | |||
| 174 | 174 | ||
| 175 | 175 | def test_env_vars_passed_to_git(self): | |
| 176 | 176 | editor = 'non_existant_editor' | |
| 177 | - with mock.patch.dict('os.environ', {'GIT_EDITOR': editor}): | ||
| 177 | + with mock.patch.dict('os.environ', {'GIT_EDITOR': editor}): # @UndefinedVariable | ||
| 178 | 178 | self.assertEqual(self.git.var("GIT_EDITOR"), editor) | |
| 179 | 179 | ||
| 180 | 180 | @with_rw_directory | |
@@ -203,7 +203,7 @@ def test_environment(self, rw_dir): | |||
| 203 | 203 | stream.write("#!/usr/bin/env sh\n" + | |
| 204 | 204 | "echo FOO\n") | |
| 205 | 205 | stream.close() | |
| 206 | - os.chmod(path, 0o555) | ||
| 206 | + os.chmod(path, 0o777) | ||
| 207 | 207 | ||
| 208 | 208 | rw_repo = Repo.init(os.path.join(rw_dir, 'repo')) | |
| 209 | 209 | remote = rw_repo.create_remote('ssh-origin', "ssh://git@server/foo") | |
@@ -220,9 +220,6 @@ def test_environment(self, rw_dir): | |||
| 220 | 220 | self.assertEqual(err.status, 128) | |
| 221 | 221 | else: | |
| 222 | 222 | self.assertIn('FOO', str(err)) | |
| 223 | - # end | ||
| 224 | - # end | ||
| 225 | - # end if select.poll exists | ||
| 226 | 223 | ||
| 227 | 224 | def test_handle_process_output(self): | |
| 228 | 225 | from git.cmd import handle_process_output | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ | |||
| 11 | 11 | fixture, | |
| 12 | 12 | with_rw_repo | |
| 13 | 13 | ) | |
| 14 | - from git.util import Actor | ||
| 14 | + from git.util import Actor, rmtree | ||
| 15 | 15 | from git.exc import ( | |
| 16 | 16 | HookExecutionError, | |
| 17 | 17 | InvalidGitRepositoryError | |
@@ -32,7 +32,6 @@ | |||
| 32 | 32 | import os | |
| 33 | 33 | import sys | |
| 34 | 34 | import tempfile | |
| 35 | - import shutil | ||
| 36 | 35 | from stat import ( | |
| 37 | 36 | S_ISLNK, | |
| 38 | 37 | ST_MODE | |
@@ -46,7 +45,7 @@ | |||
| 46 | 45 | IndexEntry | |
| 47 | 46 | ) | |
| 48 | 47 | from git.index.fun import hook_path | |
| 49 | - from gitdb.test.lib import with_rw_directory | ||
| 48 | + from git.test.lib import with_rw_directory | ||
| 50 | 49 | ||
| 51 | 50 | ||
| 52 | 51 | class TestIndex(TestBase): | |
@@ -387,7 +386,7 @@ def test_index_file_diffing(self, rw_repo): | |||
| 387 | 386 | assert not open(test_file, 'rb').read().endswith(append_data) | |
| 388 | 387 | ||
| 389 | 388 | # checkout directory | |
| 390 | - shutil.rmtree(os.path.join(rw_repo.working_tree_dir, "lib")) | ||
| 389 | + rmtree(os.path.join(rw_repo.working_tree_dir, "lib")) | ||
| 391 | 390 | rval = index.checkout('lib') | |
| 392 | 391 | assert len(list(rval)) > 1 | |
| 393 | 392 | ||
@@ -719,7 +718,7 @@ def make_paths(): | |||
| 719 | 718 | with open(hp, "wt") as fp: | |
| 720 | 719 | fp.write("#!/usr/bin/env sh\necho stdout; echo stderr 1>&2; exit 1") | |
| 721 | 720 | # end | |
| 722 | - os.chmod(hp, 0o544) | ||
| 721 | + os.chmod(hp, 0o744) | ||
| 723 | 722 | try: | |
| 724 | 723 | index.commit("This should fail") | |
| 725 | 724 | except HookExecutionError as err: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,11 +7,10 @@ | |||
| 7 | 7 | RefLogEntry, | |
| 8 | 8 | RefLog | |
| 9 | 9 | ) | |
| 10 | - from git.util import Actor | ||
| 10 | + from git.util import Actor, rmtree | ||
| 11 | 11 | from gitdb.util import hex_to_bin | |
| 12 | 12 | ||
| 13 | 13 | import tempfile | |
| 14 | - import shutil | ||
| 15 | 14 | import os | |
| 16 | 15 | ||
| 17 | 16 | ||
@@ -104,4 +103,4 @@ def test_base(self): | |||
| 104 | 103 | # END for each reflog | |
| 105 | 104 | ||
| 106 | 105 | # finally remove our temporary data | |
| 107 | - shutil.rmtree(tdir) | ||
| 106 | + rmtree(tdir) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments