aboutsummaryrefslogtreecommitdiff
path: root/git/test/lib/helper.py
diff options
context:
space:
mode:
Diffstat (limited to 'git/test/lib/helper.py')
-rw-r--r--git/test/lib/helper.py44
1 files changed, 27 insertions, 17 deletions
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index a85ac2fd..e92ce8b4 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -12,7 +12,8 @@ import tempfile
import io
import logging
-from git import Repo, Remote, GitCommandError, Git
+from functools import wraps
+
from git.util import rmtree
from git.compat import string_types, is_win
import textwrap
@@ -30,6 +31,11 @@ __all__ = (
log = logging.getLogger('git.util')
+#: We need an easy way to see if Appveyor TCs start failing,
+#: so the errors marked with this var are considered "acknowledged" ones, awaiting remedy,
+#: till then, we wish to hide them.
+HIDE_WINDOWS_KNOWN_ERRORS = is_win and os.environ.get('HIDE_WINDOWS_KNOWN_ERRORS', True)
+
#{ Routines
@@ -86,6 +92,7 @@ def with_rw_directory(func):
"""Create a temporary directory which can be written to, remove it if the
test succeeds, but leave it otherwise to aid additional debugging"""
+ @wraps(func)
def wrapper(self):
path = tempfile.mktemp(prefix=func.__name__)
os.mkdir(path)
@@ -94,8 +101,8 @@ def with_rw_directory(func):
try:
return func(self, path)
except Exception:
- log.info.write("Test %s.%s failed, output is at %r\n",
- type(self).__name__, func.__name__, path)
+ log.info("Test %s.%s failed, output is at %r\n",
+ type(self).__name__, func.__name__, path)
keep = True
raise
finally:
@@ -108,6 +115,8 @@ def with_rw_directory(func):
if not keep:
rmtree(path)
+ return wrapper
+
def with_rw_repo(working_tree_ref, bare=False):
"""
@@ -122,6 +131,7 @@ def with_rw_repo(working_tree_ref, bare=False):
assert isinstance(working_tree_ref, string_types), "Decorator requires ref name for working tree checkout"
def argument_passer(func):
+ @wraps(func)
def repo_creator(self):
prefix = 'non_'
if bare:
@@ -155,13 +165,13 @@ def with_rw_repo(working_tree_ref, bare=False):
# END rm test repo if possible
# END cleanup
# END rw repo creator
- repo_creator.__name__ = func.__name__
return repo_creator
# END argument passer
return argument_passer
def launch_git_daemon(temp_dir, ip, port):
+ from git import Git
if is_win:
## On MINGW-git, daemon exists in .\Git\mingw64\libexec\git-core\,
# but if invoked as 'git daemon', it detaches from parent `git` cmd,
@@ -207,10 +217,12 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
See working dir info in with_rw_repo
:note: We attempt to launch our own invocation of git-daemon, which will be shutdown at the end of the test.
"""
+ from git import Remote, GitCommandError
assert isinstance(working_tree_ref, string_types), "Decorator requires ref name for working tree checkout"
def argument_passer(func):
+ @wraps(func)
def remote_repo_creator(self):
remote_repo_dir = _mktemp("remote_repo_%s" % func.__name__)
repo_dir = _mktemp("remote_clone_non_bare_repo")
@@ -225,16 +237,13 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
rw_remote_repo.daemon_export = True
# this thing is just annoying !
- crw = rw_remote_repo.config_writer()
- section = "daemon"
- try:
- crw.add_section(section)
- except Exception:
- pass
- crw.set(section, "receivepack", True)
- # release lock
- crw.release()
- del(crw)
+ with rw_remote_repo.config_writer() as crw:
+ section = "daemon"
+ try:
+ crw.add_section(section)
+ except Exception:
+ pass
+ crw.set(section, "receivepack", True)
# initialize the remote - first do it as local remote and pull, then
# we change the url to point to the daemon. The daemon should be started
@@ -243,7 +252,8 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
d_remote.fetch()
remote_repo_url = "git://localhost:%s%s" % (GIT_DAEMON_PORT, remote_repo_dir)
- d_remote.config_writer.set('url', remote_repo_url)
+ with d_remote.config_writer as cw:
+ cw.set('url', remote_repo_url)
temp_dir = osp(_mktemp())
gd = launch_git_daemon(temp_dir, '127.0.0.1', GIT_DAEMON_PORT)
@@ -319,10 +329,9 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
gd.proc.wait()
# END cleanup
# END bare repo creator
- remote_repo_creator.__name__ = func.__name__
return remote_repo_creator
# END remote repo creator
- # END argument parsser
+ # END argument parser
return argument_passer
@@ -358,6 +367,7 @@ class TestBase(TestCase):
Dynamically add a read-only repository to our actual type. This way
each test type has its own repository
"""
+ from git import Repo
import gc
gc.collect()
cls.rorepo = Repo(GIT_REPO)