diff options
Diffstat (limited to 'git/test')
| -rw-r--r-- | git/test/fixtures/.gitconfig | 3 | ||||
| -rw-r--r-- | git/test/lib/helper.py | 10 | ||||
| -rw-r--r-- | git/test/test_config.py | 15 | ||||
| -rw-r--r-- | git/test/test_docs.py | 2 | ||||
| -rw-r--r-- | git/test/test_remote.py | 5 |
5 files changed, 23 insertions, 12 deletions
diff --git a/git/test/fixtures/.gitconfig b/git/test/fixtures/.gitconfig new file mode 100644 index 00000000..6a0459f6 --- /dev/null +++ b/git/test/fixtures/.gitconfig @@ -0,0 +1,3 @@ +[alias] + rbi = "!g() { git rebase -i origin/${1:-master} ; } ; g" + expush = "!f() { git branch -f tmp ; { git rbi $1 && git push ; } ; git reset --hard tmp ; git rebase origin/${1:-master}; } ; f"
\ No newline at end of file diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py index 541b972d..8be2881c 100644 --- a/git/test/lib/helper.py +++ b/git/test/lib/helper.py @@ -18,10 +18,11 @@ from git.compat import string_types osp = os.path.dirname GIT_REPO = os.environ.get("GIT_PYTHON_TEST_GIT_REPO_BASE", osp(osp(osp(osp(__file__))))) +GIT_DAEMON_PORT = os.environ.get("GIT_PYTHON_TEST_GIT_DAEMON_PORT", "9418") __all__ = ( 'fixture_path', 'fixture', 'absolute_project_path', 'StringProcessAdapter', - 'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase', 'GIT_REPO' + 'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase', 'GIT_REPO', 'GIT_DAEMON_PORT' ) #{ Routines @@ -193,14 +194,15 @@ def with_rw_and_rw_remote_repo(working_tree_ref): # by the user, not by us d_remote = Remote.create(rw_repo, "daemon_origin", remote_repo_dir) d_remote.fetch() - remote_repo_url = "git://localhost%s" % remote_repo_dir + remote_repo_url = "git://localhost:%s%s" % (GIT_DAEMON_PORT, remote_repo_dir) d_remote.config_writer.set('url', remote_repo_url) temp_dir = osp(_mktemp()) # On windows, this will fail ... we deal with failures anyway and default to telling the user to do it try: - gd = Git().daemon(temp_dir, enable='receive-pack', as_process=True) + gd = Git().daemon(temp_dir, enable='receive-pack', listen='127.0.0.1', port=GIT_DAEMON_PORT, + as_process=True) # yes, I know ... fortunately, this is always going to work if sleep time is just large enough time.sleep(0.5) except Exception: @@ -223,6 +225,8 @@ def with_rw_and_rw_remote_repo(working_tree_ref): raise AssertionError(msg) else: msg = 'Please start a git-daemon to run this test, execute: git daemon --enable=receive-pack "%s"' + msg += 'You can also run the daemon on a different port by passing --port=<port>' + msg += 'and setting the environment variable GIT_PYTHON_TEST_GIT_DAEMON_PORT to <port>' msg %= temp_dir raise AssertionError(msg) # END make assertion diff --git a/git/test/test_config.py b/git/test/test_config.py index fc2b87b6..7758a094 100644 --- a/git/test/test_config.py +++ b/git/test/test_config.py @@ -18,7 +18,6 @@ from git.compat import ( ) import io import os -from copy import copy from git.config import cp @@ -30,21 +29,18 @@ class TestBase(TestCase): sio.name = file_path return sio - def _parsers_equal_or_raise(self, lhs, rhs): - pass - def test_read_write(self): # writer must create the exact same file as the one read before for filename in ("git_config", "git_config_global"): file_obj = self._to_memcache(fixture_path(filename)) - file_obj_orig = copy(file_obj) w_config = GitConfigParser(file_obj, read_only=False) w_config.read() # enforce reading assert w_config._sections w_config.write() # enforce writing # we stripped lines when reading, so the results differ - assert file_obj.getvalue() and file_obj.getvalue() != file_obj_orig.getvalue() + assert file_obj.getvalue() + self.assertEqual(file_obj.getvalue(), self._to_memcache(fixture_path(filename)).getvalue()) # creating an additional config writer must fail due to exclusive access self.failUnlessRaises(IOError, GitConfigParser, file_obj, read_only=False) @@ -207,3 +203,10 @@ class TestBase(TestCase): assert not cw.has_section('core') assert len(cw.items(nn)) == 4 cw.release() + + def test_complex_aliases(self): + file_obj = self._to_memcache(fixture_path('.gitconfig')) + w_config = GitConfigParser(file_obj, read_only=False) + self.assertEqual(w_config.get('alias', 'rbi'), '"!g() { git rebase -i origin/${1:-master} ; } ; g"') + w_config.release() + self.assertEqual(file_obj.getvalue(), self._to_memcache(fixture_path('.gitconfig')).getvalue()) diff --git a/git/test/test_docs.py b/git/test/test_docs.py index 586f0ce4..5b8aa817 100644 --- a/git/test/test_docs.py +++ b/git/test/test_docs.py @@ -94,7 +94,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('0') + assert (now.commit.tree / 'VERSION').data_stream.read().decode('ascii').startswith('1') # You can traverse trees as well to handle all contained files of a particular commit file_count = 0 diff --git a/git/test/test_remote.py b/git/test/test_remote.py index c419ecee..af854988 100644 --- a/git/test/test_remote.py +++ b/git/test/test_remote.py @@ -8,7 +8,8 @@ from git.test.lib import ( TestBase, with_rw_repo, with_rw_and_rw_remote_repo, - fixture + fixture, + GIT_DAEMON_PORT ) from git import ( RemoteProgress, @@ -250,7 +251,7 @@ 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 = "git://localhost%s" % remote_repo.git_dir + remote_repo_url = "git://localhost:%s%s" % (GIT_DAEMON_PORT, remote_repo.git_dir) # put origin to git-url other_origin = other_repo.remotes.origin |
