summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git/cmd.py7
-rw-r--r--git/test/test_base.py25
-rw-r--r--git/test/test_remote.py85
-rw-r--r--git/util.py1
4 files changed, 64 insertions, 54 deletions
diff --git a/git/cmd.py b/git/cmd.py
index 59f17448..aa711168 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -539,6 +539,9 @@ class Git(LazyMixin):
cmd_not_found_exception = OSError
# end handle
+ stdout_sink = (PIPE
+ if with_stdout
+ else getattr(subprocess, 'DEVNULL', open(os.devnull, 'wb')))
log.debug("Popen(%s, cwd=%s, universal_newlines=%s, shell=%s)",
command, cwd, universal_newlines, shell)
try:
@@ -548,9 +551,9 @@ class Git(LazyMixin):
bufsize=-1,
stdin=istream,
stderr=PIPE,
- stdout=PIPE if with_stdout else open(os.devnull, 'wb'),
+ stdout=stdout_sink,
shell=shell is not None and shell or self.USE_SHELL,
- close_fds=(is_posix), # unsupported on windows
+ close_fds=is_posix, # unsupported on windows
universal_newlines=universal_newlines,
creationflags=PROC_CREATIONFLAGS,
**subprocess_kwargs
diff --git a/git/test/test_base.py b/git/test/test_base.py
index a4382d3e..7fc3096f 100644
--- a/git/test/test_base.py
+++ b/git/test/test_base.py
@@ -41,7 +41,7 @@ class TestBase(TestBase):
def test_base_object(self):
# test interface of base object classes
types = (Blob, Tree, Commit, TagObject)
- assert len(types) == len(self.type_tuples)
+ self.assertEqual(len(types), len(self.type_tuples))
s = set()
num_objs = 0
@@ -55,12 +55,12 @@ class TestBase(TestBase):
item = obj_type(self.rorepo, binsha, 0, path)
# END handle index objects
num_objs += 1
- assert item.hexsha == hexsha
- assert item.type == typename
+ self.assertEqual(item.hexsha, hexsha)
+ self.assertEqual(item.type, typename)
assert item.size
- assert item == item
- assert not item != item
- assert str(item) == item.hexsha
+ self.assertEqual(item, item)
+ self.assertNotEqual(not item, item)
+ self.assertEqual(str(item), item.hexsha)
assert repr(item)
s.add(item)
@@ -78,16 +78,16 @@ class TestBase(TestBase):
tmpfilename = tempfile.mktemp(suffix='test-stream')
with open(tmpfilename, 'wb+') as tmpfile:
- assert item == item.stream_data(tmpfile)
+ self.assertEqual(item, item.stream_data(tmpfile))
tmpfile.seek(0)
- assert tmpfile.read() == data
+ self.assertEqual(tmpfile.read(), data)
os.remove(tmpfilename)
# END for each object type to create
# each has a unique sha
- assert len(s) == num_objs
- assert len(s | s) == num_objs
- assert num_index_objs == 2
+ self.assertEqual(len(s), num_objs)
+ self.assertEqual(len(s | s), num_objs)
+ self.assertEqual(num_index_objs, 2)
def test_get_object_type_by_name(self):
for tname in base.Object.TYPES:
@@ -98,7 +98,7 @@ class TestBase(TestBase):
def test_object_resolution(self):
# objects must be resolved to shas so they compare equal
- assert 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):
@@ -110,6 +110,7 @@ class TestBase(TestBase):
assert not rw_repo.config_reader("repository").getboolean("core", "bare")
assert os.path.isdir(os.path.join(rw_repo.working_tree_dir, 'lib'))
+ #@skipIf(HIDE_WINDOWS_FREEZE_ERRORS, "FIXME: Freezes! sometimes...")
@with_rw_and_rw_remote_repo('0.1.6')
def test_with_rw_remote_and_rw_repo(self, rw_repo, rw_remote_repo):
assert not rw_repo.config_reader("repository").getboolean("core", "bare")
diff --git a/git/test/test_remote.py b/git/test/test_remote.py
index 8382d7fa..7203bee4 100644
--- a/git/test/test_remote.py
+++ b/git/test/test_remote.py
@@ -4,14 +4,10 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-from git.test.lib import (
- TestBase,
- with_rw_repo,
- with_rw_and_rw_remote_repo,
- fixture,
- GIT_DAEMON_PORT,
- assert_raises
-)
+import random
+import tempfile
+from unittest.case import skipIf
+
from git import (
RemoteProgress,
FetchInfo,
@@ -25,14 +21,19 @@ from git import (
Remote,
GitCommandError
)
-from git.util import IterableList, rmtree
+from git.cmd import Git
from git.compat import string_types
-import tempfile
+from git.test.lib import (
+ TestBase,
+ with_rw_repo,
+ with_rw_and_rw_remote_repo,
+ fixture,
+ GIT_DAEMON_PORT,
+ assert_raises
+)
+from git.util import IterableList, rmtree, HIDE_WINDOWS_FREEZE_ERRORS, HIDE_WINDOWS_KNOWN_ERRORS
import os.path as osp
-import random
-from unittest.case import skipIf
-from git.util import HIDE_WINDOWS_KNOWN_ERRORS
-from git.cmd import Git
+
# assure we have repeatable results
random.seed(0)
@@ -213,7 +214,7 @@ class TestRemote(TestBase):
new_remote_branch.rename("other_branch_name")
res = fetch_and_test(remote)
other_branch_info = get_info(res, remote, new_remote_branch)
- assert other_branch_info.ref.commit == new_branch_info.ref.commit
+ self.assertEqual(other_branch_info.ref.commit, new_branch_info.ref.commit)
# remove new branch
Head.delete(new_remote_branch.repo, new_remote_branch)
@@ -223,34 +224,37 @@ class TestRemote(TestBase):
# prune stale tracking branches
stale_refs = remote.stale_refs
- assert len(stale_refs) == 2 and isinstance(stale_refs[0], RemoteReference)
+ self.assertEqual(len(stale_refs), 2)
+ self.assertIsInstance(stale_refs[0], RemoteReference)
RemoteReference.delete(rw_repo, *stale_refs)
# test single branch fetch with refspec including target remote
res = fetch_and_test(remote, refspec="master:refs/remotes/%s/master" % remote)
- assert len(res) == 1 and get_info(res, remote, 'master')
+ self.assertEqual(len(res), 1)
+ self.assertTrue(get_info(res, remote, 'master'))
# ... with respec and no target
res = fetch_and_test(remote, refspec='master')
- assert len(res) == 1
+ self.assertEqual(len(res), 1)
# ... multiple refspecs ... works, but git command returns with error if one ref is wrong without
# doing anything. This is new in later binaries
# res = fetch_and_test(remote, refspec=['master', 'fred'])
- # assert len(res) == 1
+ # self.assertEqual(len(res), 1)
# add new tag reference
rtag = TagReference.create(remote_repo, "1.0-RV_hello.there")
res = fetch_and_test(remote, tags=True)
tinfo = res[str(rtag)]
- assert isinstance(tinfo.ref, TagReference) and tinfo.ref.commit == rtag.commit
+ self.assertIsInstance(tinfo.ref, TagReference)
+ self.assertEqual(tinfo.ref.commit, rtag.commit)
assert tinfo.flags & tinfo.NEW_TAG
# adjust tag commit
Reference.set_object(rtag, rhead.commit.parents[0].parents[0])
res = fetch_and_test(remote, tags=True)
tinfo = res[str(rtag)]
- assert tinfo.commit == rtag.commit
+ self.assertEqual(tinfo.commit, rtag.commit)
assert tinfo.flags & tinfo.TAG_UPDATE
# delete remote tag - local one will stay
@@ -326,7 +330,7 @@ class TestRemote(TestBase):
# force rejected pull
res = remote.push('+%s' % lhead.reference)
- assert res[0].flags & PushInfo.ERROR == 0
+ self.assertEqual(res[0].flags & PushInfo.ERROR, 0)
assert res[0].flags & PushInfo.FORCED_UPDATE
self._do_test_push_result(res, remote)
@@ -352,7 +356,8 @@ class TestRemote(TestBase):
# push force this tag
res = remote.push("+%s" % new_tag.path)
- assert res[-1].flags & PushInfo.ERROR == 0 and res[-1].flags & PushInfo.FORCED_UPDATE
+ self.assertEqual(res[-1].flags & PushInfo.ERROR, 0)
+ self.assertTrue(res[-1].flags & PushInfo.FORCED_UPDATE)
# delete tag - have to do it using refspec
res = remote.push(":%s" % new_tag.path)
@@ -485,7 +490,7 @@ class TestRemote(TestBase):
new_name = "test_new_one"
arg_list = (new_name, "git@server:hello.git")
remote = Remote.create(bare_rw_repo, *arg_list)
- assert remote.name == "test_new_one"
+ self.assertEqual(remote.name, "test_new_one")
assert remote in bare_rw_repo.remotes
assert remote.exists()
@@ -520,7 +525,7 @@ class TestRemote(TestBase):
remote_info_line_fmt % "local/master",
fetch_info_line_fmt % 'remote-tracking branch')
assert not fi.ref.is_valid()
- assert fi.ref.name == "local/master"
+ self.assertEqual(fi.ref.name, "local/master")
# handles non-default refspecs: One can specify a different path in refs/remotes
# or a special path just in refs/something for instance
@@ -547,7 +552,7 @@ class TestRemote(TestBase):
fetch_info_line_fmt % 'tag')
assert isinstance(fi.ref, TagReference)
- assert fi.ref.path == tag_path
+ self.assertEqual(fi.ref.path, tag_path)
# branches default to refs/remotes
fi = FetchInfo._from_line(self.rorepo,
@@ -555,7 +560,7 @@ class TestRemote(TestBase):
fetch_info_line_fmt % 'branch')
assert isinstance(fi.ref, RemoteReference)
- assert fi.ref.remote_name == 'remotename'
+ self.assertEqual(fi.ref.remote_name, 'remotename')
# but you can force it anywhere, in which case we only have a references
fi = FetchInfo._from_line(self.rorepo,
@@ -563,7 +568,7 @@ class TestRemote(TestBase):
fetch_info_line_fmt % 'branch')
assert type(fi.ref) is Reference
- assert fi.ref.path == "refs/something/branch"
+ self.assertEqual(fi.ref.path, "refs/something/branch")
def test_uncommon_branch_names(self):
stderr_lines = fixture('uncommon_branch_prefix_stderr').decode('ascii').splitlines()
@@ -574,8 +579,8 @@ class TestRemote(TestBase):
res = [FetchInfo._from_line('ShouldntMatterRepo', stderr, fetch_line)
for stderr, fetch_line in zip(stderr_lines, fetch_lines)]
assert len(res)
- assert res[0].remote_ref_path == 'refs/pull/1/head'
- assert res[0].ref.path == 'refs/heads/pull/1/head'
+ self.assertEqual(res[0].remote_ref_path, 'refs/pull/1/head')
+ self.assertEqual(res[0].ref.path, 'refs/heads/pull/1/head')
assert isinstance(res[0].ref, Head)
@with_rw_repo('HEAD', bare=False)
@@ -588,22 +593,22 @@ class TestRemote(TestBase):
remote = rw_repo.remotes[0]
# Testing setting a single URL
remote.set_url(test1)
- assert list(remote.urls) == [test1]
+ self.assertEqual(list(remote.urls), [test1])
# Testing replacing that single URL
remote.set_url(test1)
- assert list(remote.urls) == [test1]
+ self.assertEqual(list(remote.urls), [test1])
# Testing adding new URLs
remote.set_url(test2, add=True)
- assert list(remote.urls) == [test1, test2]
+ self.assertEqual(list(remote.urls), [test1, test2])
remote.set_url(test3, add=True)
- assert list(remote.urls) == [test1, test2, test3]
+ self.assertEqual(list(remote.urls), [test1, test2, test3])
# Testing removing an URL
remote.set_url(test2, delete=True)
- assert list(remote.urls) == [test1, test3]
+ self.assertEqual(list(remote.urls), [test1, test3])
# Testing changing an URL
remote.set_url(test3, test2)
- assert list(remote.urls) == [test1, test2]
+ self.assertEqual(list(remote.urls), [test1, test2])
# will raise: fatal: --add --delete doesn't make sense
assert_raises(GitCommandError, remote.set_url, test2, add=True, delete=True)
@@ -611,13 +616,13 @@ class TestRemote(TestBase):
# Testing on another remote, with the add/delete URL
remote = rw_repo.create_remote('another', url=test1)
remote.add_url(test2)
- assert list(remote.urls) == [test1, test2]
+ self.assertEqual(list(remote.urls), [test1, test2])
remote.add_url(test3)
- assert list(remote.urls) == [test1, test2, test3]
+ self.assertEqual(list(remote.urls), [test1, test2, test3])
# Testing removing all the URLs
remote.delete_url(test2)
- assert list(remote.urls) == [test1, test3]
+ self.assertEqual(list(remote.urls), [test1, test3])
remote.delete_url(test1)
- assert list(remote.urls) == [test3]
+ self.assertEqual(list(remote.urls), [test3])
# will raise fatal: Will not delete all non-push URLs
assert_raises(GitCommandError, remote.delete_url, test3)
diff --git a/git/util.py b/git/util.py
index 57e056c3..568d9328 100644
--- a/git/util.py
+++ b/git/util.py
@@ -51,6 +51,7 @@ __all__ = ("stream_copy", "join_path", "to_native_path_windows", "to_native_path
#: so the errors marked with this var are considered "acknowledged" ones, awaiting remedy,
#: till then, we wish to hide them.
HIDE_WINDOWS_KNOWN_ERRORS = is_win and os.environ.get('HIDE_WINDOWS_KNOWN_ERRORS', True)
+HIDE_WINDOWS_FREEZE_ERRORS = is_win and os.environ.get('HIDE_WINDOWS_FREEZE_ERRORS', HIDE_WINDOWS_KNOWN_ERRORS)
#{ Utility Methods