-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marc Udoff
committed
Aug 3, 2020
1 parent
1fa946d
commit a0f38bf
Showing
3 changed files
with
128 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import os | ||
from subprocess import CalledProcessError | ||
from unittest.mock import Mock, call, patch | ||
|
||
import pytest | ||
import tornado | ||
|
||
from jupyterlab_git import JupyterLabGit | ||
from jupyterlab_git.git import Git | ||
|
||
from .testutils import FakeContentManager, maybe_future | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_init(): | ||
with patch("jupyterlab_git.git.execute") as mock_execute: | ||
# Given | ||
mock_execute.return_value = maybe_future((0, "", "")) | ||
|
||
# When | ||
actual_response = await Git(FakeContentManager("/bin")).init("test_curr_path") | ||
|
||
mock_execute.assert_called_once_with( | ||
["git", "init"], cwd=os.path.join("/bin", "test_curr_path") | ||
) | ||
|
||
assert {"code": 0, "actions": None} == actual_response | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_init_and_post_init(): | ||
with patch("jupyterlab_git.git.execute") as mock_execute: | ||
# Given | ||
mock_execute.side_effect = [ | ||
maybe_future((0, "", "")), | ||
maybe_future((0, "hello", "")), | ||
] | ||
|
||
# When | ||
actual_response = await Git( | ||
FakeContentManager("/bin"), | ||
JupyterLabGit(actions={"post_init": ['echo "hello"']}), | ||
).init("test_curr_path") | ||
|
||
mock_execute.assert_called_with( | ||
["echo", "hello"], cwd=os.path.join("/bin", "test_curr_path") | ||
) | ||
|
||
assert { | ||
"code": 0, | ||
"actions": [ | ||
{"cmd": 'echo "hello"', "code": 0, "stderr": "", "stdout": "hello"} | ||
], | ||
} == actual_response | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_init_and_post_init_fail(): | ||
with patch("jupyterlab_git.git.execute") as mock_execute: | ||
# Given | ||
mock_execute.side_effect = [ | ||
maybe_future((0, "", "")), | ||
maybe_future((1, "", "not_there: command not found")), | ||
] | ||
|
||
# When | ||
actual_response = await Git( | ||
FakeContentManager("/bin"), | ||
JupyterLabGit(actions={"post_init": ["not_there arg"]}), | ||
).init("test_curr_path") | ||
|
||
mock_execute.assert_called_with( | ||
["not_there", "arg"], cwd=os.path.join("/bin", "test_curr_path") | ||
) | ||
|
||
assert { | ||
"code": 1, | ||
"message": "", | ||
"command": "git init", | ||
"actions": [ | ||
{ | ||
"stderr": "not_there: command not found", | ||
"stdout": "", | ||
"code": 1, | ||
"cmd": "not_there arg", | ||
} | ||
], | ||
} == actual_response |