aboutsummaryrefslogtreecommitdiff
path: root/git/test
diff options
context:
space:
mode:
Diffstat (limited to 'git/test')
-rw-r--r--git/test/lib/helper.py11
-rw-r--r--git/test/test_config.py38
2 files changed, 32 insertions, 17 deletions
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index 2d21f5bf..4335a977 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -12,6 +12,8 @@ import tempfile
import io
import logging
+from functools import wraps
+
from git import Repo, Remote, GitCommandError, Git
from git.util import rmtree
from git.compat import string_types, is_win
@@ -86,6 +88,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)
@@ -107,7 +110,7 @@ def with_rw_directory(func):
gc.collect()
if not keep:
rmtree(path)
- wrapper.__name__ = func.__name__
+
return wrapper
@@ -124,6 +127,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:
@@ -157,7 +161,6 @@ 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
@@ -213,6 +216,7 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
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")
@@ -321,10 +325,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
diff --git a/git/test/test_config.py b/git/test/test_config.py
index 154aaa24..32873f24 100644
--- a/git/test/test_config.py
+++ b/git/test/test_config.py
@@ -60,7 +60,8 @@ class TestBase(TestCase):
self.assertEqual(file_obj.getvalue(), self._to_memcache(fixture_path(filename)).getvalue())
# creating an additional config writer must fail due to exclusive access
- self.failUnlessRaises(IOError, GitConfigParser, file_obj, read_only=False)
+ with self.assertRaises(IOError):
+ GitConfigParser(file_obj, read_only=False)
# should still have a lock and be able to make changes
assert w_config._lock._has_lock()
@@ -91,18 +92,21 @@ class TestBase(TestCase):
@with_rw_directory
def test_lock_reentry(self, rw_dir):
fpl = os.path.join(rw_dir, 'l')
- with GitConfigParser(fpl, read_only=False) as gcp:
- gcp.set_value('include', 'some_value', 'a')
+ gcp = GitConfigParser(fpl, read_only=False)
+ with gcp as cw:
+ cw.set_value('include', 'some_value', 'a')
# entering again locks the file again...
with gcp as cw:
cw.set_value('include', 'some_other_value', 'b')
# ...so creating an additional config writer must fail due to exclusive access
- self.failUnlessRaises(IOError, GitConfigParser, fpl, read_only=False)
+ with self.assertRaises(IOError):
+ GitConfigParser(fpl, read_only=False)
# but work when the lock is removed
with GitConfigParser(fpl, read_only=False):
assert os.path.exists(fpl)
# reentering with an existing lock must fail due to exclusive access
- self.failUnlessRaises(IOError, gcp.__enter__)
+ with self.assertRaises(IOError):
+ gcp.__enter__()
def test_multi_line_config(self):
file_obj = self._to_memcache(fixture_path("git_config_with_comments"))
@@ -144,10 +148,13 @@ class TestBase(TestCase):
assert "\n" not in val
# writing must fail
- self.failUnlessRaises(IOError, r_config.set, section, option, None)
- self.failUnlessRaises(IOError, r_config.remove_option, section, option)
+ with self.assertRaises(IOError):
+ r_config.set(section, option, None)
+ with self.assertRaises(IOError):
+ r_config.remove_option(section, option)
# END for each option
- self.failUnlessRaises(IOError, r_config.remove_section, section)
+ with self.assertRaises(IOError):
+ r_config.remove_section(section)
# END for each section
assert num_sections and num_options
assert r_config._is_initialized is True
@@ -157,7 +164,8 @@ class TestBase(TestCase):
assert r_config.get_value("doesnt", "exist", default) == default
# it raises if there is no default though
- self.failUnlessRaises(cp.NoSectionError, r_config.get_value, "doesnt", "exist")
+ with self.assertRaises(cp.NoSectionError):
+ r_config.get_value("doesnt", "exist")
@with_rw_directory
def test_config_include(self, rw_dir):
@@ -206,7 +214,8 @@ class TestBase(TestCase):
write_test_value(cw, tv)
with GitConfigParser(fpa, read_only=True) as cr:
- self.failUnlessRaises(cp.NoSectionError, check_test_value, cr, tv)
+ with self.assertRaises(cp.NoSectionError):
+ check_test_value(cr, tv)
# But can make it skip includes alltogether, and thus allow write-backs
with GitConfigParser(fpa, read_only=False, merge_includes=False) as cw:
@@ -218,8 +227,10 @@ class TestBase(TestCase):
def test_rename(self):
file_obj = self._to_memcache(fixture_path('git_config'))
with GitConfigParser(file_obj, read_only=False, merge_includes=False) as cw:
- self.failUnlessRaises(ValueError, cw.rename_section, "doesntexist", "foo")
- self.failUnlessRaises(ValueError, cw.rename_section, "core", "include")
+ with self.assertRaises(ValueError):
+ cw.rename_section("doesntexist", "foo")
+ with self.assertRaises(ValueError):
+ cw.rename_section("core", "include")
nn = "bee"
assert cw.rename_section('core', nn) is cw
@@ -237,4 +248,5 @@ class TestBase(TestCase):
assert cr.get_value('core', 'filemode'), "Should read keys with values"
- self.failUnlessRaises(cp.NoOptionError, cr.get_value, 'color', 'ui')
+ with self.assertRaises(cp.NoOptionError):
+ cr.get_value('color', 'ui')