summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/lib/__init__.py6
-rw-r--r--test/lib/helper.py32
-rw-r--r--test/performance/lib.py13
-rw-r--r--test/performance/test_commit.py9
-rw-r--r--test/performance/test_odb.py17
-rw-r--r--test/performance/test_streams.py4
-rw-r--r--test/test_base.py4
-rw-r--r--test/test_blob.py4
-rw-r--r--test/test_clone.py8
-rw-r--r--test/test_commit.py74
-rw-r--r--test/test_config.py36
-rw-r--r--test/test_diff.py28
-rw-r--r--test/test_docs.py202
-rw-r--r--test/test_exc.py4
-rw-r--r--test/test_fun.py19
-rw-r--r--test/test_git.py32
-rw-r--r--test/test_index.py87
-rw-r--r--test/test_installation.py8
-rw-r--r--test/test_reflog.py8
-rw-r--r--test/test_refs.py37
-rw-r--r--test/test_remote.py64
-rw-r--r--test/test_repo.py76
-rw-r--r--test/test_submodule.py174
-rw-r--r--test/test_tree.py4
-rw-r--r--test/test_util.py8
25 files changed, 242 insertions, 716 deletions
diff --git a/test/lib/__init__.py b/test/lib/__init__.py
index ae4c2b67..a4e57b8e 100644
--- a/test/lib/__init__.py
+++ b/test/lib/__init__.py
@@ -8,8 +8,4 @@
import inspect
from .helper import *
-__all__ = [
- name
- for name, obj in locals().items()
- if not (name.startswith("_") or inspect.ismodule(obj))
-]
+__all__ = [name for name, obj in locals().items() if not (name.startswith("_") or inspect.ismodule(obj))]
diff --git a/test/lib/helper.py b/test/lib/helper.py
index 8f4046da..c04c5cd9 100644
--- a/test/lib/helper.py
+++ b/test/lib/helper.py
@@ -127,9 +127,7 @@ def with_rw_repo(working_tree_ref, bare=False):
To make working with relative paths easier, the cwd will be set to the working
dir of the repository.
"""
- assert isinstance(
- working_tree_ref, str
- ), "Decorator requires ref name for working tree checkout"
+ assert isinstance(working_tree_ref, str), "Decorator requires ref name for working tree checkout"
def argument_passer(func):
@wraps(func)
@@ -270,23 +268,15 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
"""
from git import Git, Remote # To avoid circular deps.
- assert isinstance(
- working_tree_ref, str
- ), "Decorator requires ref name for working tree checkout"
+ assert isinstance(working_tree_ref, str), "Decorator requires ref name for working tree checkout"
def argument_passer(func):
@wraps(func)
def remote_repo_creator(self):
- rw_daemon_repo_dir = tempfile.mktemp(
- prefix="daemon_repo-%s-" % func.__name__
- )
- rw_repo_dir = tempfile.mktemp(
- prefix="daemon_cloned_repo-%s-" % func.__name__
- )
+ rw_daemon_repo_dir = tempfile.mktemp(prefix="daemon_repo-%s-" % func.__name__)
+ rw_repo_dir = tempfile.mktemp(prefix="daemon_cloned_repo-%s-" % func.__name__)
- rw_daemon_repo = self.rorepo.clone(
- rw_daemon_repo_dir, shared=True, bare=True
- )
+ rw_daemon_repo = self.rorepo.clone(rw_daemon_repo_dir, shared=True, bare=True)
# recursive alternates info ?
rw_repo = rw_daemon_repo.clone(rw_repo_dir, shared=True, bare=False, n=True)
try:
@@ -312,16 +302,12 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
base_daemon_path, rel_repo_dir = osp.split(rw_daemon_repo_dir)
- remote_repo_url = Git.polish_url(
- "git://localhost:%s/%s" % (GIT_DAEMON_PORT, rel_repo_dir)
- )
+ remote_repo_url = Git.polish_url("git://localhost:%s/%s" % (GIT_DAEMON_PORT, rel_repo_dir))
with d_remote.config_writer as cw:
cw.set("url", remote_repo_url)
with git_daemon_launched(
- Git.polish_url(
- base_daemon_path, is_cygwin=False
- ), # No daemon in Cygwin.
+ Git.polish_url(base_daemon_path, is_cygwin=False), # No daemon in Cygwin.
"127.0.0.1",
GIT_DAEMON_PORT,
):
@@ -389,9 +375,7 @@ class TestBase(TestCase):
""":return" a path to a small, clonable repository"""
from git.cmd import Git
- return Git.polish_url(
- osp.join(self.rorepo.working_tree_dir, "git/ext/gitdb/gitdb/ext/smmap")
- )
+ return Git.polish_url(osp.join(self.rorepo.working_tree_dir, "git/ext/gitdb/gitdb/ext/smmap"))
@classmethod
def setUpClass(cls):
diff --git a/test/performance/lib.py b/test/performance/lib.py
index 101e2cd4..c793d771 100644
--- a/test/performance/lib.py
+++ b/test/performance/lib.py
@@ -45,17 +45,12 @@ class TestBigRepoR(TestBase):
repo_path = os.environ.get(k_env_git_repo)
if repo_path is None:
logging.info(
- (
- "You can set the %s environment variable to a .git repository of"
- % k_env_git_repo
- )
+ ("You can set the %s environment variable to a .git repository of" % k_env_git_repo)
+ "your choice - defaulting to the gitpython repository"
)
repo_path = osp.dirname(__file__)
# end set some repo path
- self.gitrorepo = Repo(
- repo_path, odbt=GitCmdObjectDB, search_parent_directories=True
- )
+ self.gitrorepo = Repo(repo_path, odbt=GitCmdObjectDB, search_parent_directories=True)
self.puregitrorepo = Repo(repo_path, odbt=GitDB, search_parent_directories=True)
def tearDown(self):
@@ -79,9 +74,7 @@ class TestBigRepoRW(TestBigRepoR):
pass
dirname = tempfile.mktemp()
os.mkdir(dirname)
- self.gitrwrepo = self.gitrorepo.clone(
- dirname, shared=True, bare=True, odbt=GitCmdObjectDB
- )
+ self.gitrwrepo = self.gitrorepo.clone(dirname, shared=True, bare=True, odbt=GitCmdObjectDB)
self.puregitrwrepo = Repo(dirname, odbt=GitDB)
def tearDown(self):
diff --git a/test/performance/test_commit.py b/test/performance/test_commit.py
index 25cc34b8..38b529af 100644
--- a/test/performance/test_commit.py
+++ b/test/performance/test_commit.py
@@ -66,8 +66,7 @@ class TestPerformance(TestBigRepoRW, TestCommitSerialization):
# END for each traversed commit
elapsed_time = time() - st
print(
- "Traversed %i Commits in %s [s] ( %f commits/s )"
- % (nc, elapsed_time, nc / elapsed_time),
+ "Traversed %i Commits in %s [s] ( %f commits/s )" % (nc, elapsed_time, nc / elapsed_time),
file=sys.stderr,
)
@@ -81,8 +80,7 @@ class TestPerformance(TestBigRepoRW, TestCommitSerialization):
# END for each traversed commit
elapsed_time = time() - st
print(
- "Iterated %i Commits in %s [s] ( %f commits/s )"
- % (nc, elapsed_time, nc / elapsed_time),
+ "Iterated %i Commits in %s [s] ( %f commits/s )" % (nc, elapsed_time, nc / elapsed_time),
file=sys.stderr,
)
@@ -123,7 +121,6 @@ class TestPerformance(TestBigRepoRW, TestCommitSerialization):
elapsed = time() - st
print(
- "Serialized %i commits to loose objects in %f s ( %f commits / s )"
- % (nc, elapsed, nc / elapsed),
+ "Serialized %i commits to loose objects in %f s ( %f commits / s )" % (nc, elapsed, nc / elapsed),
file=sys.stderr,
)
diff --git a/test/performance/test_odb.py b/test/performance/test_odb.py
index 680464c9..4208c418 100644
--- a/test/performance/test_odb.py
+++ b/test/performance/test_odb.py
@@ -63,16 +63,13 @@ class TestObjDBPerformance(TestBigRepoR):
# END for each bloblist
elapsed = time() - st
- msg = (
- "%s: Retrieved %i blob (%i KiB) and their data in %g s ( %f blobs / s, %f KiB / s )"
- % (
- type(repo.odb),
- nb,
- data_bytes / 1000,
- elapsed,
- nb / elapsed,
- (data_bytes / 1000) / elapsed,
- )
+ msg = "%s: Retrieved %i blob (%i KiB) and their data in %g s ( %f blobs / s, %f KiB / s )" % (
+ type(repo.odb),
+ nb,
+ data_bytes / 1000,
+ elapsed,
+ nb / elapsed,
+ (data_bytes / 1000) / elapsed,
)
print(msg, file=sys.stderr)
results[2].append(elapsed)
diff --git a/test/performance/test_streams.py b/test/performance/test_streams.py
index 2ae94e29..5588212e 100644
--- a/test/performance/test_streams.py
+++ b/test/performance/test_streams.py
@@ -97,9 +97,7 @@ class TestObjDBPerformance(TestBigRepoR):
# VS. CGIT
##########
# CGIT ! Can using the cgit programs be faster ?
- proc = rwrepo.git.hash_object(
- "-w", "--stdin", as_process=True, istream=subprocess.PIPE
- )
+ proc = rwrepo.git.hash_object("-w", "--stdin", as_process=True, istream=subprocess.PIPE)
# write file - pump everything in at once to be a fast as possible
data = stream.getvalue() # cache it
diff --git a/test/test_base.py b/test/test_base.py
index a7c034e2..ccfdc8ed 100644
--- a/test/test_base.py
+++ b/test/test_base.py
@@ -92,9 +92,7 @@ class TestBase(_TestBase):
def test_object_resolution(self):
# objects must be resolved to shas so they compare equal
- self.assertEqual(
- self.rorepo.head.reference.object, self.rorepo.active_branch.object
- )
+ self.assertEqual(self.rorepo.head.reference.object, self.rorepo.active_branch.object)
@with_rw_repo("HEAD", bare=True)
def test_with_bare_rw_repo(self, bare_rw_repo):
diff --git a/test/test_blob.py b/test/test_blob.py
index ad5b46c1..b94dcec2 100644
--- a/test/test_blob.py
+++ b/test/test_blob.py
@@ -18,6 +18,4 @@ class TestBlob(TestBase):
self.assertEqual("text/plain", blob.mime_type)
def test_nodict(self):
- self.assertRaises(
- AttributeError, setattr, self.rorepo.tree()["AUTHORS"], "someattr", 2
- )
+ self.assertRaises(AttributeError, setattr, self.rorepo.tree()["AUTHORS"], "someattr", 2)
diff --git a/test/test_clone.py b/test/test_clone.py
index 6bd944f9..304ab33c 100644
--- a/test/test_clone.py
+++ b/test/test_clone.py
@@ -25,12 +25,8 @@ class TestClone(TestBase):
try:
self.rorepo.clone(non_empty_dir)
except git.GitCommandError as exc:
- self.assertTrue(
- exc.stderr, "GitCommandError's 'stderr' is unexpectedly empty"
- )
- expr = re.compile(
- r"(?is).*\bfatal:\s+destination\s+path\b.*\bexists\b.*\bnot\b.*\bempty\s+directory\b"
- )
+ self.assertTrue(exc.stderr, "GitCommandError's 'stderr' is unexpectedly empty")
+ expr = re.compile(r"(?is).*\bfatal:\s+destination\s+path\b.*\bexists\b.*\bnot\b.*\bempty\s+directory\b")
self.assertTrue(
expr.search(exc.stderr),
'"%s" does not match "%s"' % (expr.pattern, exc.stderr),
diff --git a/test/test_commit.py b/test/test_commit.py
index 17a4fe4f..82126987 100644
--- a/test/test_commit.py
+++ b/test/test_commit.py
@@ -27,9 +27,7 @@ import os.path as osp
class TestCommitSerialization(TestBase):
- def assert_commit_serialization(
- self, rwrepo, commit_id, print_performance_info=False
- ):
+ def assert_commit_serialization(self, rwrepo, commit_id, print_performance_info=False):
"""traverse all commits in the history of commit identified by commit_id and check
if the serialization works.
:param print_performance_info: if True, we will show how fast we are"""
@@ -104,12 +102,8 @@ class TestCommit(TestCommitSerialization):
self.assertEqual("Sebastian Thiel", commit.author.name)
self.assertEqual("byronimo@gmail.com", commit.author.email)
self.assertEqual(commit.author, commit.committer)
- assert isinstance(commit.authored_date, int) and isinstance(
- commit.committed_date, int
- )
- assert isinstance(commit.author_tz_offset, int) and isinstance(
- commit.committer_tz_offset, int
- )
+ assert isinstance(commit.authored_date, int) and isinstance(commit.committed_date, int)
+ assert isinstance(commit.author_tz_offset, int) and isinstance(commit.committer_tz_offset, int)
self.assertEqual(
commit.message,
"Added missing information to docstrings of commit and stats module\n",
@@ -195,14 +189,12 @@ class TestCommit(TestCommitSerialization):
# at some point, both iterations should stop
self.assertEqual(list(bfirst)[-1], first)
- stoptraverse = self.rorepo.commit(
- "254d04aa3180eb8b8daf7b7ff25f010cd69b4e7d"
- ).traverse(ignore_self=0, as_edge=True)
+ stoptraverse = self.rorepo.commit("254d04aa3180eb8b8daf7b7ff25f010cd69b4e7d").traverse(
+ ignore_self=0, as_edge=True
+ )
stoptraverse_list = list(stoptraverse)
for itemtup in stoptraverse_list:
- self.assertIsInstance(itemtup, (tuple)) and self.assertEqual(
- len(itemtup), 2
- ) # as_edge=True -> tuple
+ self.assertIsInstance(itemtup, (tuple)) and self.assertEqual(len(itemtup), 2) # as_edge=True -> tuple
src, item = itemtup
self.assertIsInstance(item, Commit)
if src:
@@ -210,9 +202,7 @@ class TestCommit(TestCommitSerialization):
else:
self.assertIsNone(src) # ignore_self=0 -> first is (None, Commit)
- stoptraverse = self.rorepo.commit(
- "254d04aa3180eb8b8daf7b7ff25f010cd69b4e7d"
- ).traverse(as_edge=True)
+ stoptraverse = self.rorepo.commit("254d04aa3180eb8b8daf7b7ff25f010cd69b4e7d").traverse(as_edge=True)
self.assertEqual(len(next(stoptraverse)), 2)
# ignore self
@@ -222,14 +212,10 @@ class TestCommit(TestCommitSerialization):
self.assertEqual(len(list(start.traverse(ignore_self=False, depth=0))), 1)
# prune
- self.assertEqual(
- next(start.traverse(branch_first=1, prune=lambda i, d: i == p0)), p1
- )
+ self.assertEqual(next(start.traverse(branch_first=1, prune=lambda i, d: i == p0)), p1)
# predicate
- self.assertEqual(
- next(start.traverse(branch_first=1, predicate=lambda i, d: i == p1)), p1
- )
+ self.assertEqual(next(start.traverse(branch_first=1, predicate=lambda i, d: i == p1)), p1)
# traversal should stop when the beginning is reached
self.assertRaises(StopIteration, next, first.traverse())
@@ -253,25 +239,19 @@ class TestCommit(TestCommitSerialization):
assert ltd_commits and len(ltd_commits) < len(all_commits)
# show commits of multiple paths, resulting in a union of commits
- less_ltd_commits = list(
- Commit.iter_items(self.rorepo, "master", paths=("CHANGES", "AUTHORS"))
- )
+ less_ltd_commits = list(Commit.iter_items(self.rorepo, "master", paths=("CHANGES", "AUTHORS")))
assert len(ltd_commits) < len(less_ltd_commits)
class Child(Commit):
def __init__(self, *args, **kwargs):
super(Child, self).__init__(*args, **kwargs)
- child_commits = list(
- Child.iter_items(self.rorepo, "master", paths=("CHANGES", "AUTHORS"))
- )
+ child_commits = list(Child.iter_items(self.rorepo, "master", paths=("CHANGES", "AUTHORS")))
assert type(child_commits[0]) == Child
def test_iter_items(self):
# pretty not allowed
- self.assertRaises(
- ValueError, Commit.iter_items, self.rorepo, "master", pretty="raw"
- )
+ self.assertRaises(ValueError, Commit.iter_items, self.rorepo, "master", pretty="raw")
def test_rev_list_bisect_all(self):
"""
@@ -284,9 +264,7 @@ class TestCommit(TestCommitSerialization):
bisect_all=True,
)
- commits = Commit._iter_from_process_or_stream(
- self.rorepo, StringProcessAdapter(revs.encode("ascii"))
- )
+ commits = Commit._iter_from_process_or_stream(self.rorepo, StringProcessAdapter(revs.encode("ascii")))
expected_ids = (
"7156cece3c49544abb6bf7a0c218eb36646fad6d",
"1f66cfbbce58b4b552b041707a12d437cc5f400a",
@@ -312,9 +290,7 @@ class TestCommit(TestCommitSerialization):
# This doesn't work anymore, as we will either attempt getattr with bytes, or compare 20 byte string
# with actual 20 byte bytes. This usage makes no sense anyway
assert isinstance(
- Commit.list_items(self.rorepo, "0.1.5", max_count=5)[
- "5117c9c8a4d3af19a9958677e45cda9269de1541"
- ],
+ Commit.list_items(self.rorepo, "0.1.5", max_count=5)["5117c9c8a4d3af19a9958677e45cda9269de1541"],
Commit,
)
@@ -434,9 +410,7 @@ JzJMZDRLQLFvnzqZuCjE
cmt.gpgsig = None
cstream = BytesIO()
cmt._serialize(cstream)
- assert not re.search(
- r"^gpgsig ", cstream.getvalue().decode("ascii"), re.MULTILINE
- )
+ assert not re.search(r"^gpgsig ", cstream.getvalue().decode("ascii"), re.MULTILINE)
def assert_gpgsig_deserialization(self, cstream):
assert "gpgsig" in "precondition: need gpgsig"
@@ -496,9 +470,7 @@ JzJMZDRLQLFvnzqZuCjE
# Check if KEY 1 & 2 with Value 1 & 2 is extracted from multiple msg variations
msgs = []
msgs.append(f"Subject\n\n{KEY_1}: {VALUE_1}\n{KEY_2}: {VALUE_2}\n")
- msgs.append(
- f"Subject\n \nSome body of a function\n \n{KEY_1}: {VALUE_1}\n{KEY_2}: {VALUE_2}\n"
- )
+ msgs.append(f"Subject\n \nSome body of a function\n \n{KEY_1}: {VALUE_1}\n{KEY_2}: {VALUE_2}\n")
msgs.append(
f"Subject\n \nSome body of a function\n\nnon-key: non-value\n\n{KEY_1}: {VALUE_1}\n{KEY_2}: {VALUE_2}\n"
)
@@ -519,12 +491,8 @@ JzJMZDRLQLFvnzqZuCjE
msgs = []
msgs.append(f"Subject\n")
msgs.append(f"Subject\n\nBody with some\nText\n")
- msgs.append(
- f"Subject\n\nBody with\nText\n\nContinuation but\n doesn't contain colon\n"
- )
- msgs.append(
- f"Subject\n\nBody with\nText\n\nContinuation but\n only contains one :\n"
- )
+ msgs.append(f"Subject\n\nBody with\nText\n\nContinuation but\n doesn't contain colon\n")
+ msgs.append(f"Subject\n\nBody with\nText\n\nContinuation but\n only contains one :\n")
msgs.append(f"Subject\n\nBody with\nText\n\nKey: Value\nLine without colon\n")
msgs.append(f"Subject\n\nBody with\nText\n\nLine without colon\nKey: Value\n")
@@ -537,9 +505,7 @@ JzJMZDRLQLFvnzqZuCjE
# check that only the last key value paragraph is evaluated
commit = self.rorepo.commit("master")
commit = copy.copy(commit)
- commit.message = (
- f"Subject\n\nMultiline\nBody\n\n{KEY_1}: {VALUE_1}\n\n{KEY_2}: {VALUE_2}\n"
- )
+ commit.message = f"Subject\n\nMultiline\nBody\n\n{KEY_1}: {VALUE_1}\n\n{KEY_2}: {VALUE_2}\n"
assert KEY_1 not in commit.trailers.keys()
assert KEY_2 in commit.trailers.keys()
assert commit.trailers[KEY_2] == VALUE_2
diff --git a/test/test_config.py b/test/test_config.py
index 45677b0d..8bb2aa30 100644
--- a/test/test_config.py
+++ b/test/test_config.py
@@ -37,9 +37,7 @@ class TestBase(TestCase):
def tearDown(self):
for lfp in glob.glob(_tc_lock_fpaths):
if osp.isfile(lfp):
- raise AssertionError(
- "Previous TC left hanging git-lock file: {}".format(lfp)
- )
+ raise AssertionError("Previous TC left hanging git-lock file: {}".format(lfp))
def _to_memcache(self, file_path):
with open(file_path, "rb") as fp:
@@ -94,9 +92,7 @@ class TestBase(TestCase):
# END for each filename
def test_includes_order(self):
- with GitConfigParser(
- list(map(fixture_path, ("git_config", "git_config_global")))
- ) as r_config:
+ with GitConfigParser(list(map(fixture_path, ("git_config", "git_config_global")))) as r_config:
r_config.read() # enforce reading
# Simple inclusions, again checking them taking precedence
assert r_config.get_value("sec", "var0") == "value0_included"
@@ -106,9 +102,7 @@ class TestBase(TestCase):
try:
assert r_config.get_value("sec", "var1") == "value1_main"
except AssertionError as e:
- raise SkipTest(
- "Known failure -- included values are not in effect right away"
- ) from e
+ raise SkipTest("Known failure -- included values are not in effect right away") from e
@with_rw_directory
def test_lock_reentry(self, rw_dir):
@@ -231,9 +225,7 @@ class TestBase(TestCase):
for tv in ("a", "b", "c"):
check_test_value(cr, tv)
# end for each test to verify
- assert (
- len(cr.items("include")) == 8
- ), "Expected all include sections to be merged"
+ assert len(cr.items("include")) == 8, "Expected all include sections to be merged"
# test writable config writers - assure write-back doesn't involve includes
with GitConfigParser(fpa, read_only=False, merge_includes=True) as cw:
@@ -399,9 +391,7 @@ class TestBase(TestCase):
)
def test_empty_config_value(self):
- cr = GitConfigParser(
- fixture_path("git_config_with_empty_value"), read_only=True
- )
+ cr = GitConfigParser(fixture_path("git_config_with_empty_value"), read_only=True)
assert cr.get_value("core", "filemode"), "Should read keys with values"
@@ -417,9 +407,7 @@ class TestBase(TestCase):
# Where there are multiple values, "get" returns the last.
self.assertEqual(cw.get("section1", "option1"), "value1b")
- self.assertEqual(
- cw.get_values("section1", "option1"), ["value1a", "value1b"]
- )
+ self.assertEqual(cw.get_values("section1", "option1"), ["value1a", "value1b"])
self.assertEqual(
cw.items("section1"),
[("option1", "value1b"), ("other_option1", "other_value1")],
@@ -445,9 +433,7 @@ class TestBase(TestCase):
file_obj.seek(0)
cr = GitConfigParser(file_obj, read_only=True)
self.assertEqual(cr.get_value("section2", "option1"), "value1b")
- self.assertEqual(
- cr.get_values("section2", "option1"), ["value1a", "value1b"]
- )
+ self.assertEqual(cr.get_values("section2", "option1"), ["value1a", "value1b"])
self.assertEqual(
cr.items("section2"),
[("option1", "value1b"), ("other_option1", "other_value1")],
@@ -488,9 +474,7 @@ class TestBase(TestCase):
file_obj.seek(0)
cr = GitConfigParser(file_obj, read_only=True)
self.assertEqual(cr.get_value("section1", "option1"), "value1b")
- self.assertEqual(
- cr.get_values("section1", "option1"), ["value1a", "value1b"]
- )
+ self.assertEqual(cr.get_values("section1", "option1"), ["value1a", "value1b"])
self.assertEqual(cr.get_value("section1", "other_option1"), "other_value1a")
self.assertEqual(
cr.get_values("section1", "other_option1"),
@@ -516,9 +500,7 @@ class TestBase(TestCase):
file_obj.seek(0)
cr = GitConfigParser(file_obj, read_only=True)
self.assertEqual(cr.get_value("section1", "option1"), "value1c")
- self.assertEqual(
- cr.get_values("section1", "option1"), ["value1a", "value1b", "value1c"]
- )
+ self.assertEqual(cr.get_values("section1", "option1"), ["value1a", "value1b", "value1c"])
self.assertEqual(
cr.items("section1"),
[("option1", "value1c"), ("other_option1", "other_value1")],
diff --git a/test/test_diff.py b/test/test_diff.py
index 10f5d6db..3e1c5ddc 100644
--- a/test/test_diff.py
+++ b/test/test_diff.py
@@ -189,9 +189,7 @@ class TestDiff(TestBase):
self.assertEqual(len(list(diffs.iter_change_type("T"))), 1)
def test_diff_of_modified_files_not_added_to_the_index(self):
- output = StringProcessAdapter(
- to_raw(fixture("diff_abbrev-40_full-index_M_raw_no-color"))
- )
+ output = StringProcessAdapter(to_raw(fixture("diff_abbrev-40_full-index_M_raw_no-color")))
diffs = Diff._index_from_raw_format(self.rorepo, output)
self.assertEqual(len(diffs), 1, "one modification")
@@ -224,9 +222,7 @@ class TestDiff(TestBase):
self.assertEqual(len(res), 6)
for dr in res:
self.assertTrue(dr.diff.startswith(b"@@"), dr)
- self.assertIsNotNone(
- str(dr), "Diff to string conversion should be possible"
- )
+ self.assertIsNotNone(str(dr), "Diff to string conversion should be possible")
# end for each diff
dr = res[3]
@@ -240,9 +236,7 @@ class TestDiff(TestBase):
res[0].b_path,
)
- @unittest.skip(
- "This currently fails and would need someone to improve diff parsing"
- )
+ @unittest.skip("This currently fails and would need someone to improve diff parsing")
def test_diff_file_with_colon(self):
output = fixture("diff_file_with_colon")
res = []
@@ -287,9 +281,7 @@ class TestDiff(TestBase):
# NOTE: The path prefixes a/ and b/ here are legit! We're actually
# verifying that it's not "a/a/" that shows up, see the fixture data.
self.assertEqual(res[11].a_path, "a/with spaces") # NOTE: path a/ here legit!
- self.assertEqual(
- res[11].b_path, "b/with some spaces"
- ) # NOTE: path b/ here legit!
+ self.assertEqual(res[11].b_path, "b/with some spaces") # NOTE: path b/ here legit!
self.assertEqual(res[12].a_path, "a/ending in a space ")
self.assertEqual(res[12].b_path, "b/ending with space ")
self.assertEqual(res[13].a_path, 'a/"with-quotes"')
@@ -321,9 +313,7 @@ class TestDiff(TestBase):
data = StringProcessAdapter(fixture("diff_file_with_spaces"))
diff_index = Diff._index_from_patch_format(self.rorepo, data)
self.assertIsNone(diff_index[0].a_path, repr(diff_index[0].a_path))
- self.assertEqual(
- diff_index[0].b_path, "file with spaces", repr(diff_index[0].b_path)
- )
+ self.assertEqual(diff_index[0].b_path, "file with spaces", repr(diff_index[0].b_path))
def test_diff_submodule(self):
"""Test that diff is able to correctly diff commits that cover submodule changes"""
@@ -374,9 +364,7 @@ class TestDiff(TestBase):
for other in (None, NULL_TREE, commit.Index, commit.parents[0]):
for paths in (None, "CHANGES", ("CHANGES", "lib")):
for create_patch in range(2):
- diff_index = diff_item.diff(
- other=other, paths=paths, create_patch=create_patch
- )
+ diff_index = diff_item.diff(other=other, paths=paths, create_patch=create_patch)
assert isinstance(diff_index, DiffIndex)
if diff_index:
@@ -384,9 +372,7 @@ class TestDiff(TestBase):
for ct in DiffIndex.change_type:
key = "ct_%s" % ct
assertion_map.setdefault(key, 0)
- assertion_map[key] = assertion_map[key] + len(
- list(diff_index.iter_change_type(ct))
- )
+ assertion_map[key] = assertion_map[key] + len(list(diff_index.iter_change_type(ct)))
# END for each changetype
# check entries
diff --git a/test/test_docs.py b/test/test_docs.py
index b6a0ed31..bea34a0b 100644
--- a/test/test_docs.py
+++ b/test/test_docs.py
@@ -63,15 +63,9 @@ class Tutorials(TestBase):
# repository paths
# [7-test_init_repo_object]
- assert os.path.isdir(
- cloned_repo.working_tree_dir
- ) # directory with your work files
- assert cloned_repo.git_dir.startswith(
- cloned_repo.working_tree_dir
- ) # directory containing the git repository
- assert (
- bare_repo.working_tree_dir is None
- ) # bare repositories have no working tree
+ assert os.path.isdir(cloned_repo.working_tree_dir) # directory with your work files
+ assert cloned_repo.git_dir.startswith(cloned_repo.working_tree_dir) # directory containing the git repository
+ assert bare_repo.working_tree_dir is None # bare repositories have no working tree
# ![7-test_init_repo_object]
# heads, tags and references
@@ -82,35 +76,22 @@ class Tutorials(TestBase):
repo.heads.master, # head is a sym-ref pointing to master
"It's ok if TC not running from `master`.",
)
- self.assertEqual(
- repo.tags["0.3.5"], repo.tag("refs/tags/0.3.5")
- ) # you can access tags in various ways too
- self.assertEqual(
- repo.refs.master, repo.heads["master"]
- ) # .refs provides all refs, ie heads ...
+ self.assertEqual(repo.tags["0.3.5"], repo.tag("refs/tags/0.3.5")) # you can access tags in various ways too
+ self.assertEqual(repo.refs.master, repo.heads["master"]) # .refs provides all refs, ie heads ...
if "TRAVIS" not in os.environ:
- self.assertEqual(
- repo.refs["origin/master"], repo.remotes.origin.refs.master
- ) # ... remotes ...
+ self.assertEqual(repo.refs["origin/master"], repo.remotes.origin.refs.master) # ... remotes ...
self.assertEqual(repo.refs["0.3.5"], repo.tags["0.3.5"]) # ... and tags
# ![8-test_init_repo_object]
# create a new head/branch
# [9-test_init_repo_object]
new_branch = cloned_repo.create_head("feature") # create a new branch ...
- assert (
- cloned_repo.active_branch != new_branch
- ) # which wasn't checked out yet ...
- self.assertEqual(
- new_branch.commit, cloned_repo.active_branch.commit
- ) # pointing to the checked-out commit
+ assert cloned_repo.active_branch != new_branch # which wasn't checked out yet ...
+ self.assertEqual(new_branch.commit, cloned_repo.active_branch.commit) # pointing to the checked-out commit
# It's easy to let a branch point to the previous commit, without affecting anything else
# Each reference provides access to the git object it points to, usually commits
- assert (
- new_branch.set_commit("HEAD~1").commit
- == cloned_repo.active_branch.commit.parents[0]
- )
+ assert new_branch.set_commit("HEAD~1").commit == cloned_repo.active_branch.commit.parents[0]
# ![9-test_init_repo_object]
# create a new tag reference
@@ -120,16 +101,10 @@ class Tutorials(TestBase):
ref=new_branch,
message="This is a tag-object pointing to %s" % new_branch.name,
)
- self.assertEqual(
- past.commit, new_branch.commit
- ) # the tag points to the specified commit
- assert past.tag.message.startswith(
- "This is"
- ) # and its object carries the message provided
-
- now = cloned_repo.create_tag(
- "now"
- ) # This is a tag-reference. It may not carry meta-data
+ self.assertEqual(past.commit, new_branch.commit) # the tag points to the specified commit
+ assert past.tag.message.startswith("This is") # and its object carries the message provided
+
+ now = cloned_repo.create_tag("now") # This is a tag-reference. It may not carry meta-data
assert now.tag is None
# ![10-test_init_repo_object]
@@ -137,12 +112,7 @@ class Tutorials(TestBase):
# [11-test_init_repo_object]
assert now.commit.message != past.commit.message
# You can read objects directly through binary streams, no working tree required
- assert (
- (now.commit.tree / "VERSION")
- .data_stream.read()
- .decode("ascii")
- .startswith("3")
- )
+ assert (now.commit.tree / "VERSION").data_stream.read().decode("ascii").startswith("3")
# You can traverse trees as well to handle all contained files of a particular commit
file_count = 0
@@ -151,12 +121,8 @@ class Tutorials(TestBase):
for item in tree.traverse():
file_count += item.type == "blob"
tree_count += item.type == "tree"
- assert (
- file_count and tree_count
- ) # we have accumulated all directories and files
- self.assertEqual(
- len(tree.blobs) + len(tree.trees), len(tree)
- ) # a tree is iterable on its children
+ assert file_count and tree_count # we have accumulated all directories and files
+ self.assertEqual(len(tree.blobs) + len(tree.trees), len(tree)) # a tree is iterable on its children
# ![11-test_init_repo_object]
# remotes allow handling push, pull and fetch operations
@@ -175,9 +141,7 @@ class Tutorials(TestBase):
# end
- self.assertEqual(
- len(cloned_repo.remotes), 1
- ) # we have been cloned, so should be one remote
+ self.assertEqual(len(cloned_repo.remotes), 1) # we have been cloned, so should be one remote
self.assertEqual(len(bare_repo.remotes), 0) # this one was just initialized
origin = bare_repo.create_remote("origin", url=cloned_repo.working_tree_dir)
assert origin.exists()
@@ -193,9 +157,7 @@ class Tutorials(TestBase):
# index
# [13-test_init_repo_object]
- self.assertEqual(
- new_branch.checkout(), cloned_repo.active_branch
- ) # checking out branch adjusts the wtree
+ self.assertEqual(new_branch.checkout(), cloned_repo.active_branch) # checking out branch adjusts the wtree
self.assertEqual(new_branch.commit, past.commit) # Now the past is checked out
new_file_path = os.path.join(cloned_repo.working_tree_dir, "my-new-file")
@@ -205,15 +167,9 @@ class Tutorials(TestBase):
cloned_repo.index.commit("Added a new file in the past - for later merege")
# prepare a merge
- master = (
- cloned_repo.heads.master
- ) # right-hand side is ahead of us, in the future
- merge_base = cloned_repo.merge_base(
- new_branch, master
- ) # allows for a three-way merge
- cloned_repo.index.merge_tree(
- master, base=merge_base
- ) # write the merge result into index
+ master = cloned_repo.heads.master # right-hand side is ahead of us, in the future
+ merge_base = cloned_repo.merge_base(new_branch, master) # allows for a three-way merge
+ cloned_repo.index.merge_tree(master, base=merge_base) # write the merge result into index
cloned_repo.index.commit(
"Merged past and now into future ;)",
parent_commits=(new_branch.commit, master.commit),
@@ -222,13 +178,9 @@ class Tutorials(TestBase):
# now new_branch is ahead of master, which probably should be checked out and reset softly.
# note that all these operations didn't touch the working tree, as we managed it ourselves.
# This definitely requires you to know what you are doing :) !
- assert (
- os.path.basename(new_file_path) in new_branch.commit.tree
- ) # new file is now in tree
+ assert os.path.basename(new_file_path) in new_branch.commit.tree # new file is now in tree
master.commit = new_branch.commit # let master point to most recent commit
- cloned_repo.head.reference = (
- master # we adjusted just the reference, not the working tree or index
- )
+ cloned_repo.head.reference = master # we adjusted just the reference, not the working tree or index
# ![13-test_init_repo_object]
# submodules
@@ -238,28 +190,18 @@ class Tutorials(TestBase):
# As our GitPython repository has submodules already that point to GitHub, make sure we don't
# interact with them
for sm in cloned_repo.submodules:
- assert (
- not sm.remove().exists()
- ) # after removal, the sm doesn't exist anymore
- sm = cloned_repo.create_submodule(
- "mysubrepo", "path/to/subrepo", url=bare_repo.git_dir, branch="master"
- )
+ assert not sm.remove().exists() # after removal, the sm doesn't exist anymore
+ sm = cloned_repo.create_submodule("mysubrepo", "path/to/subrepo", url=bare_repo.git_dir, branch="master")
# .gitmodules was written and added to the index, which is now being committed
cloned_repo.index.commit("Added submodule")
- assert (
- sm.exists() and sm.module_exists()
- ) # this submodule is defintely available
+ assert sm.exists() and sm.module_exists() # this submodule is defintely available
sm.remove(module=True, configuration=False) # remove the working tree
- assert (
- sm.exists() and not sm.module_exists()
- ) # the submodule itself is still available
+ assert sm.exists() and not sm.module_exists() # the submodule itself is still available
# update all submodules, non-recursively to save time, this method is very powerful, go have a look
cloned_repo.submodule_update(recursive=False)
- assert (
- sm.module_exists()
- ) # The submodules working tree was checked out by update
+ assert sm.module_exists() # The submodules working tree was checked out by update
# ![14-test_init_repo_object]
@with_rw_directory
@@ -267,9 +209,7 @@ class Tutorials(TestBase):
# [1-test_references_and_objects]
import git
- repo = git.Repo.clone_from(
- self._small_repo_url(), os.path.join(rw_dir, "repo"), branch="master"
- )
+ repo = git.Repo.clone_from(self._small_repo_url(), os.path.join(rw_dir, "repo"), branch="master")
heads = repo.heads
master = heads.master # lists can be accessed by name for convenience
@@ -302,17 +242,13 @@ class Tutorials(TestBase):
# [5-test_references_and_objects]
new_branch = repo.create_head("new") # create a new one
new_branch.commit = "HEAD~10" # set branch to another commit without changing index or working trees
- repo.delete_head(
- new_branch
- ) # delete an existing head - only works if it is not checked out
+ repo.delete_head(new_branch) # delete an existing head - only works if it is not checked out
# ![5-test_references_and_objects]
# [6-test_references_and_objects]
new_tag = repo.create_tag("my_new_tag", message="my message")
# You cannot change the commit a tag points to. Tags need to be re-created
- self.assertRaises(
- AttributeError, setattr, new_tag, "commit", repo.commit("HEAD~1")
- )
+ self.assertRaises(AttributeError, setattr, new_tag, "commit", repo.commit("HEAD~1"))
repo.delete_tag(new_tag)
# ![6-test_references_and_objects]
@@ -330,9 +266,7 @@ class Tutorials(TestBase):
# ![8-test_references_and_objects]
# [9-test_references_and_objects]
- self.assertEqual(
- hct.type, "tree"
- ) # preset string type, being a class attribute
+ self.assertEqual(hct.type, "tree") # preset string type, being a class attribute
assert hct.size > 0 # size in bytes
assert len(hct.hexsha) == 40
assert len(hct.binsha) == 20
@@ -342,16 +276,12 @@ class Tutorials(TestBase):
self.assertEqual(hct.path, "") # root tree has no path
assert hct.trees[0].path != "" # the first contained item has one though
self.assertEqual(hct.mode, 0o40000) # trees have the mode of a linux directory
- self.assertEqual(
- hct.blobs[0].mode, 0o100644
- ) # blobs have specific mode, comparable to a standard linux fs
+ self.assertEqual(hct.blobs[0].mode, 0o100644) # blobs have specific mode, comparable to a standard linux fs
# ![10-test_references_and_objects]
# [11-test_references_and_objects]
hct.blobs[0].data_stream.read() # stream object to read data from
- hct.blobs[0].stream_data(
- open(os.path.join(rw_dir, "blob_data"), "wb")
- ) # write data to given stream
+ hct.blobs[0].stream_data(open(os.path.join(rw_dir, "blob_data"), "wb")) # write data to given stream
# ![11-test_references_and_objects]
# [12-test_references_and_objects]
@@ -364,9 +294,7 @@ class Tutorials(TestBase):
fifty_first_commits = list(repo.iter_commits("master", max_count=50))
assert len(fifty_first_commits) == 50
# this will return commits 21-30 from the commit list as traversed backwards master
- ten_commits_past_twenty = list(
- repo.iter_commits("master", max_count=10, skip=20)
- )
+ ten_commits_past_twenty = list(repo.iter_commits("master", max_count=10, skip=20))
assert len(ten_commits_past_twenty) == 10
assert fifty_first_commits[20:30] == ten_commits_past_twenty
# ![13-test_references_and_objects]
@@ -406,20 +334,14 @@ class Tutorials(TestBase):
# ![18-test_references_and_objects]
# [19-test_references_and_objects]
- self.assertEqual(
- tree["smmap"], tree / "smmap"
- ) # access by index and by sub-path
+ self.assertEqual(tree["smmap"], tree / "smmap") # access by index and by sub-path
for entry in tree: # intuitive iteration of tree members
print(entry)
blob = tree.trees[1].blobs[0] # let's get a blob in a sub-tree
assert blob.name
assert len(blob.path) < len(blob.abspath)
- self.assertEqual(
- tree.trees[1].name + "/" + blob.name, blob.path
- ) # this is how relative blob path generated
- self.assertEqual(
- tree[blob.path], blob
- ) # you can use paths like 'dir/file' in tree
+ self.assertEqual(tree.trees[1].name + "/" + blob.name, blob.path) # this is how relative blob path generated
+ self.assertEqual(tree[blob.path], blob) # you can use paths like 'dir/file' in tree
# ![19-test_references_and_objects]
# [20-test_references_and_objects]
@@ -432,9 +354,7 @@ class Tutorials(TestBase):
assert repo.tree() == repo.head.commit.tree
past = repo.commit("HEAD~5")
assert repo.tree(past) == repo.tree(past.hexsha)
- self.assertEqual(
- repo.tree("v0.8.1").type, "tree"
- ) # yes, you can provide any refspec - works everywhere
+ self.assertEqual(repo.tree("v0.8.1").type, "tree") # yes, you can provide any refspec - works everywhere
# ![21-test_references_and_objects]
# [22-test_references_and_objects]
@@ -444,9 +364,7 @@ class Tutorials(TestBase):
# [23-test_references_and_objects]
index = repo.index
# The index contains all blobs in a flat list
- assert len(list(index.iter_blobs())) == len(
- [o for o in repo.head.commit.tree.traverse() if o.type == "blob"]
- )
+ assert len(list(index.iter_blobs())) == len([o for o in repo.head.commit.tree.traverse() if o.type == "blob"])
# Access blob objects
for (_path, _stage), entry in index.entries.items():
pass
@@ -454,13 +372,9 @@ class Tutorials(TestBase):
open(new_file_path, "w").close()
index.add([new_file_path]) # add a new file to the index
index.remove(["LICENSE"]) # remove an existing one
- assert os.path.isfile(
- os.path.join(repo.working_tree_dir, "LICENSE")
- ) # working tree is untouched
+ assert os.path.isfile(os.path.join(repo.working_tree_dir, "LICENSE")) # working tree is untouched
- self.assertEqual(
- index.commit("my commit message").type, "commit"
- ) # commit changed index
+ self.assertEqual(index.commit("my commit message").type, "commit") # commit changed index
repo.active_branch.commit = repo.commit("HEAD~1") # forget last commit
from git import Actor
@@ -477,9 +391,7 @@ class Tutorials(TestBase):
# loads a tree into a temporary index, which exists just in memory
IndexFile.from_tree(repo, "HEAD~1")
# merge two trees three-way into memory
- merge_index = IndexFile.from_tree(
- repo, "HEAD~10", "HEAD", repo.merge_base("HEAD~10", "HEAD")
- )
+ merge_index = IndexFile.from_tree(repo, "HEAD~10", "HEAD", repo.merge_base("HEAD~10", "HEAD"))
# and persist it
merge_index.write(os.path.join(rw_dir, "merged_index"))
# ![24-test_references_and_objects]
@@ -491,17 +403,11 @@ class Tutorials(TestBase):
assert origin == empty_repo.remotes.origin == empty_repo.remotes["origin"]
origin.fetch() # assure we actually have data. fetch() returns useful information
# Setup a local tracking branch of a remote branch
- empty_repo.create_head(
- "master", origin.refs.master
- ) # create local branch "master" from remote "master"
- empty_repo.heads.master.set_tracking_branch(
- origin.refs.master
- ) # set local "master" to track remote "master
+ empty_repo.create_head("master", origin.refs.master) # create local branch "master" from remote "master"
+ empty_repo.heads.master.set_tracking_branch(origin.refs.master) # set local "master" to track remote "master
empty_repo.heads.master.checkout() # checkout local "master" to working tree
# Three above commands in one:
- empty_repo.create_head("master", origin.refs.master).set_tracking_branch(
- origin.refs.master
- ).checkout()
+ empty_repo.create_head("master", origin.refs.master).set_tracking_branch(origin.refs.master).checkout()
# rename remotes
origin.rename("new_origin")
# push and pull behaves similarly to `git push|pull`
@@ -563,9 +469,7 @@ class Tutorials(TestBase):
git = repo.git
git.checkout("HEAD", b="my_new_branch") # create a new branch
git.branch("another-new-one")
- git.branch(
- "-D", "another-new-one"
- ) # pass strings for full control over argument order
+ git.branch("-D", "another-new-one") # pass strings for full control over argument order
git.for_each_ref() # '-' becomes '_' when calling it
# ![31-test_references_and_objects]
@@ -578,17 +482,11 @@ class Tutorials(TestBase):
assert len(sms) == 1
sm = sms[0]
- self.assertEqual(
- sm.name, "gitdb"
- ) # git-python has gitdb as single submodule ...
- self.assertEqual(
- sm.children()[0].name, "smmap"
- ) # ... which has smmap as single submodule
+ self.assertEqual(sm.name, "gitdb") # git-python has gitdb as single submodule ...
+ self.assertEqual(sm.children()[0].name, "smmap") # ... which has smmap as single submodule
# The module is the repository referenced by the submodule
- assert (
- sm.module_exists()
- ) # the module is available, which doesn't have to be the case.
+ assert sm.module_exists() # the module is available, which doesn't have to be the case.
assert sm.module().working_tree_dir.endswith("gitdb")
# the submodule's absolute path is the module's path
assert sm.abspath == sm.module().working_tree_dir
diff --git a/test/test_exc.py b/test/test_exc.py
index 6c3353fc..f998ff4d 100644
--- a/test/test_exc.py
+++ b/test/test_exc.py
@@ -82,9 +82,7 @@ class TExc(TestBase):
for ex_class in exception_classes:
self.assertTrue(issubclass(ex_class, GitError))
- @ddt.data(
- *list(itt.product(_cmd_argvs, _causes_n_substrings, _streams_n_substrings))
- )
+ @ddt.data(*list(itt.product(_cmd_argvs, _causes_n_substrings, _streams_n_substrings)))
def test_CommandError_unicode(self, case):
argv, (cause, subs), stream = case
cls = CommandError
diff --git a/test/test_fun.py b/test/test_fun.py
index 7c99a4a1..d76e189e 100644
--- a/test/test_fun.py
+++ b/test/test_fun.py
@@ -25,10 +25,7 @@ from gitdb.typ import str_tree_type
class TestFun(TestBase):
def _assert_index_entries(self, entries, trees):
- index = IndexFile.from_tree(
- self.rorepo,
- *[self.rorepo.tree(bin_to_hex(t).decode("ascii")) for t in trees]
- )
+ index = IndexFile.from_tree(self.rorepo, *[self.rorepo.tree(bin_to_hex(t).decode("ascii")) for t in trees])
assert entries
assert len(index.entries) == len(entries)
for entry in entries:
@@ -191,11 +188,7 @@ class TestFun(TestBase):
if is_them:
trees = [tb, tb, th]
entries = aggressive_tree_merge(odb, trees)
- assert (
- len(entries) == 1
- and entries[0].binsha == shaa
- and entries[0].mode == fa[1]
- )
+ assert len(entries) == 1 and entries[0].binsha == shaa and entries[0].mode == fa[1]
# one side deletes, the other changes = conflict
fa = mkfile(bfn, shab)
@@ -245,9 +238,7 @@ class TestFun(TestBase):
H = self.rorepo.tree("29eb123beb1c55e5db4aa652d843adccbd09ae18") # head tree
M = self.rorepo.tree("e14e3f143e7260de9581aee27e5a9b2645db72de") # merge tree
B = self.rorepo.tree("f606937a7a21237c866efafcad33675e6539c103") # base tree
- B_old = self.rorepo.tree(
- "1f66cfbbce58b4b552b041707a12d437cc5f400a"
- ) # old base tree
+ B_old = self.rorepo.tree("1f66cfbbce58b4b552b041707a12d437cc5f400a") # old base tree
# two very different trees
entries = traverse_trees_recursive(odb, [B_old.binsha, H.binsha], "")
@@ -275,9 +266,7 @@ class TestFun(TestBase):
max_count = 50
count = 0
odb = self.rorepo.odb
- for commit in self.rorepo.commit(
- "29eb123beb1c55e5db4aa652d843adccbd09ae18"
- ).traverse():
+ for commit in self.rorepo.commit("29eb123beb1c55e5db4aa652d843adccbd09ae18").traverse():
if count >= max_count:
break
count += 1
diff --git a/test/test_git.py b/test/test_git.py
index 2a034e41..6ba833b4 100644
--- a/test/test_git.py
+++ b/test/test_git.py
@@ -56,15 +56,9 @@ class TestGit(TestBase):
self.assertEqual(["-s", "5"], self.git.transform_kwargs(**{"s": 5}))
self.assertEqual([], self.git.transform_kwargs(**{"s": None}))
- self.assertEqual(
- ["--max-count"], self.git.transform_kwargs(**{"max_count": True})
- )
- self.assertEqual(
- ["--max-count=5"], self.git.transform_kwargs(**{"max_count": 5})
- )
- self.assertEqual(
- ["--max-count=0"], self.git.transform_kwargs(**{"max_count": 0})
- )
+ self.assertEqual(["--max-count"], self.git.transform_kwargs(**{"max_count": True}))
+ self.assertEqual(["--max-count=5"], self.git.transform_kwargs(**{"max_count": 5}))
+ self.assertEqual(["--max-count=0"], self.git.transform_kwargs(**{"max_count": 0}))
self.assertEqual([], self.git.transform_kwargs(**{"max_count": None}))
# Multiple args are supported by using lists/tuples
@@ -72,18 +66,14 @@ class TestGit(TestBase):
["-L", "1-3", "-L", "12-18"],
self.git.transform_kwargs(**{"L": ("1-3", "12-18")}),
)
- self.assertEqual(
- ["-C", "-C"], self.git.transform_kwargs(**{"C": [True, True, None, False]})
- )
+ self.assertEqual(["-C", "-C"], self.git.transform_kwargs(**{"C": [True, True, None, False]}))
# order is undefined
res = self.git.transform_kwargs(**{"s": True, "t": True})
self.assertEqual({"-s", "-t"}, set(res))
def test_it_executes_git_to_shell_and_returns_result(self):
- self.assertRegex(
- self.git.execute(["git", "version"]), r"^git version [\d\.]{2}.*$"
- )
+ self.assertRegex(self.git.execute(["git", "version"]), r"^git version [\d\.]{2}.*$")
def test_it_accepts_stdin(self):
filename = fixture_path("cat_file_blob")
@@ -126,9 +116,7 @@ class TestGit(TestBase):
def test_persistent_cat_file_command(self):
# read header only
hexsha = "b2339455342180c7cc1e9bba3e9f181f7baa5167"
- g = self.git.cat_file(
- batch_check=True, istream=subprocess.PIPE, as_process=True
- )
+ g = self.git.cat_file(batch_check=True, istream=subprocess.PIPE, as_process=True)
g.stdin.write(b"b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
g.stdin.flush()
obj_info = g.stdout.readline()
@@ -207,9 +195,7 @@ class TestGit(TestBase):
def test_single_char_git_options_are_passed_to_git(self):
input_value = "TestValue"
- output_value = self.git(c="user.name=%s" % input_value).config(
- "--get", "user.name"
- )
+ output_value = self.git(c="user.name=%s" % input_value).config("--get", "user.name")
self.assertEqual(input_value, output_value)
def test_change_to_transform_kwargs_does_not_break_command_options(self):
@@ -221,9 +207,7 @@ class TestGit(TestBase):
def test_env_vars_passed_to_git(self):
editor = "non_existent_editor"
- with mock.patch.dict(
- "os.environ", {"GIT_EDITOR": editor}
- ): # @UndefinedVariable
+ with mock.patch.dict("os.environ", {"GIT_EDITOR": editor}): # @UndefinedVariable
self.assertEqual(self.git.var("GIT_EDITOR"), editor)
@with_rw_directory
diff --git a/test/test_index.py b/test/test_index.py
index 3f88f5c5..d6e0fb81 100644
--- a/test/test_index.py
+++ b/test/test_index.py
@@ -141,9 +141,7 @@ class TestIndex(TestBase):
tree = self.rorepo.commit(tree).tree
blist = []
- for blob in tree.traverse(
- predicate=lambda e, d: e.type == "blob", branch_first=False
- ):
+ for blob in tree.traverse(predicate=lambda e, d: e.type == "blob", branch_first=False):
assert (blob.path, 0) in index.entries
blist.append(blob)
# END for each blob in tree
@@ -151,8 +149,7 @@ class TestIndex(TestBase):
iset = {k[0] for k in index.entries.keys()}
bset = {b.path for b in blist}
raise AssertionError(
- "CMP Failed: Missing entries in index: %s, missing in tree: %s"
- % (bset - iset, iset - bset)
+ "CMP Failed: Missing entries in index: %s, missing in tree: %s" % (bset - iset, iset - bset)
)
# END assertion message
@@ -192,9 +189,7 @@ class TestIndex(TestBase):
self._cmp_tree_index(cur_sha, two_way_index)
# merge three trees - here we have a merge conflict
- three_way_index = IndexFile.from_tree(
- rw_repo, common_ancestor_sha, cur_sha, other_sha
- )
+ three_way_index = IndexFile.from_tree(rw_repo, common_ancestor_sha, cur_sha, other_sha)
assert len([e for e in three_way_index.entries.values() if e.stage != 0])
# ITERATE BLOBS
@@ -244,18 +239,14 @@ class TestIndex(TestBase):
assert manifest_entry.binsha != rw_repo.index.entries[manifest_key].binsha
rw_repo.index.reset(rw_repo.head)
- self.assertEqual(
- rw_repo.index.entries[manifest_key].binsha, manifest_entry.binsha
- )
+ self.assertEqual(rw_repo.index.entries[manifest_key].binsha, manifest_entry.binsha)
# FAKE MERGE
#############
# Add a change with a NULL sha that should conflict with next_commit. We
# pretend there was a change, but we do not even bother adding a proper
# sha for it ( which makes things faster of course )
- manifest_fake_entry = BaseIndexEntry(
- (manifest_entry[0], b"\0" * 20, 0, manifest_entry[3])
- )
+ manifest_fake_entry = BaseIndexEntry((manifest_entry[0], b"\0" * 20, 0, manifest_entry[3]))
# try write flag
self._assert_entries(rw_repo.index.add([manifest_fake_entry], write=False))
# add actually resolves the null-hex-sha for us as a feature, but we can
@@ -274,9 +265,7 @@ class TestIndex(TestBase):
# a three way merge would result in a conflict and fails as the command will
# not overwrite any entries in our index and hence leave them unmerged. This is
# mainly a protection feature as the current index is not yet in a tree
- self.assertRaises(
- GitCommandError, index.merge_tree, next_commit, base=parent_commit
- )
+ self.assertRaises(GitCommandError, index.merge_tree, next_commit, base=parent_commit)
# the only way to get the merged entries is to safe the current index away into a tree,
# which is like a temporary commit for us. This fails as well as the NULL sha deos not
@@ -286,9 +275,7 @@ class TestIndex(TestBase):
# if missing objects are okay, this would work though ( they are always okay now )
# As we can't read back the tree with NULL_SHA, we rather set it to something else
- index.entries[manifest_key] = IndexEntry(
- manifest_entry[:1] + (hex_to_bin("f" * 40),) + manifest_entry[2:]
- )
+ index.entries[manifest_key] = IndexEntry(manifest_entry[:1] + (hex_to_bin("f" * 40),) + manifest_entry[2:])
tree = index.write_tree()
# now make a proper three way merge with unmerged entries
@@ -476,9 +463,7 @@ class TestIndex(TestBase):
# END mixed iterator
deleted_files = index.remove(mixed_iterator(), working_tree=False)
assert deleted_files
- self.assertEqual(
- self._count_existing(rw_repo, deleted_files), len(deleted_files)
- )
+ self.assertEqual(self._count_existing(rw_repo, deleted_files), len(deleted_files))
self.assertEqual(len(index.entries), 0)
# reset the index to undo our changes
@@ -492,17 +477,13 @@ class TestIndex(TestBase):
# reset everything
index.reset(working_tree=True)
- self.assertEqual(
- self._count_existing(rw_repo, deleted_files), len(deleted_files)
- )
+ self.assertEqual(self._count_existing(rw_repo, deleted_files), len(deleted_files))
# invalid type
self.assertRaises(TypeError, index.remove, [1])
# absolute path
- deleted_files = index.remove(
- [osp.join(rw_repo.working_tree_dir, "lib")], r=True
- )
+ deleted_files = index.remove([osp.join(rw_repo.working_tree_dir, "lib")], r=True)
assert len(deleted_files) > 1
self.assertRaises(ValueError, index.remove, ["/doesnt/exists"])
@@ -527,9 +508,7 @@ class TestIndex(TestBase):
my_author = Actor("Frèderic Çaufl€", "author@example.com")
my_committer = Actor("Committing Frèderic Çaufl€", "committer@example.com")
- commit_actor = index.commit(
- commit_message, author=my_author, committer=my_committer
- )
+ commit_actor = index.commit(commit_message, author=my_author, committer=my_committer)
assert cur_commit != commit_actor
self.assertEqual(commit_actor.author.name, "Frèderic Çaufl€")
self.assertEqual(commit_actor.author.email, "author@example.com")
@@ -565,9 +544,7 @@ class TestIndex(TestBase):
# same index, multiple parents
commit_message = "Index with multiple parents\n commit with another line"
- commit_multi_parent = index.commit(
- commit_message, parent_commits=(commit_no_parents, new_commit)
- )
+ commit_multi_parent = index.commit(commit_message, parent_commits=(commit_no_parents, new_commit))
self.assertEqual(commit_multi_parent.message, commit_message)
self.assertEqual(len(commit_multi_parent.parents), 2)
self.assertEqual(commit_multi_parent.parents[0], commit_no_parents)
@@ -576,9 +553,7 @@ class TestIndex(TestBase):
# re-add all files in lib
# get the lib folder back on disk, but get an index without it
- index.reset(new_commit.parents[0], working_tree=True).reset(
- new_commit, working_tree=False
- )
+ index.reset(new_commit.parents[0], working_tree=True).reset(new_commit, working_tree=False)
lib_file_path = osp.join("lib", "git", "__init__.py")
assert (lib_file_path, 0) not in index.entries
assert osp.isfile(osp.join(rw_repo.working_tree_dir, lib_file_path))
@@ -590,9 +565,7 @@ class TestIndex(TestBase):
assert len(entries) > 1
# glob
- entries = index.reset(new_commit).add(
- [osp.join("lib", "git", "*.py")], fprogress=self._fprogress_add
- )
+ entries = index.reset(new_commit).add([osp.join("lib", "git", "*.py")], fprogress=self._fprogress_add)
self._assert_entries(entries)
self._assert_fprogress(entries)
self.assertEqual(len(entries), 14)
@@ -610,9 +583,7 @@ class TestIndex(TestBase):
self.assertEqual(len(entries), 2)
# missing path
- self.assertRaises(
- OSError, index.reset(new_commit).add, ["doesnt/exist/must/raise"]
- )
+ self.assertRaises(OSError, index.reset(new_commit).add, ["doesnt/exist/must/raise"])
# blob from older revision overrides current index revision
old_blob = new_commit.parents[0].tree.blobs[0]
@@ -650,16 +621,12 @@ class TestIndex(TestBase):
link_file = osp.join(rw_repo.working_tree_dir, basename)
os.symlink(target, link_file)
- entries = index.reset(new_commit).add(
- [link_file], fprogress=self._fprogress_add
- )
+ entries = index.reset(new_commit).add([link_file], fprogress=self._fprogress_add)
self._assert_entries(entries)
self._assert_fprogress(entries)
self.assertEqual(len(entries), 1)
self.assertTrue(S_ISLNK(entries[0].mode))
- self.assertTrue(
- S_ISLNK(index.entries[index.entry_key("my_real_symlink", 0)].mode)
- )
+ self.assertTrue(S_ISLNK(index.entries[index.entry_key("my_real_symlink", 0)].mode))
# we expect only the target to be written
self.assertEqual(
@@ -676,9 +643,7 @@ class TestIndex(TestBase):
link_target = "/etc/that"
fake_symlink_path = self._make_file(fake_symlink_relapath, link_target, rw_repo)
fake_entry = BaseIndexEntry((0o120000, null_bin_sha, 0, fake_symlink_relapath))
- entries = index.reset(new_commit).add(
- [fake_entry], fprogress=self._fprogress_add
- )
+ entries = index.reset(new_commit).add([fake_entry], fprogress=self._fprogress_add)
self._assert_entries(entries)
self._assert_fprogress(entries)
assert entries[0].hexsha != null_hex_sha
@@ -686,9 +651,7 @@ class TestIndex(TestBase):
self.assertTrue(S_ISLNK(entries[0].mode))
# assure this also works with an alternate method
- full_index_entry = IndexEntry.from_base(
- BaseIndexEntry((0o120000, entries[0].binsha, 0, entries[0].path))
- )
+ full_index_entry = IndexEntry.from_base(BaseIndexEntry((0o120000, entries[0].binsha, 0, entries[0].path)))
entry_key = index.entry_key(full_index_entry)
index.reset(new_commit)
@@ -926,9 +889,7 @@ class TestIndex(TestBase):
@with_rw_repo("HEAD", bare=True)
def test_pre_commit_hook_fail(self, rw_repo):
index = rw_repo.index
- hp = _make_hook(
- index.repo.git_dir, "pre-commit", "echo stdout; echo stderr 1>&2; exit 1"
- )
+ hp = _make_hook(index.repo.git_dir, "pre-commit", "echo stdout; echo stderr 1>&2; exit 1")
try:
index.commit("This should fail")
except HookExecutionError as err:
@@ -959,16 +920,12 @@ class TestIndex(TestBase):
'printf " {}" >> "$1"'.format(from_hook_message),
)
new_commit = index.commit(commit_message)
- self.assertEqual(
- new_commit.message, "{} {}".format(commit_message, from_hook_message)
- )
+ self.assertEqual(new_commit.message, "{} {}".format(commit_message, from_hook_message))
@with_rw_repo("HEAD", bare=True)
def test_commit_msg_hook_fail(self, rw_repo):
index = rw_repo.index
- hp = _make_hook(
- index.repo.git_dir, "commit-msg", "echo stdout; echo stderr 1>&2; exit 1"
- )
+ hp = _make_hook(index.repo.git_dir, "commit-msg", "echo stdout; echo stderr 1>&2; exit 1")
try:
index.commit("This should fail")
except HookExecutionError as err:
diff --git a/test/test_installation.py b/test/test_installation.py
index 2607ff4e..c092aef5 100644
--- a/test/test_installation.py
+++ b/test/test_installation.py
@@ -41,9 +41,7 @@ class TestInstallation(TestBase):
result.returncode,
msg=result.stderr or result.stdout or "Can't build - setup.py failed",
)
- result = subprocess.run(
- [self.python, "-c", "import git"], stdout=subprocess.PIPE, cwd=self.sources
- )
+ result = subprocess.run([self.python, "-c", "import git"], stdout=subprocess.PIPE, cwd=self.sources)
self.assertEqual(
0,
result.returncode,
@@ -61,6 +59,4 @@ class TestInstallation(TestBase):
syspath[0],
msg="Failed to follow the conventions for https://docs.python.org/3/library/sys.html#sys.path",
)
- self.assertTrue(
- syspath[1].endswith("gitdb"), msg="Failed to add gitdb to sys.path"
- )
+ self.assertTrue(syspath[1].endswith("gitdb"), msg="Failed to add gitdb to sys.path")
diff --git a/test/test_reflog.py b/test/test_reflog.py
index c126d3dc..e899ac48 100644
--- a/test/test_reflog.py
+++ b/test/test_reflog.py
@@ -16,9 +16,7 @@ class TestRefLog(TestBase):
actor = Actor("name", "email")
msg = "message"
- self.assertRaises(
- ValueError, RefLogEntry.new, nullhexsha, hexsha, "noactor", 0, 0, ""
- )
+ self.assertRaises(ValueError, RefLogEntry.new, nullhexsha, hexsha, "noactor", 0, 0, "")
e = RefLogEntry.new(nullhexsha, hexsha, actor, 0, 1, msg)
assert e.oldhexsha == nullhexsha
@@ -78,9 +76,7 @@ class TestRefLog(TestBase):
assert open(tfile).read() == open(rlp).read()
# append an entry
- entry = RefLog.append_entry(
- cr, tfile, IndexObject.NULL_BIN_SHA, binsha, msg
- )
+ entry = RefLog.append_entry(cr, tfile, IndexObject.NULL_BIN_SHA, binsha, msg)
assert entry.oldhexsha == IndexObject.NULL_HEX_SHA
assert entry.newhexsha == "f" * 40
assert entry.message == msg
diff --git a/test/test_refs.py b/test/test_refs.py
index ee4ec86f..605648b0 100644
--- a/test/test_refs.py
+++ b/test/test_refs.py
@@ -117,22 +117,16 @@ class TestRefs(TestBase):
assert head.tracking_branch() is None
special_name = "feature#123"
- special_name_remote_ref = SymbolicReference.create(
- rwrepo, "refs/remotes/origin/%s" % special_name
- )
+ special_name_remote_ref = SymbolicReference.create(rwrepo, "refs/remotes/origin/%s" % special_name)
gp_tracking_branch = rwrepo.create_head("gp_tracking#123")
- special_name_remote_ref = rwrepo.remotes[0].refs[
- special_name
- ] # get correct type
+ special_name_remote_ref = rwrepo.remotes[0].refs[special_name] # get correct type
gp_tracking_branch.set_tracking_branch(special_name_remote_ref)
TBranch = gp_tracking_branch.tracking_branch()
if TBranch is not None:
assert TBranch.path == special_name_remote_ref.path
git_tracking_branch = rwrepo.create_head("git_tracking#123")
- rwrepo.git.branch(
- "-u", special_name_remote_ref.name, git_tracking_branch.name
- )
+ rwrepo.git.branch("-u", special_name_remote_ref.name, git_tracking_branch.name)
TBranch = gp_tracking_branch.tracking_branch()
if TBranch is not None:
assert TBranch.name == special_name_remote_ref.name
@@ -172,9 +166,7 @@ class TestRefs(TestBase):
assert len(cur_head.log()) == blog_len + 2
# a new branch has just a single entry
- other_head = Head.create(
- rwrepo, "mynewhead", pcommit, logmsg="new head created"
- )
+ other_head = Head.create(rwrepo, "mynewhead", pcommit, logmsg="new head created")
log = other_head.log()
assert len(log) == 1
assert log[0].oldhexsha == pcommit.NULL_HEX_SHA
@@ -209,9 +201,7 @@ class TestRefs(TestBase):
cur_head.reset(new_head_commit, index=True) # index only
assert cur_head.reference.commit == new_head_commit
- self.assertRaises(
- ValueError, cur_head.reset, new_head_commit, index=False, working_tree=True
- )
+ self.assertRaises(ValueError, cur_head.reset, new_head_commit, index=False, working_tree=True)
new_head_commit = new_head_commit.parents[0]
cur_head.reset(new_head_commit, index=True, working_tree=True) # index + wt
assert cur_head.reference.commit == new_head_commit
@@ -279,9 +269,7 @@ class TestRefs(TestBase):
Head.create(rw_repo, new_name, new_head.commit)
# its not fine with a different value
- self.assertRaises(
- OSError, Head.create, rw_repo, new_name, new_head.commit.parents[0]
- )
+ self.assertRaises(OSError, Head.create, rw_repo, new_name, new_head.commit.parents[0])
# force it
new_head = Head.create(rw_repo, new_name, actual_commit, force=True)
@@ -290,9 +278,7 @@ class TestRefs(TestBase):
assert new_head.rename("hello").name == "hello"
assert new_head.rename("hello/world").name == "hello/world"
- assert (
- new_head.rename(old_name).name == old_name and new_head.path == old_path
- )
+ assert new_head.rename(old_name).name == old_name and new_head.path == old_path
# rename with force
tmp_head = Head.create(rw_repo, "tmphead")
@@ -454,9 +440,7 @@ class TestRefs(TestBase):
# END for each name type
# References that don't exist trigger an error if we want to access them
- self.assertRaises(
- ValueError, getattr, Reference(rw_repo, "refs/doesntexist"), "commit"
- )
+ self.assertRaises(ValueError, getattr, Reference(rw_repo, "refs/doesntexist"), "commit")
# exists, fail unless we force
ex_ref_path = far_away_head.path
@@ -481,10 +465,7 @@ class TestRefs(TestBase):
cur_head.reference.commit,
)
# it works if the new ref points to the same reference
- assert (
- SymbolicReference.create(rw_repo, symref.path, symref.reference).path
- == symref.path
- ) # @NoEffect
+ assert SymbolicReference.create(rw_repo, symref.path, symref.reference).path == symref.path # @NoEffect
SymbolicReference.delete(rw_repo, symref)
# would raise if the symref wouldn't have been deletedpbl
symref = SymbolicReference.create(rw_repo, symref_path, cur_head.reference)
diff --git a/test/test_remote.py b/test/test_remote.py
index 53f71e3d..7df64c20 100644
--- a/test/test_remote.py
+++ b/test/test_remote.py
@@ -70,17 +70,11 @@ class TestRemoteProgress(RemoteProgress):
assert not message, "should not have message when remote begins writing"
elif op_code & self.END > 0:
assert message
- assert not message.startswith(", "), (
- "Sanitize progress messages: '%s'" % message
- )
- assert not message.endswith(", "), (
- "Sanitize progress messages: '%s'" % message
- )
+ assert not message.startswith(", "), "Sanitize progress messages: '%s'" % message
+ assert not message.endswith(", "), "Sanitize progress messages: '%s'" % message
self._stages_per_op.setdefault(op_id, 0)
- self._stages_per_op[op_id] = self._stages_per_op[op_id] | (
- op_code & self.STAGE_MASK
- )
+ self._stages_per_op[op_id] = self._stages_per_op[op_id] | (op_code & self.STAGE_MASK)
if op_code & (self.WRITING | self.END) == (self.WRITING | self.END):
assert message
@@ -184,9 +178,7 @@ class TestRemote(TestBase):
# Create a file with a random name and random data and commit it to repo.
# Return the committed absolute file path
index = repo.index
- new_file = self._make_file(
- osp.basename(tempfile.mktemp()), str(random.random()), repo
- )
+ new_file = self._make_file(osp.basename(tempfile.mktemp()), str(random.random()), repo)
index.add([new_file])
index.commit("Committing %s" % new_file)
return new_file
@@ -304,12 +296,8 @@ class TestRemote(TestBase):
# must clone with a local path for the repo implementation not to freak out
# as it wants local paths only ( which I can understand )
other_repo = remote_repo.clone(other_repo_dir, shared=False)
- remote_repo_url = osp.basename(
- remote_repo.git_dir
- ) # git-daemon runs with appropriate `--base-path`.
- remote_repo_url = Git.polish_url(
- "git://localhost:%s/%s" % (GIT_DAEMON_PORT, remote_repo_url)
- )
+ remote_repo_url = osp.basename(remote_repo.git_dir) # git-daemon runs with appropriate `--base-path`.
+ remote_repo_url = Git.polish_url("git://localhost:%s/%s" % (GIT_DAEMON_PORT, remote_repo_url))
# put origin to git-url
other_origin = other_repo.remotes.origin
@@ -379,9 +367,7 @@ class TestRemote(TestBase):
progress = TestRemoteProgress()
to_be_updated = "my_tag.1.0RV"
new_tag = TagReference.create(rw_repo, to_be_updated) # @UnusedVariable
- other_tag = TagReference.create(
- rw_repo, "my_obj_tag.2.1aRV", logmsg="my message"
- )
+ other_tag = TagReference.create(rw_repo, "my_obj_tag.2.1aRV", logmsg="my message")
res = remote.push(progress=progress, tags=True)
self.assertTrue(res[-1].flags & PushInfo.NEW_TAG)
progress.make_assertion()
@@ -389,9 +375,7 @@ class TestRemote(TestBase):
# update push new tags
# Rejection is default
- new_tag = TagReference.create(
- rw_repo, to_be_updated, reference="HEAD~1", force=True
- )
+ new_tag = TagReference.create(rw_repo, to_be_updated, reference="HEAD~1", force=True)
res = remote.push(tags=True)
self._do_test_push_result(res, remote)
self.assertTrue(res[-1].flags & PushInfo.REJECTED)
@@ -503,9 +487,7 @@ class TestRemote(TestBase):
# Only for remotes - local cases are the same or less complicated
# as additional progress information will never be emitted
if remote.name == "daemon_origin":
- self._do_test_fetch(
- remote, rw_repo, remote_repo, kill_after_timeout=10.0
- )
+ self._do_test_fetch(remote, rw_repo, remote_repo, kill_after_timeout=10.0)
ran_fetch_test = True
# END fetch test
@@ -554,9 +536,7 @@ class TestRemote(TestBase):
self.assertRaises(GitCommandError, Remote.create, bare_rw_repo, *arg_list)
Remote.remove(bare_rw_repo, new_name)
- self.assertTrue(
- remote.exists()
- ) # We still have a cache that doesn't know we were deleted by name
+ self.assertTrue(remote.exists()) # We still have a cache that doesn't know we were deleted by name
remote._clear_cache()
assert not remote.exists() # Cache should be renewed now. This is an issue ...
@@ -571,9 +551,7 @@ class TestRemote(TestBase):
def test_fetch_info(self):
# assure we can handle remote-tracking branches
- fetch_info_line_fmt = (
- "c437ee5deb8d00cf02f03720693e4c802e99f390 not-for-merge %s '0.3' of "
- )
+ fetch_info_line_fmt = "c437ee5deb8d00cf02f03720693e4c802e99f390 not-for-merge %s '0.3' of "
fetch_info_line_fmt += "git://github.com/gitpython-developers/GitPython"
remote_info_line_fmt = "* [new branch] nomatter -> %s"
@@ -617,9 +595,7 @@ class TestRemote(TestBase):
# it can also be anywhere !
tag_path = "refs/something/remotename/tags/tagname"
- fi = FetchInfo._from_line(
- self.rorepo, remote_info_line_fmt % tag_path, fetch_info_line_fmt % "tag"
- )
+ fi = FetchInfo._from_line(self.rorepo, remote_info_line_fmt % tag_path, fetch_info_line_fmt % "tag")
self.assertIsInstance(fi.ref, TagReference)
self.assertEqual(fi.ref.path, tag_path)
@@ -645,12 +621,8 @@ class TestRemote(TestBase):
self.assertEqual(fi.ref.path, "refs/something/branch")
def test_uncommon_branch_names(self):
- stderr_lines = (
- fixture("uncommon_branch_prefix_stderr").decode("ascii").splitlines()
- )
- fetch_lines = (
- fixture("uncommon_branch_prefix_FETCH_HEAD").decode("ascii").splitlines()
- )
+ stderr_lines = fixture("uncommon_branch_prefix_stderr").decode("ascii").splitlines()
+ fetch_lines = fixture("uncommon_branch_prefix_FETCH_HEAD").decode("ascii").splitlines()
# The contents of the files above must be fetched with a custom refspec:
# +refs/pull/*:refs/heads/pull/*
@@ -709,17 +681,13 @@ class TestRemote(TestBase):
def test_fetch_error(self):
rem = self.rorepo.remote("origin")
- with self.assertRaisesRegex(
- GitCommandError, "[Cc]ouldn't find remote ref __BAD_REF__"
- ):
+ with self.assertRaisesRegex(GitCommandError, "[Cc]ouldn't find remote ref __BAD_REF__"):
rem.fetch("__BAD_REF__")
@with_rw_repo("0.1.6", bare=False)
def test_push_error(self, repo):
rem = repo.remote("origin")
- with self.assertRaisesRegex(
- GitCommandError, "src refspec __BAD_REF__ does not match any"
- ):
+ with self.assertRaisesRegex(GitCommandError, "src refspec __BAD_REF__ does not match any"):
rem.push("__BAD_REF__")
diff --git a/test/test_repo.py b/test/test_repo.py
index 7cffbbd8..30db1392 100644
--- a/test/test_repo.py
+++ b/test/test_repo.py
@@ -69,9 +69,7 @@ class TestRepo(TestBase):
def tearDown(self):
for lfp in glob.glob(_tc_lock_fpaths):
if osp.isfile(lfp):
- raise AssertionError(
- "Previous TC left hanging git-lock file: {}".format(lfp)
- )
+ raise AssertionError("Previous TC left hanging git-lock file: {}".format(lfp))
import gc
gc.collect()
@@ -137,9 +135,7 @@ class TestRepo(TestBase):
c = commits[0]
self.assertEqual("9a4b1d4d11eee3c5362a4152216376e634bd14cf", c.hexsha)
- self.assertEqual(
- ["c76852d0bff115720af3f27acdb084c59361e5f6"], [p.hexsha for p in c.parents]
- )
+ self.assertEqual(["c76852d0bff115720af3f27acdb084c59361e5f6"], [p.hexsha for p in c.parents])
self.assertEqual("ce41fc29549042f1aa09cc03174896cf23f112e3", c.tree.hexsha)
self.assertEqual("Michael Trier", c.author.name)
self.assertEqual("mtrier@gmail.com", c.author.email)
@@ -195,9 +191,7 @@ class TestRepo(TestBase):
original_repo = Repo.init(osp.join(rw_dir, "repo"))
environment = {"entry1": "value", "another_entry": "10"}
- cloned = Repo.clone_from(
- original_repo.git_dir, osp.join(rw_dir, "clone"), env=environment
- )
+ cloned = Repo.clone_from(original_repo.git_dir, osp.join(rw_dir, "clone"), env=environment)
self.assertEqual(environment, cloned.git.environment())
@@ -228,13 +222,9 @@ class TestRepo(TestBase):
],
)
- self.assertEqual(
- cloned.config_reader().get_value("submodule", "active"), "repo"
- )
+ self.assertEqual(cloned.config_reader().get_value("submodule", "active"), "repo")
self.assertEqual(cloned.config_reader().get_value("core", "filemode"), False)
- self.assertEqual(
- cloned.config_reader().get_value('submodule "repo"', "update"), "checkout"
- )
+ self.assertEqual(cloned.config_reader().get_value('submodule "repo"', "update"), "checkout")
self.assertEqual(
cloned.config_reader().get_value('filter "lfs"', "clean"),
"git-lfs clean -- %f",
@@ -259,15 +249,11 @@ class TestRepo(TestBase):
password = "fakepassword1234"
try:
Repo.clone_from(
- url="https://fakeuser:{}@fakerepo.example.com/testrepo".format(
- password
- ),
+ url="https://fakeuser:{}@fakerepo.example.com/testrepo".format(password),
to_path=rw_dir,
)
except GitCommandError as err:
- assert password not in str(err), (
- "The error message '%s' should not contain the password" % err
- )
+ assert password not in str(err), "The error message '%s' should not contain the password" % err
# Working example from a blank private project
Repo.clone_from(
url="https://gitlab+deploy-token-392045:mLWhVus7bjLsy8xj8q2V@gitlab.com/mercierm/test_git_python",
@@ -284,9 +270,7 @@ class TestRepo(TestBase):
self.assertTrue(len(b) <= self.max_chunk_size)
for chunk_size in [16, 128, 1024]:
- repo.git.status(
- output_stream=TestOutputStream(chunk_size), max_chunk_size=chunk_size
- )
+ repo.git.status(output_stream=TestOutputStream(chunk_size), max_chunk_size=chunk_size)
repo.git.log(
n=100,
@@ -394,9 +378,7 @@ class TestRepo(TestBase):
for index in (0, 1):
for working_tree in (0, 1):
for untracked_files in (0, 1):
- assert self.rorepo.is_dirty(
- index, working_tree, untracked_files
- ) in (True, False)
+ assert self.rorepo.is_dirty(index, working_tree, untracked_files) in (True, False)
# END untracked files
# END working tree
# END index
@@ -410,9 +392,7 @@ class TestRepo(TestBase):
for index in (0, 1):
for working_tree in (0, 1):
for untracked_files in (0, 1):
- assert self.rorepo.is_dirty(
- index, working_tree, untracked_files, path=":!foo"
- ) in (True, False)
+ assert self.rorepo.is_dirty(index, working_tree, untracked_files, path=":!foo") in (True, False)
# END untracked files
# END working tree
# END index
@@ -440,9 +420,7 @@ class TestRepo(TestBase):
assert rwrepo.is_dirty(untracked_files=True, path="doc") is True
def test_head(self):
- self.assertEqual(
- self.rorepo.head.reference.object, self.rorepo.active_branch.object
- )
+ self.assertEqual(self.rorepo.head.reference.object, self.rorepo.active_branch.object)
def test_index(self):
index = self.rorepo.index
@@ -496,9 +474,7 @@ class TestRepo(TestBase):
tlist = b[0][1]
self.assertTrue(tlist)
self.assertTrue(isinstance(tlist[0], str))
- self.assertTrue(
- len(tlist) < sum(len(t) for t in tlist)
- ) # test for single-char bug
+ self.assertTrue(len(tlist) < sum(len(t) for t in tlist)) # test for single-char bug
# BINARY BLAME
git.return_value = fixture("blame_binary")
@@ -517,18 +493,14 @@ class TestRepo(TestBase):
nml += int(len(b[1]) > 1)
# END for each item to traverse
assert c, "Should have executed at least one blame command"
- assert (
- nml
- ), "There should at least be one blame commit that contains multiple lines"
+ assert nml, "There should at least be one blame commit that contains multiple lines"
@mock.patch.object(Git, "_call_process")
def test_blame_incremental(self, git):
# loop over two fixtures, create a test fixture for 2.11.1+ syntax
for git_fixture in ("blame_incremental", "blame_incremental_2.11.1_plus"):
git.return_value = fixture(git_fixture)
- blame_output = self.rorepo.blame_incremental(
- "9debf6b0aafb6f7781ea9d1383c86939a1aacde3", "AUTHORS"
- )
+ blame_output = self.rorepo.blame_incremental("9debf6b0aafb6f7781ea9d1383c86939a1aacde3", "AUTHORS")
blame_output = list(blame_output)
self.assertEqual(len(blame_output), 5)
@@ -548,9 +520,7 @@ class TestRepo(TestBase):
)
commits = [entry.commit.hexsha[:7] for entry in blame_output]
- self.assertEqual(
- commits, ["82b8902", "82b8902", "c76852d", "c76852d", "c76852d"]
- )
+ self.assertEqual(commits, ["82b8902", "82b8902", "c76852d", "c76852d", "c76852d"])
# Original filenames
self.assertSequenceEqual(
@@ -615,9 +585,7 @@ class TestRepo(TestBase):
self.assertEqual(len(files), num_test_untracked)
repo_add(untracked_files)
- self.assertEqual(
- len(rwrepo.untracked_files), (num_recently_untracked - len(files))
- )
+ self.assertEqual(len(rwrepo.untracked_files), (num_recently_untracked - len(files)))
# end for each run
def test_config_reader(self):
@@ -826,9 +794,7 @@ class TestRepo(TestBase):
rev_parse = self.rorepo.rev_parse
# try special case: This one failed at some point, make sure its fixed
- self.assertEqual(
- rev_parse("33ebe").hexsha, "33ebe7acec14b25c5f84f35a664803fcab2f7781"
- )
+ self.assertEqual(rev_parse("33ebe").hexsha, "33ebe7acec14b25c5f84f35a664803fcab2f7781")
# start from reference
num_resolved = 0
@@ -1099,9 +1065,7 @@ class TestRepo(TestBase):
self.assertTrue(repo.is_valid_object(tag_sha, "tag"))
# Check for invalid objects
- self.assertFalse(
- repo.is_valid_object(b"1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a", "blob")
- )
+ self.assertFalse(repo.is_valid_object(b"1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a", "blob"))
# Check for invalid objects of specific type
self.assertFalse(repo.is_valid_object(commit_sha, "blob"))
@@ -1200,6 +1164,4 @@ class TestRepo(TestBase):
fs.write("hello\n")
r.git.add(Git.polish_url(fp))
r.git.commit(message="init")
- self.assertEqual(
- r.git.show("HEAD:hello.txt", strip_newline_in_stdout=False), "hello\n"
- )
+ self.assertEqual(r.git.show("HEAD:hello.txt", strip_newline_in_stdout=False), "hello\n")
diff --git a/test/test_submodule.py b/test/test_submodule.py
index fc96391d..2930ce03 100644
--- a/test/test_submodule.py
+++ b/test/test_submodule.py
@@ -56,9 +56,7 @@ class TestSubmodule(TestBase):
assert len(Submodule.list_items(rwrepo, self.k_no_subm_tag)) == 0
assert sm.path == "git/ext/gitdb"
- assert (
- sm.path != sm.name
- ) # in our case, we have ids there, which don't equal the path
+ assert sm.path != sm.name # in our case, we have ids there, which don't equal the path
assert sm.url.endswith("github.com/gitpython-developers/gitdb.git")
assert sm.branch_path == "refs/heads/master" # the default ...
assert sm.branch_name == "master"
@@ -94,9 +92,7 @@ class TestSubmodule(TestBase):
else:
with sm.config_writer() as writer:
# for faster checkout, set the url to the local path
- new_smclone_path = Git.polish_url(
- osp.join(self.rorepo.working_tree_dir, sm.path)
- )
+ new_smclone_path = Git.polish_url(osp.join(self.rorepo.working_tree_dir, sm.path))
writer.set_value("url", new_smclone_path)
writer.release()
assert sm.config_reader().get_value("url") == new_smclone_path
@@ -129,9 +125,7 @@ class TestSubmodule(TestBase):
if rwrepo.bare:
self.assertRaises(InvalidGitRepositoryError, sm.module)
self.assertRaises(InvalidGitRepositoryError, sm.remove)
- self.assertRaises(
- InvalidGitRepositoryError, sm.add, rwrepo, "here", "there"
- )
+ self.assertRaises(InvalidGitRepositoryError, sm.add, rwrepo, "here", "there")
else:
# its not checked out in our case
self.assertRaises(InvalidGitRepositoryError, sm.module)
@@ -149,9 +143,7 @@ class TestSubmodule(TestBase):
assert sma.path == sm.path
# no url and no module at path fails
- self.assertRaises(
- ValueError, Submodule.add, rwrepo, "newsubm", "pathtorepo", url=None
- )
+ self.assertRaises(ValueError, Submodule.add, rwrepo, "newsubm", "pathtorepo", url=None)
# CONTINUE UPDATE
#################
@@ -209,9 +201,7 @@ class TestSubmodule(TestBase):
csm_repopath = csm.path
# adjust the path of the submodules module to point to the local destination
- new_csmclone_path = Git.polish_url(
- osp.join(self.rorepo.working_tree_dir, sm.path, csm.path)
- )
+ new_csmclone_path = Git.polish_url(osp.join(self.rorepo.working_tree_dir, sm.path, csm.path))
with csm.config_writer() as writer:
writer.set_value("url", new_csmclone_path)
assert csm.url == new_csmclone_path
@@ -250,9 +240,7 @@ class TestSubmodule(TestBase):
assert repo.head.commit != repo.head.ref.tracking_branch().commit
# END for each repo to check
- self.assertRaises(
- RepositoryDirtyError, sm.update, recursive=True, to_latest_revision=True
- )
+ self.assertRaises(RepositoryDirtyError, sm.update, recursive=True, to_latest_revision=True)
sm.update(recursive=True, to_latest_revision=True, force=True)
for repo in smods:
assert repo.head.commit == repo.head.ref.tracking_branch().commit
@@ -285,9 +273,7 @@ class TestSubmodule(TestBase):
csm.set_parent_commit(csm.repo.head.commit)
with csm.config_writer() as cw:
cw.set_value("url", self._small_repo_url())
- csm.repo.index.commit(
- "adjusted URL to point to local source, instead of the internet"
- )
+ csm.repo.index.commit("adjusted URL to point to local source, instead of the internet")
# We have modified the configuration, hence the index is dirty, and the
# deletion will fail
@@ -369,23 +355,15 @@ class TestSubmodule(TestBase):
assert nsm.module_exists()
assert nsm.exists()
# its not checked out
- assert not osp.isfile(
- join_path_native(
- nsm.module().working_tree_dir, Submodule.k_modules_file
- )
- )
+ assert not osp.isfile(join_path_native(nsm.module().working_tree_dir, Submodule.k_modules_file))
assert len(rwrepo.submodules) == 1
# add another submodule, but into the root, not as submodule
- osm = Submodule.add(
- rwrepo, osmid, csm_repopath, new_csmclone_path, Submodule.k_head_default
- )
+ osm = Submodule.add(rwrepo, osmid, csm_repopath, new_csmclone_path, Submodule.k_head_default)
assert osm != nsm
assert osm.module_exists()
assert osm.exists()
- assert osp.isfile(
- join_path_native(osm.module().working_tree_dir, "setup.py")
- )
+ assert osp.isfile(join_path_native(osm.module().working_tree_dir, "setup.py"))
assert len(rwrepo.submodules) == 2
@@ -401,9 +379,7 @@ class TestSubmodule(TestBase):
# MOVE MODULE
#############
# invalid input
- self.assertRaises(
- ValueError, nsm.move, "doesntmatter", module=False, configuration=False
- )
+ self.assertRaises(ValueError, nsm.move, "doesntmatter", module=False, configuration=False)
# renaming to the same path does nothing
assert nsm.move(sm_path) is nsm
@@ -437,9 +413,7 @@ class TestSubmodule(TestBase):
for remote in osmod.remotes:
remote.remove(osmod, remote.name)
assert not osm.exists()
- self.assertRaises(
- ValueError, Submodule.add, rwrepo, osmid, csm_repopath, url=None
- )
+ self.assertRaises(ValueError, Submodule.add, rwrepo, osmid, csm_repopath, url=None)
# END handle bare mode
# Error if there is no submodule file here
@@ -493,9 +467,7 @@ class TestSubmodule(TestBase):
# deep traversal gitdb / async
rsmsp = [sm.path for sm in rm.traverse()]
- assert (
- len(rsmsp) >= 2
- ) # gitdb and async [and smmap], async being a child of gitdb
+ assert len(rsmsp) >= 2 # gitdb and async [and smmap], async being a child of gitdb
# cannot set the parent commit as root module's path didn't exist
self.assertRaises(ValueError, rm.set_parent_commit, "HEAD")
@@ -517,9 +489,7 @@ class TestSubmodule(TestBase):
# assure we clone from a local source
with sm.config_writer() as writer:
- writer.set_value(
- "url", Git.polish_url(osp.join(self.rorepo.working_tree_dir, sm.path))
- )
+ writer.set_value("url", Git.polish_url(osp.join(self.rorepo.working_tree_dir, sm.path)))
# dry-run does nothing
sm.update(recursive=False, dry_run=True, progress=prog)
@@ -528,9 +498,7 @@ class TestSubmodule(TestBase):
sm.update(recursive=False)
assert sm.module_exists()
with sm.config_writer() as writer:
- writer.set_value(
- "path", fp
- ) # change path to something with prefix AFTER url change
+ writer.set_value("path", fp) # change path to something with prefix AFTER url change
# update doesn't fail, because list_items ignores the wrong path in such situations.
rm.update(recursive=False)
@@ -554,13 +522,9 @@ class TestSubmodule(TestBase):
# ================
nsmn = "newsubmodule"
nsmp = "submrepo"
- subrepo_url = Git.polish_url(
- osp.join(self.rorepo.working_tree_dir, rsmsp[0], rsmsp[1])
- )
+ subrepo_url = Git.polish_url(osp.join(self.rorepo.working_tree_dir, rsmsp[0], rsmsp[1]))
nsm = Submodule.add(rwrepo, nsmn, nsmp, url=subrepo_url)
- csmadded = rwrepo.index.commit(
- "Added submodule"
- ).hexsha # make sure we don't keep the repo reference
+ csmadded = rwrepo.index.commit("Added submodule").hexsha # make sure we don't keep the repo reference
nsm.set_parent_commit(csmadded)
assert nsm.module_exists()
# in our case, the module should not exist, which happens if we update a parent
@@ -591,9 +555,7 @@ class TestSubmodule(TestBase):
# when removing submodules, we may get new commits as nested submodules are auto-committing changes
# to allow deletions without force, as the index would be dirty otherwise.
# QUESTION: Why does this seem to work in test_git_submodule_compatibility() ?
- self.assertRaises(
- InvalidGitRepositoryError, rm.update, recursive=False, force_remove=False
- )
+ self.assertRaises(InvalidGitRepositoryError, rm.update, recursive=False, force_remove=False)
rm.update(recursive=False, force_remove=True)
assert not osp.isdir(smp)
@@ -604,23 +566,17 @@ class TestSubmodule(TestBase):
assert nsm.module().head.commit.hexsha == nsm.hexsha
nsm.module().index.add([nsm])
nsm.module().index.commit("added new file")
- rm.update(
- recursive=False, dry_run=True, progress=prog
- ) # would not change head, and thus doesn't fail
+ rm.update(recursive=False, dry_run=True, progress=prog) # would not change head, and thus doesn't fail
# Everything we can do from now on will trigger the 'future' check, so no is_dirty() check will even run
# This would only run if our local branch is in the past and we have uncommitted changes
prev_commit = nsm.module().head.commit
rm.update(recursive=False, dry_run=False, progress=prog)
- assert (
- prev_commit == nsm.module().head.commit
- ), "head shouldn't change, as it is in future of remote branch"
+ assert prev_commit == nsm.module().head.commit, "head shouldn't change, as it is in future of remote branch"
# this kills the new file
rm.update(recursive=True, progress=prog, force_reset=True)
- assert (
- prev_commit != nsm.module().head.commit
- ), "head changed, as the remote url and its commit changed"
+ assert prev_commit != nsm.module().head.commit, "head changed, as the remote url and its commit changed"
# change url ...
# ===============
@@ -643,9 +599,7 @@ class TestSubmodule(TestBase):
assert nsm.module().remotes.origin.url == nsmurl
assert prev_commit != nsm.module().head.commit, "Should now point to gitdb"
assert len(rwrepo.submodules) == 1
- assert (
- not rwrepo.submodules[0].children()[0].module_exists()
- ), "nested submodule should not be checked out"
+ assert not rwrepo.submodules[0].children()[0].module_exists(), "nested submodule should not be checked out"
# add the submodule's changed commit to the index, which is what the
# user would do
@@ -706,16 +660,12 @@ class TestSubmodule(TestBase):
("first", "submodules/first"),
("second", osp.join(rwrepo.working_tree_dir, "submodules/second")),
):
- sm = rwrepo.create_submodule(
- sm_name, sm_path, rwrepo.git_dir, no_checkout=True
- )
+ sm = rwrepo.create_submodule(sm_name, sm_path, rwrepo.git_dir, no_checkout=True)
assert sm.exists() and sm.module_exists()
rwrepo.index.commit("Added submodule " + sm_name)
# end for each submodule path to add
- self.assertRaises(
- ValueError, rwrepo.create_submodule, "fail", osp.expanduser("~")
- )
+ self.assertRaises(ValueError, rwrepo.create_submodule, "fail", osp.expanduser("~"))
self.assertRaises(
ValueError,
rwrepo.create_submodule,
@@ -814,9 +764,7 @@ class TestSubmodule(TestBase):
# object pointing to the new submodule commit
sm_too = parent.submodules["module_moved"]
assert parent.head.commit.tree[sm.path].binsha == sm.binsha
- assert (
- sm_too.binsha == sm.binsha
- ), "cached submodule should point to the same commit as updated one"
+ assert sm_too.binsha == sm.binsha, "cached submodule should point to the same commit as updated one"
added_bies = parent.index.add([sm]) # added base-index-entries
assert len(added_bies) == 1
@@ -841,9 +789,7 @@ class TestSubmodule(TestBase):
def test_git_submodule_compatibility(self, rwdir):
parent = git.Repo.init(osp.join(rwdir, "parent"))
sm_path = join_path_native("submodules", "intermediate", "one")
- sm = parent.create_submodule(
- "mymodules/myname", sm_path, url=self._small_repo_url()
- )
+ sm = parent.create_submodule("mymodules/myname", sm_path, url=self._small_repo_url())
parent.index.commit("added submodule")
def assert_exists(sm, value=True):
@@ -864,9 +810,7 @@ class TestSubmodule(TestBase):
else:
assert osp.isfile(module_repo_path)
assert sm.module().has_separate_working_tree()
- assert (
- find_submodule_git_dir(module_repo_path) is not None
- ), "module pointed to by .git file must be valid"
+ assert find_submodule_git_dir(module_repo_path) is not None, "module pointed to by .git file must be valid"
# end verify submodule 'style'
# test move
@@ -895,9 +839,7 @@ class TestSubmodule(TestBase):
new_name = csm.name + "/mine"
assert csm.rename(new_name).name == new_name
assert_exists(csm)
- assert csm.repo.is_dirty(
- index=True, working_tree=False
- ), "index must contain changed .gitmodules file"
+ assert csm.repo.is_dirty(index=True, working_tree=False), "index must contain changed .gitmodules file"
csm.repo.index.commit("renamed module")
# keep_going evaluation
@@ -906,9 +848,7 @@ class TestSubmodule(TestBase):
assert_exists(csm)
with csm.config_writer().set_value("url", "bar"):
pass
- csm.repo.index.commit(
- "Have to commit submodule change for algorithm to pick it up"
- )
+ csm.repo.index.commit("Have to commit submodule change for algorithm to pick it up")
assert csm.url == "bar"
self.assertRaises(
@@ -919,9 +859,7 @@ class TestSubmodule(TestBase):
progress=prog,
)
assert_exists(csm)
- rsm.update(
- recursive=True, to_latest_revision=True, progress=prog, keep_going=True
- )
+ rsm.update(recursive=True, to_latest_revision=True, progress=prog, keep_going=True)
# remove
sm_module_path = sm.module().git_dir
@@ -958,9 +896,7 @@ class TestSubmodule(TestBase):
parent.index.commit("Added submodule")
assert sm.rename(sm_name) is sm and sm.name == sm_name
- assert not sm.repo.is_dirty(
- index=True, working_tree=False, untracked_files=False
- )
+ assert not sm.repo.is_dirty(index=True, working_tree=False, untracked_files=False)
new_path = "renamed/myname"
assert sm.move(new_path).name == new_path
@@ -971,12 +907,8 @@ class TestSubmodule(TestBase):
assert sm.exists()
sm_mod = sm.module()
- if osp.isfile(
- osp.join(sm_mod.working_tree_dir, ".git")
- ) == sm._need_gitfile_submodules(parent.git):
- assert sm_mod.git_dir.endswith(
- join_path_native(".git", "modules", new_sm_name)
- )
+ if osp.isfile(osp.join(sm_mod.working_tree_dir, ".git")) == sm._need_gitfile_submodules(parent.git):
+ assert sm_mod.git_dir.endswith(join_path_native(".git", "modules", new_sm_name))
# end
@with_rw_directory
@@ -984,9 +916,7 @@ class TestSubmodule(TestBase):
# Setup initial sandbox:
# parent repo has one submodule, which has all the latest changes
source_url = self._small_repo_url()
- sm_source_repo = git.Repo.clone_from(
- source_url, osp.join(rw_dir, "sm-source"), b="master"
- )
+ sm_source_repo = git.Repo.clone_from(source_url, osp.join(rw_dir, "sm-source"), b="master")
parent_repo = git.Repo.init(osp.join(rw_dir, "parent"))
sm = parent_repo.create_submodule(
"mysubmodule",
@@ -1016,9 +946,7 @@ class TestSubmodule(TestBase):
assert sm_mod.head.ref.name == "master"
assert parent_repo.submodule_update()
assert sm_mod.head.ref.name == sm_fb.name
- assert (
- sm_mod.commit() == prev_commit
- ), "Without to_latest_revision, we don't change the commit"
+ assert sm_mod.commit() == prev_commit, "Without to_latest_revision, we don't change the commit"
assert parent_repo.submodule_update(to_latest_revision=True)
assert sm_mod.head.ref.name == sm_fb.name
@@ -1028,9 +956,7 @@ class TestSubmodule(TestBase):
# To make it even 'harder', we shall fork and create a new commit
sm_pfb = sm_source_repo.create_head("past-feature", commit="HEAD~20")
sm_pfb.checkout()
- sm_source_repo.index.add(
- [touch(osp.join(sm_source_repo.working_tree_dir, "new-file"))]
- )
+ sm_source_repo.index.add([touch(osp.join(sm_source_repo.working_tree_dir, "new-file"))])
sm_source_repo.index.commit("new file added, to past of '%r'" % sm_fb)
# Change designated submodule checkout branch to a new commit in its own past
@@ -1046,9 +972,7 @@ class TestSubmodule(TestBase):
sm_mod.head.ref.name == sm_pfb.name, "should have been switched to past head"
sm_mod.commit() == sm_fb.commit, "Head wasn't reset"
- self.assertRaises(
- RepositoryDirtyError, parent_repo.submodule_update, to_latest_revision=True
- )
+ self.assertRaises(RepositoryDirtyError, parent_repo.submodule_update, to_latest_revision=True)
parent_repo.submodule_update(to_latest_revision=True, force_reset=True)
assert sm_mod.commit() == sm_pfb.commit, "Now head should have been reset"
assert sm_mod.head.ref.name == sm_pfb.name
@@ -1061,9 +985,7 @@ class TestSubmodule(TestBase):
super_repo = Repo()
submodule_path = "D:\\submodule_path"
relative_path = Submodule._to_relative_path(super_repo, submodule_path)
- msg = (
- '_to_relative_path should be "submodule_path" but was "%s"' % relative_path
- )
+ msg = '_to_relative_path should be "submodule_path" but was "%s"' % relative_path
assert relative_path == "submodule_path", msg
@skipIf(
@@ -1075,9 +997,7 @@ class TestSubmodule(TestBase):
parent = git.Repo.init(osp.join(rwdir, "test_depth"))
sm_name = "mymodules/myname"
sm_depth = 1
- sm = parent.create_submodule(
- sm_name, sm_name, url=self._small_repo_url(), depth=sm_depth
- )
+ sm = parent.create_submodule(sm_name, sm_name, url=self._small_repo_url(), depth=sm_depth)
self.assertEqual(len(list(sm.module().iter_commits())), sm_depth)
@with_rw_directory
@@ -1101,9 +1021,7 @@ class TestSubmodule(TestBase):
sm.update(init=True, clone_multi_options=["--config core.eol=true"])
# Assert
- sm_config = GitConfigParser(
- file_or_files=osp.join(parent.git_dir, "modules", sm_name, "config")
- )
+ sm_config = GitConfigParser(file_or_files=osp.join(parent.git_dir, "modules", sm_name, "config"))
self.assertTrue(sm_config.get_value("core", "eol"))
@with_rw_directory
@@ -1127,9 +1045,7 @@ class TestSubmodule(TestBase):
sm.update(init=True)
# Assert
- sm_config = GitConfigParser(
- file_or_files=osp.join(parent.git_dir, "modules", sm_name, "config")
- )
+ sm_config = GitConfigParser(file_or_files=osp.join(parent.git_dir, "modules", sm_name, "config"))
with self.assertRaises(cp.NoOptionError):
sm_config.get_value("core", "eol")
@@ -1149,9 +1065,7 @@ class TestSubmodule(TestBase):
)
# Assert
- sm_config = GitConfigParser(
- file_or_files=osp.join(parent.git_dir, "modules", sm_name, "config")
- )
+ sm_config = GitConfigParser(file_or_files=osp.join(parent.git_dir, "modules", sm_name, "config"))
self.assertTrue(sm_config.get_value("core", "eol"))
@with_rw_directory
@@ -1164,8 +1078,6 @@ class TestSubmodule(TestBase):
Submodule.add(parent, sm_name, sm_name, url=self._small_repo_url())
# Assert
- sm_config = GitConfigParser(
- file_or_files=osp.join(parent.git_dir, "modules", sm_name, "config")
- )
+ sm_config = GitConfigParser(file_or_files=osp.join(parent.git_dir, "modules", sm_name, "config"))
with self.assertRaises(cp.NoOptionError):
sm_config.get_value("core", "eol")
diff --git a/test/test_tree.py b/test/test_tree.py
index 97067fb2..22c9c7d7 100644
--- a/test/test_tree.py
+++ b/test/test_tree.py
@@ -89,9 +89,7 @@ class TestTree(TestBase):
# trees and blobs
assert len(set(trees) | set(root.trees)) == len(trees)
- assert len({b for b in root if isinstance(b, Blob)} | set(root.blobs)) == len(
- root.blobs
- )
+ assert len({b for b in root if isinstance(b, Blob)} | set(root.blobs)) == len(root.blobs)
subitem = trees[0][0]
assert "/" in subitem.path
assert subitem.name == osp.basename(subitem.path)
diff --git a/test/test_util.py b/test/test_util.py
index b2903620..eb016189 100644
--- a/test/test_util.py
+++ b/test/test_util.py
@@ -181,9 +181,7 @@ class TestUtils(TestBase):
(1522827734, 0),
(1522827734, +3600),
):
- self.assertEqual(
- parse_date(from_timestamp(timestamp, offset)), (timestamp, offset)
- )
+ self.assertEqual(parse_date(from_timestamp(timestamp, offset)), (timestamp, offset))
# test all supported formats
def assert_rval(rval, veri_time, offset=0):
@@ -359,9 +357,7 @@ class TestUtils(TestBase):
def test_remove_password_from_command_line(self):
username = "fakeuser"
password = "fakepassword1234"
- url_with_user_and_pass = "https://{}:{}@fakerepo.example.com/testrepo".format(
- username, password
- )
+ url_with_user_and_pass = "https://{}:{}@fakerepo.example.com/testrepo".format(username, password)
url_with_user = "https://{}@fakerepo.example.com/testrepo".format(username)
url_with_pass = "https://:{}@fakerepo.example.com/testrepo".format(password)
url_without_user_or_pass = "https://fakerepo.example.com/testrepo"