Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add a few tests
  • Loading branch information
teeberg committed Jan 22, 2015
commit 6f038611ff120f8283f0f1a56962f95b66730c72
20 changes: 20 additions & 0 deletions git/test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,23 @@ def test_env_vars_passed_to_git(self):
editor = 'non_existant_editor'
with mock.patch.dict('os.environ', {'GIT_EDITOR': editor}):
assert self.git.var("GIT_EDITOR") == editor

def test_environment(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how I could test the sshkey context manager without accessing an actual repo. Also, how could I check whether the environment is actually passed into the git process? The former would cover the latter. Do you have ideas?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something that could work is to adjust the script for the test to actually fail with a distinct error code, and possibly emit something distinctive to STDERR.
That way, you could call the real git process, on a bogus git@server:foo/bar repo URL, and verify that it failed under your conditions. That can proof that the script was actually called.
The cool thing is that this would require you to put in a way to adjust the path the script handling the GIT_SSH, which could be done so that advanced users can either set it, or derive from the Git command implementation.

# sanity check
assert self.git.environment() == {}

# make sure the context manager works and cleans up after itself
with self.git.with_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() == {}