Skip to content

Commit

Permalink
Added tests to catch command line execution errors
Browse files Browse the repository at this point in the history
I added three tests to check to make sure command line
calls execute correctly under the following conditions:
- non-existent branch passed
- existing branch passed
- no branch passed(or "") -- figure out default
  • Loading branch information
sean-morris committed Jun 16, 2021
1 parent 66101be commit 1e57904
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nbgitpuller/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ def main():
for line in GitPuller(
args.git_url,
args.repo_dir,
branch=args.branch_name
branch=args.branch_name if args.branch_name else None
).pull():
print(line)


if __name__ == '__main__':
main()
43 changes: 43 additions & 0 deletions tests/test_gitpuller.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,49 @@ def test_initialize():
assert puller.git('rev-parse', 'HEAD') == pusher.git('rev-parse', 'HEAD')


def command_line_test_helper(remote_path, branch, pusher_path):
work_dir = "/".join(os.path.dirname(os.path.abspath(__file__)).split("/")[:-1]) + "/nbgitpuller"
try:
cmd = ['python3', 'pull.py', remote_path, branch, pusher_path]
sp.check_output(
cmd,
cwd=work_dir
).decode()
return True
except Exception:
return False


def test_command_line_existing_branch():
branch = "master"
with Remote() as remote, Pusher(remote) as pusher:
pusher.push_file('README.md', '1')
remotepath = "file://%s" % os.path.abspath(remote.path)
pusherpath = os.path.abspath(pusher.path)
subprocess_result = command_line_test_helper(remotepath, branch, pusherpath)
assert subprocess_result


def test_command_line_default_branch():
branch = ""
with Remote() as remote, Pusher(remote) as pusher:
pusher.push_file('README.md', '1')
remotepath = "file://%s" % os.path.abspath(remote.path)
pusherpath = os.path.abspath(pusher.path)
subprocess_result = command_line_test_helper(remotepath, branch, pusherpath)
assert subprocess_result


def test_command_line_non_existing_branch():
branch = "wrong"
with Remote() as remote, Pusher(remote) as pusher:
pusher.push_file('README.md', '1')
remotepath = "file://%s" % os.path.abspath(remote.path)
pusherpath = os.path.abspath(pusher.path)
subprocess_result = command_line_test_helper(remotepath, branch, pusherpath)
assert not subprocess_result


def test_branch_exists():
with Remote() as remote, Pusher(remote) as pusher:
pusher.push_file('README.md', '1')
Expand Down

0 comments on commit 1e57904

Please sign in to comment.