dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00178
[PATCH 04/10] Use run_git_or_fail in compat tests wherever possible.
From: Dave Borowitz <dborowitz@xxxxxxxxxx>
This reduces code and has the added side effect of suppressing lots of
unnecessary git output.
Change-Id: I8a6d53b6c2875f1cd704aa5511eb8839cdb40513
---
dulwich/tests/compat/server_utils.py | 12 +++++-------
dulwich/tests/compat/test_client.py | 10 +++++-----
dulwich/tests/compat/test_pack.py | 7 ++-----
dulwich/tests/compat/test_repository.py | 7 ++-----
dulwich/tests/compat/utils.py | 3 +--
5 files changed, 15 insertions(+), 24 deletions(-)
diff --git a/dulwich/tests/compat/server_utils.py b/dulwich/tests/compat/server_utils.py
index 37000c4..2230d2c 100644
--- a/dulwich/tests/compat/server_utils.py
+++ b/dulwich/tests/compat/server_utils.py
@@ -32,7 +32,7 @@ from dulwich.tests.utils import (
)
from utils import (
import_repo,
- run_git,
+ run_git_or_fail,
)
@@ -61,9 +61,8 @@ class ServerTests(object):
all_branches = ['master', 'branch']
branch_args = ['%s:%s' % (b, b) for b in all_branches]
url = '%s://localhost:%s/' % (self.protocol, port)
- returncode, _ = run_git(['push', url] + branch_args,
- cwd=self._new_repo.path)
- self.assertEqual(0, returncode)
+ run_git_or_fail(['push', url] + branch_args,
+ cwd=self._new_repo.path)
self.assertReposEqual(self._old_repo, self._new_repo)
def test_fetch_from_dulwich(self):
@@ -73,11 +72,10 @@ class ServerTests(object):
all_branches = ['master', 'branch']
branch_args = ['%s:%s' % (b, b) for b in all_branches]
url = '%s://localhost:%s/' % (self.protocol, port)
- returncode, _ = run_git(['fetch', url] + branch_args,
- cwd=self._old_repo.path)
+ run_git_or_fail(['fetch', url] + branch_args,
+ cwd=self._old_repo.path)
# flush the pack cache so any new packs are picked up
self._old_repo.object_store._pack_cache = None
- self.assertEqual(0, returncode)
self.assertReposEqual(self._old_repo, self._new_repo)
diff --git a/dulwich/tests/compat/test_client.py b/dulwich/tests/compat/test_client.py
index 578ee61..4cf0037 100644
--- a/dulwich/tests/compat/test_client.py
+++ b/dulwich/tests/compat/test_client.py
@@ -40,7 +40,7 @@ from utils import (
CompatTestCase,
check_for_daemon,
import_repo_to_dir,
- run_git,
+ run_git_or_fail,
)
class DulwichClientTestBase(object):
@@ -50,7 +50,7 @@ class DulwichClientTestBase(object):
self.gitroot = os.path.dirname(import_repo_to_dir('server_new.export'))
dest = os.path.join(self.gitroot, 'dest')
file.ensure_dir_exists(dest)
- run_git(['init', '--quiet', '--bare'], cwd=dest)
+ run_git_or_fail(['init', '--quiet', '--bare'], cwd=dest)
def tearDown(self):
shutil.rmtree(self.gitroot)
@@ -99,8 +99,8 @@ class DulwichClientTestBase(object):
def disable_ff_and_make_dummy_commit(self):
# disable non-fast-forward pushes to the server
dest = repo.Repo(os.path.join(self.gitroot, 'dest'))
- run_git(['config', 'receive.denyNonFastForwards', 'true'],
- cwd=dest.path)
+ run_git_or_fail(['config', 'receive.denyNonFastForwards', 'true'],
+ cwd=dest.path)
b = objects.Blob.from_string('hi')
dest.object_store.add_object(b)
t = index.commit_tree(dest.object_store, [('hi', b.id, 0100644)])
@@ -176,7 +176,7 @@ class DulwichTCPClientTest(CompatTestCase, DulwichClientTestBase):
fd, self.pidfile = tempfile.mkstemp(prefix='dulwich-test-git-client',
suffix=".pid")
os.fdopen(fd).close()
- run_git(
+ run_git_or_fail(
['daemon', '--verbose', '--export-all',
'--pid-file=%s' % self.pidfile, '--base-path=%s' % self.gitroot,
'--detach', '--reuseaddr', '--enable=receive-pack',
diff --git a/dulwich/tests/compat/test_pack.py b/dulwich/tests/compat/test_pack.py
index ba6e2b5..8b65a32 100644
--- a/dulwich/tests/compat/test_pack.py
+++ b/dulwich/tests/compat/test_pack.py
@@ -34,7 +34,7 @@ from dulwich.tests.test_pack import (
)
from utils import (
require_git_version,
- run_git,
+ run_git_or_fail,
)
@@ -56,10 +56,7 @@ class TestPack(PackTests):
pack_path = os.path.join(self._tempdir, "Elch")
write_pack(pack_path, [(x, "") for x in origpack.iterobjects()],
len(origpack))
-
- returncode, output = run_git(['verify-pack', '-v', pack_path],
- capture_stdout=True)
- self.assertEquals(0, returncode)
+ output = run_git_or_fail(['verify-pack', '-v', pack_path])
pack_shas = set()
for line in output.splitlines():
diff --git a/dulwich/tests/compat/test_repository.py b/dulwich/tests/compat/test_repository.py
index 91d0c76..6a3e906 100644
--- a/dulwich/tests/compat/test_repository.py
+++ b/dulwich/tests/compat/test_repository.py
@@ -35,7 +35,7 @@ from dulwich.tests.utils import (
)
from utils import (
- run_git,
+ run_git_or_fail,
import_repo,
CompatTestCase,
)
@@ -53,10 +53,7 @@ class ObjectStoreTestCase(CompatTestCase):
tear_down_repo(self._repo)
def _run_git(self, args):
- returncode, output = run_git(args, capture_stdout=True,
- cwd=self._repo.path)
- self.assertEqual(0, returncode)
- return output
+ return run_git_or_fail(args, cwd=self._repo.path)
def _parse_refs(self, output):
refs = {}
diff --git a/dulwich/tests/compat/utils.py b/dulwich/tests/compat/utils.py
index 0fcb23f..255ab3d 100644
--- a/dulwich/tests/compat/utils.py
+++ b/dulwich/tests/compat/utils.py
@@ -47,8 +47,7 @@ def git_version(git_path=_DEFAULT_GIT):
None if no git installation was found.
"""
try:
- _, output = run_git(['--version'], git_path=git_path,
- capture_stdout=True)
+ output = run_git_or_fail(['--version'], git_path=git_path)
except OSError:
return None
version_prefix = 'git version '
--
1.7.1
References