diff options
Diffstat (limited to 'git/test/test_git.py')
| -rw-r--r-- | git/test/test_git.py | 56 |
1 files changed, 46 insertions, 10 deletions
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 + + |
