summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2010-06-02 12:30:33 +0200
committerSebastian Thiel <byronimo@gmail.com>2010-06-02 12:51:05 +0200
commit8c1a87d11df666d308d14e4ae7ee0e9d614296b6 (patch)
tree87481ab28367db496886a3801bda37227c10f7ed /test
parentdf0892351a394d768489b5647d47b73c24d3ef5f (diff)
downloadgitpython-8c1a87d11df666d308d14e4ae7ee0e9d614296b6.tar.gz
commit: refactored existing code to decode commits from streams - performance is slightly better
git.cmd: added method to provide access to the content stream directly. This is more efficient if large objects are handled, if it is actually used test.helpers: removed unnecessary code
Diffstat (limited to 'test')
-rw-r--r--test/git/test_commit.py2
-rw-r--r--test/git/test_diff.py6
-rw-r--r--test/git/test_repo.py5
-rw-r--r--test/testlib/helper.py38
4 files changed, 13 insertions, 38 deletions
diff --git a/test/git/test_commit.py b/test/git/test_commit.py
index 48937c93..28b407ac 100644
--- a/test/git/test_commit.py
+++ b/test/git/test_commit.py
@@ -129,7 +129,7 @@ class TestCommit(TestBase):
bisect_all=True)
assert_true(git.called)
- commits = Commit._iter_from_process_or_stream(self.rorepo, ListProcessAdapter(revs), True)
+ commits = Commit._iter_from_process_or_stream(self.rorepo, StringProcessAdapter(revs), True)
expected_ids = (
'cf37099ea8d1d8c7fbf9b6d12d7ec0249d3acb8b',
'33ebe7acec14b25c5f84f35a664803fcab2f7781',
diff --git a/test/git/test_diff.py b/test/git/test_diff.py
index 2f6a19bd..a113b992 100644
--- a/test/git/test_diff.py
+++ b/test/git/test_diff.py
@@ -20,7 +20,7 @@ class TestDiff(TestBase):
return diffs
def test_list_from_string_new_mode(self):
- output = ListProcessAdapter(fixture('diff_new_mode'))
+ output = StringProcessAdapter(fixture('diff_new_mode'))
diffs = Diff._index_from_patch_format(self.rorepo, output.stdout)
self._assert_diff_format(diffs)
@@ -28,7 +28,7 @@ class TestDiff(TestBase):
assert_equal(10, len(diffs[0].diff.splitlines()))
def test_diff_with_rename(self):
- output = ListProcessAdapter(fixture('diff_rename'))
+ output = StringProcessAdapter(fixture('diff_rename'))
diffs = Diff._index_from_patch_format(self.rorepo, output.stdout)
self._assert_diff_format(diffs)
@@ -47,7 +47,7 @@ class TestDiff(TestBase):
"diff_tree_numstat_root" )
for fixture_name in fixtures:
- diff_proc = ListProcessAdapter(fixture(fixture_name))
+ diff_proc = StringProcessAdapter(fixture(fixture_name))
diffs = Diff._index_from_patch_format(self.rorepo, diff_proc.stdout)
# END for each fixture
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index ce79402a..9316245b 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -48,6 +48,7 @@ class TestRepo(TestBase):
def test_tree_from_revision(self):
tree = self.rorepo.tree('0.1.6')
+ assert len(tree.sha) == 40
assert tree.type == "tree"
assert self.rorepo.tree(tree) == tree
@@ -56,9 +57,9 @@ class TestRepo(TestBase):
@patch_object(Git, '_call_process')
def test_commits(self, git):
- git.return_value = ListProcessAdapter(fixture('rev_list'))
+ git.return_value = StringProcessAdapter(fixture('rev_list'))
- commits = list( self.rorepo.iter_commits('master', max_count=10) )
+ commits = list(self.rorepo.iter_commits('master', max_count=10))
c = commits[0]
assert_equal('4c8124ffcf4039d292442eeccabdeca5af5c5017', c.sha)
diff --git a/test/testlib/helper.py b/test/testlib/helper.py
index 9c38ffd5..c9b4c2ac 100644
--- a/test/testlib/helper.py
+++ b/test/testlib/helper.py
@@ -9,6 +9,7 @@ from git import Repo, Remote, GitCommandError
from unittest import TestCase
import tempfile
import shutil
+import cStringIO
GIT_REPO = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
@@ -23,40 +24,13 @@ def absolute_project_path():
return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
-class ListProcessAdapter(object):
- """Allows to use lists as Process object as returned by SubProcess.Popen.
+class StringProcessAdapter(object):
+ """Allows to use strings as Process object as returned by SubProcess.Popen.
Its tailored to work with the test system only"""
- class Stream(object):
- """Simple stream emulater meant to work only with tests"""
- def __init__(self, data):
- self.data = data
- self.cur_iter = None
-
- def __iter__(self):
- dat = self.data
- if isinstance(dat, basestring):
- dat = dat.splitlines()
- if self.cur_iter is None:
- self.cur_iter = iter(dat)
- return self.cur_iter
-
- def read(self):
- dat = self.data
- if isinstance(dat, (tuple,list)):
- dat = "\n".join(dat)
- return dat
-
- def next(self):
- if self.cur_iter is None:
- self.cur_iter = iter(self)
- return self.cur_iter.next()
-
- # END stream
-
- def __init__(self, input_list_or_string):
- self.stdout = self.Stream(input_list_or_string)
- self.stderr = self.Stream('')
+ def __init__(self, input_string):
+ self.stdout = cStringIO.StringIO(input_string)
+ self.stderr = cStringIO.StringIO()
def wait(self):
return 0