Skip to content

Commit 1e57904

Browse files
committed
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
1 parent 66101be commit 1e57904

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

nbgitpuller/pull.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ def main():
310310
for line in GitPuller(
311311
args.git_url,
312312
args.repo_dir,
313-
branch=args.branch_name
313+
branch=args.branch_name if args.branch_name else None
314314
).pull():
315315
print(line)
316+
317+
318+
if __name__ == '__main__':
319+
main()

tests/test_gitpuller.py

+43
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,49 @@ def test_initialize():
9696
assert puller.git('rev-parse', 'HEAD') == pusher.git('rev-parse', 'HEAD')
9797

9898

99+
def command_line_test_helper(remote_path, branch, pusher_path):
100+
work_dir = "/".join(os.path.dirname(os.path.abspath(__file__)).split("/")[:-1]) + "/nbgitpuller"
101+
try:
102+
cmd = ['python3', 'pull.py', remote_path, branch, pusher_path]
103+
sp.check_output(
104+
cmd,
105+
cwd=work_dir
106+
).decode()
107+
return True
108+
except Exception:
109+
return False
110+
111+
112+
def test_command_line_existing_branch():
113+
branch = "master"
114+
with Remote() as remote, Pusher(remote) as pusher:
115+
pusher.push_file('README.md', '1')
116+
remotepath = "file://%s" % os.path.abspath(remote.path)
117+
pusherpath = os.path.abspath(pusher.path)
118+
subprocess_result = command_line_test_helper(remotepath, branch, pusherpath)
119+
assert subprocess_result
120+
121+
122+
def test_command_line_default_branch():
123+
branch = ""
124+
with Remote() as remote, Pusher(remote) as pusher:
125+
pusher.push_file('README.md', '1')
126+
remotepath = "file://%s" % os.path.abspath(remote.path)
127+
pusherpath = os.path.abspath(pusher.path)
128+
subprocess_result = command_line_test_helper(remotepath, branch, pusherpath)
129+
assert subprocess_result
130+
131+
132+
def test_command_line_non_existing_branch():
133+
branch = "wrong"
134+
with Remote() as remote, Pusher(remote) as pusher:
135+
pusher.push_file('README.md', '1')
136+
remotepath = "file://%s" % os.path.abspath(remote.path)
137+
pusherpath = os.path.abspath(pusher.path)
138+
subprocess_result = command_line_test_helper(remotepath, branch, pusherpath)
139+
assert not subprocess_result
140+
141+
99142
def test_branch_exists():
100143
with Remote() as remote, Pusher(remote) as pusher:
101144
pusher.push_file('README.md', '1')

0 commit comments

Comments
 (0)