From 1e5790467ae4a4bbf4d76c2763baf00f342d0c66 Mon Sep 17 00:00:00 2001 From: Sean Morris Date: Mon, 14 Jun 2021 16:54:17 -0700 Subject: [PATCH] Added tests to catch command line execution errors 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 --- nbgitpuller/pull.py | 6 +++++- tests/test_gitpuller.py | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/nbgitpuller/pull.py b/nbgitpuller/pull.py index 5fa5f93a..ef2aefb7 100644 --- a/nbgitpuller/pull.py +++ b/nbgitpuller/pull.py @@ -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() diff --git a/tests/test_gitpuller.py b/tests/test_gitpuller.py index 05c01354..0055b0da 100644 --- a/tests/test_gitpuller.py +++ b/tests/test_gitpuller.py @@ -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')