summaryrefslogtreecommitdiff
path: root/git/test
diff options
context:
space:
mode:
Diffstat (limited to 'git/test')
-rw-r--r--git/test/test_docs.py9
-rw-r--r--git/test/test_git.py56
-rw-r--r--git/test/test_remote.py4
3 files changed, 57 insertions, 12 deletions
diff --git a/git/test/test_docs.py b/git/test/test_docs.py
index 586f0ce4..965d10fb 100644
--- a/git/test/test_docs.py
+++ b/git/test/test_docs.py
@@ -437,6 +437,15 @@ class Tutorials(TestBase):
git.for_each_ref() # '-' becomes '_' when calling it
# ![31-test_references_and_objects]
+ # [32-test_references_and_objects]
+ private_key_file = os.path.join(rw_dir, 'id_rsa_deployment_key')
+ with repo.git.sshkey(private_key_file):
+ # Note that we don't actually make the call here, as our test-setup doesn't permit it to
+ # succeed.
+ # It will in your case :)
+ repo.remotes.origin.fetch
+ # ![32-test_references_and_objects]
+
def test_submodules(self):
# [1-test_submodules]
repo = self.rorepo
diff --git a/git/test/test_git.py b/git/test/test_git.py
index f25fa21a..990f4cd0 100644
--- a/git/test/test_git.py
+++ b/git/test/test_git.py
@@ -4,18 +4,24 @@
#
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-
import os
import mock
-from git.test.lib import (TestBase,
- patch,
- raises,
- assert_equal,
- assert_true,
- assert_match,
- fixture_path)
-from git import (Git,
- GitCommandError)
+
+from git.test.lib import (
+ TestBase,
+ patch,
+ raises,
+ assert_equal,
+ assert_true,
+ assert_match,
+ fixture_path
+)
+from git import (
+ Git,
+ GitCommandError,
+ Repo
+)
+from gitdb.test.lib import with_rw_directory
from git.compat import PY3
@@ -153,3 +159,33 @@ class TestGit(TestBase):
editor = 'non_existant_editor'
with mock.patch.dict('os.environ', {'GIT_EDITOR': editor}):
assert self.git.var("GIT_EDITOR") == editor
+
+ @with_rw_directory
+ def test_environment(self, rw_dir):
+ # sanity check
+ assert self.git.environment() == {}
+
+ # make sure the context manager works and cleans up after itself
+ with self.git.custom_environment(PWD='/tmp'):
+ assert self.git.environment() == {'PWD': '/tmp'}
+
+ assert self.git.environment() == {}
+
+ old_env = self.git.update_environment(VARKEY='VARVALUE')
+ # The returned dict can be used to revert the change, hence why it has
+ # an entry with value 'None'.
+ assert old_env == {'VARKEY': None}
+ assert self.git.environment() == {'VARKEY': 'VARVALUE'}
+
+ new_env = self.git.update_environment(**old_env)
+ assert new_env == {'VARKEY': 'VARVALUE'}
+ assert self.git.environment() == {}
+
+ rw_repo = Repo.init(os.path.join(rw_dir, 'repo'))
+ remote = rw_repo.create_remote('ssh-origin', "ssh://git@server/foo")
+
+ with rw_repo.git.sshkey('doesntexist.key'):
+ remote.fetch()
+ # end
+
+
diff --git a/git/test/test_remote.py b/git/test/test_remote.py
index 4fd78230..98d74d8b 100644
--- a/git/test/test_remote.py
+++ b/git/test/test_remote.py
@@ -164,11 +164,11 @@ class TestRemote(TestBase):
def get_info(res, remote, name):
return res["%s/%s" % (remote, name)]
- # put remote head to master as it is garantueed to exist
+ # put remote head to master as it is guaranteed to exist
remote_repo.head.reference = remote_repo.heads.master
res = fetch_and_test(remote)
- # all uptodate
+ # all up to date
for info in res:
assert info.flags & info.HEAD_UPTODATE