summaryrefslogtreecommitdiff
path: root/git/test/test_cmd.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2014-02-10 21:40:53 +0100
committerSebastian Thiel <byronimo@gmail.com>2014-02-10 21:40:53 +0100
commit1cb02ebcaa4891c01a1d6cba11a3cd9806fad782 (patch)
tree51130c659e5089434e84404940ed1451f6c5d5cc /git/test/test_cmd.py
parent660bdca125aa9dcca7a7730535bec433edb8ba02 (diff)
parentf77230f618722e964a76657ebb03d822b2f73518 (diff)
downloadgitpython-1cb02ebcaa4891c01a1d6cba11a3cd9806fad782.tar.gz
Merge branch 'feature/spaces-and-cleanup-master'
* feature/spaces-and-cleanup-master: Basic fixes to get tests back on track. Of course there is much more work to be done here removed leftover gitdb - I thought it was merged into git tabs to 4 spaces - overall state of this branch is desolate, but fixable. Needs plenty of work
Diffstat (limited to 'git/test/test_cmd.py')
-rw-r--r--git/test/test_cmd.py220
1 files changed, 110 insertions, 110 deletions
diff --git a/git/test/test_cmd.py b/git/test/test_cmd.py
index b5732339..985cdad2 100644
--- a/git/test/test_cmd.py
+++ b/git/test/test_cmd.py
@@ -6,127 +6,127 @@
import os, sys
from git.test.lib import (
- TestBase,
- patch_object,
- raises,
- assert_equal,
- assert_true,
- assert_match,
- fixture_path
- )
+ TestBase,
+ patch,
+ raises,
+ assert_equal,
+ assert_true,
+ assert_match,
+ fixture_path
+ )
from git import Git, GitCommandError
class TestGit(TestBase):
-
- @classmethod
- def setUpAll(cls):
- super(TestGit, cls).setUpAll()
- cls.git = Git(cls.rorepo.working_dir)
+
+ @classmethod
+ def setUp(cls):
+ super(TestGit, cls).setUp()
+ cls.git = Git(cls.rorepo.working_dir)
- @patch_object(Git, 'execute')
- def test_call_process_calls_execute(self, git):
- git.return_value = ''
- self.git.version()
- assert_true(git.called)
- assert_equal(git.call_args, ((['git', 'version'],), {}))
+ @patch.object(Git, 'execute')
+ def test_call_process_calls_execute(self, git):
+ git.return_value = ''
+ self.git.version()
+ assert_true(git.called)
+ assert_equal(git.call_args, ((['git', 'version'],), {}))
- @raises(GitCommandError)
- def test_it_raises_errors(self):
- self.git.this_does_not_exist()
+ @raises(GitCommandError)
+ def test_it_raises_errors(self):
+ self.git.this_does_not_exist()
- def test_it_transforms_kwargs_into_git_command_arguments(self):
- assert_equal(["-s"], self.git.transform_kwargs(**{'s': True}))
- assert_equal(["-s5"], self.git.transform_kwargs(**{'s': 5}))
+ def test_it_transforms_kwargs_into_git_command_arguments(self):
+ assert_equal(["-s"], self.git.transform_kwargs(**{'s': True}))
+ assert_equal(["-s5"], self.git.transform_kwargs(**{'s': 5}))
- assert_equal(["--max-count"], self.git.transform_kwargs(**{'max_count': True}))
- assert_equal(["--max-count=5"], self.git.transform_kwargs(**{'max_count': 5}))
+ assert_equal(["--max-count"], self.git.transform_kwargs(**{'max_count': True}))
+ assert_equal(["--max-count=5"], self.git.transform_kwargs(**{'max_count': 5}))
- assert_equal(["-s", "-t"], self.git.transform_kwargs(**{'s': True, 't': True}))
+ assert_equal(["-s", "-t"], self.git.transform_kwargs(**{'s': True, 't': True}))
- def test_it_executes_git_to_shell_and_returns_result(self):
- assert_match('^git version [\d\.]{2}.*$', self.git.execute(["git","version"]))
+ def test_it_executes_git_to_shell_and_returns_result(self):
+ assert_match('^git version [\d\.]{2}.*$', self.git.execute(["git","version"]))
- def test_it_accepts_stdin(self):
- filename = fixture_path("cat_file_blob")
- fh = open(filename, 'r')
- assert_equal("70c379b63ffa0795fdbfbc128e5a2818397b7ef8",
- self.git.hash_object(istream=fh, stdin=True))
- fh.close()
+ def test_it_accepts_stdin(self):
+ filename = fixture_path("cat_file_blob")
+ fh = open(filename, 'r')
+ assert_equal("70c379b63ffa0795fdbfbc128e5a2818397b7ef8",
+ self.git.hash_object(istream=fh, stdin=True))
+ fh.close()
- @patch_object(Git, 'execute')
- def test_it_ignores_false_kwargs(self, git):
- # this_should_not_be_ignored=False implies it *should* be ignored
- output = self.git.version(pass_this_kwarg=False)
- assert_true("pass_this_kwarg" not in git.call_args[1])
-
- def test_persistent_cat_file_command(self):
- # read header only
- import subprocess as sp
- hexsha = "b2339455342180c7cc1e9bba3e9f181f7baa5167"
- g = self.git.cat_file(batch_check=True, istream=sp.PIPE,as_process=True)
- g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
- g.stdin.flush()
- obj_info = g.stdout.readline()
-
- # read header + data
- g = self.git.cat_file(batch=True, istream=sp.PIPE,as_process=True)
- g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
- g.stdin.flush()
- obj_info_two = g.stdout.readline()
- assert obj_info == obj_info_two
-
- # read data - have to read it in one large chunk
- size = int(obj_info.split()[2])
- data = g.stdout.read(size)
- terminating_newline = g.stdout.read(1)
-
- # now we should be able to read a new object
- g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
- g.stdin.flush()
- assert g.stdout.readline() == obj_info
-
-
- # same can be achived using the respective command functions
- hexsha, typename, size = self.git.get_object_header(hexsha)
- hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha)
- assert typename == typename_two and size == size_two
-
- def test_version(self):
- v = self.git.version_info
- assert isinstance(v, tuple)
- for n in v:
- assert isinstance(n, int)
- #END verify number types
-
- def test_cmd_override(self):
- prev_cmd = self.git.GIT_PYTHON_GIT_EXECUTABLE
- try:
- # set it to something that doens't exist, assure it raises
- type(self.git).GIT_PYTHON_GIT_EXECUTABLE = os.path.join("some", "path", "which", "doesn't", "exist", "gitbinary")
- self.failUnlessRaises(OSError, self.git.version)
- finally:
- type(self.git).GIT_PYTHON_GIT_EXECUTABLE = prev_cmd
- #END undo adjustment
-
- def test_output_strip(self):
- import subprocess as sp
- hexsha = "b2339455342180c7cc1e9bba3e9f181f7baa5167"
+ @patch.object(Git, 'execute')
+ def test_it_ignores_false_kwargs(self, git):
+ # this_should_not_be_ignored=False implies it *should* be ignored
+ output = self.git.version(pass_this_kwarg=False)
+ assert_true("pass_this_kwarg" not in git.call_args[1])
+
+ def test_persistent_cat_file_command(self):
+ # read header only
+ import subprocess as sp
+ hexsha = "b2339455342180c7cc1e9bba3e9f181f7baa5167"
+ g = self.git.cat_file(batch_check=True, istream=sp.PIPE,as_process=True)
+ g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
+ g.stdin.flush()
+ obj_info = g.stdout.readline()
+
+ # read header + data
+ g = self.git.cat_file(batch=True, istream=sp.PIPE,as_process=True)
+ g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
+ g.stdin.flush()
+ obj_info_two = g.stdout.readline()
+ assert obj_info == obj_info_two
+
+ # read data - have to read it in one large chunk
+ size = int(obj_info.split()[2])
+ data = g.stdout.read(size)
+ terminating_newline = g.stdout.read(1)
+
+ # now we should be able to read a new object
+ g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
+ g.stdin.flush()
+ assert g.stdout.readline() == obj_info
+
+
+ # same can be achived using the respective command functions
+ hexsha, typename, size = self.git.get_object_header(hexsha)
+ hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha)
+ assert typename == typename_two and size == size_two
+
+ def test_version(self):
+ v = self.git.version_info
+ assert isinstance(v, tuple)
+ for n in v:
+ assert isinstance(n, int)
+ #END verify number types
+
+ def test_cmd_override(self):
+ prev_cmd = self.git.GIT_PYTHON_GIT_EXECUTABLE
+ try:
+ # set it to something that doens't exist, assure it raises
+ type(self.git).GIT_PYTHON_GIT_EXECUTABLE = os.path.join("some", "path", "which", "doesn't", "exist", "gitbinary")
+ self.failUnlessRaises(OSError, self.git.version)
+ finally:
+ type(self.git).GIT_PYTHON_GIT_EXECUTABLE = prev_cmd
+ #END undo adjustment
+
+ def test_output_strip(self):
+ import subprocess as sp
+ hexsha = "b2339455342180c7cc1e9bba3e9f181f7baa5167"
- # Verify that a trailing newline is stripped from the output of a git
- # command.
- content = self.git.cat_file('blob', hexsha)
- g = self.git.hash_object(istream=sp.PIPE, as_process=True, stdin=True)
- g.stdin.write(content)
- g.stdin.close()
- newsha = g.stdout.readline().strip()
- self.assertNotEquals(newsha, hexsha)
+ # Verify that a trailing newline is stripped from the output of a git
+ # command.
+ content = self.git.cat_file('blob', hexsha)
+ g = self.git.hash_object(istream=sp.PIPE, as_process=True, stdin=True)
+ g.stdin.write(content)
+ g.stdin.close()
+ newsha = g.stdout.readline().strip()
+ self.assertNotEquals(newsha, hexsha)
- # Verify that output of a git command which ends with an empty
- # line is not modified when the output_strip flag is cleared.
- content = self.git.cat_file('blob', hexsha, output_strip=False)
- g = self.git.hash_object(istream=sp.PIPE, as_process=True, stdin=True)
- g.stdin.write(content)
- g.stdin.close()
- newsha = g.stdout.readline().strip()
- self.assertEquals(newsha, hexsha)
+ # Verify that output of a git command which ends with an empty
+ # line is not modified when the output_strip flag is cleared.
+ content = self.git.cat_file('blob', hexsha, output_strip=False)
+ g = self.git.hash_object(istream=sp.PIPE, as_process=True, stdin=True)
+ g.stdin.write(content)
+ g.stdin.close()
+ newsha = g.stdout.readline().strip()
+ self.assertEquals(newsha, hexsha)