generated from iamogbz/oss-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add nvm shim for running nvm commands (#168)
- Loading branch information
Showing
13 changed files
with
120 additions
and
47 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
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,14 @@ | ||
import os | ||
import shlex | ||
import sys | ||
|
||
import nvshim.core.__main__ as core | ||
|
||
|
||
def main(): | ||
nvm_args = " ".join(shlex.quote(arg) for arg in sys.argv[1:]) | ||
core.run_nvm_cmd(core.get_nvmsh_path(core.get_nvm_dir()), nvm_args) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
import runpy | ||
import sys | ||
|
||
import pytest | ||
|
||
from nvshim.core.shim_nvm import main | ||
from nvshim.utils.constants import ErrorCode | ||
from nvshim.utils.process import clean_output | ||
|
||
|
||
@pytest.fixture | ||
def test_shim_args(): | ||
initial_args = list(sys.argv) | ||
sys.argv = ["/full/path/to/shim/nvm", "--version", "--help"] | ||
yield sys.argv | ||
sys.argv = initial_args | ||
|
||
|
||
def test_shim_nvm_executes_with_args(mocker, test_shim_args): | ||
nvm_dir = "/home/.nvm" | ||
mocker.patch( | ||
"nvshim.core.shim_nvm.core.get_nvm_dir", autospec=True, return_value=nvm_dir | ||
) | ||
mocked_core_run_nvm_cmd = mocker.patch( | ||
"nvshim.core.shim_nvm.core.run_nvm_cmd", autospec=True | ||
) | ||
main() | ||
mocked_core_run_nvm_cmd.assert_called_once_with( | ||
f"{nvm_dir}/nvm.sh", "--version --help" | ||
) |
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,3 @@ | ||
# name: test_process_run_handles_exception_interrupt | ||
'Interrupted. Ctrl+C' | ||
--- |
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 |
---|---|---|
@@ -1,16 +1,31 @@ | ||
import subprocess | ||
import pytest | ||
|
||
from nvshim.utils import process | ||
from nvshim.utils import constants, process | ||
|
||
|
||
def test_process_run_completes_successfully(): | ||
output = process.run("echo", "success", stdout=subprocess.PIPE).stdout.strip() | ||
assert output == b"success" | ||
assert output == "success" | ||
|
||
|
||
def test_process_run_raises_correct_exception(): | ||
def test_process_run_handles_exception_system_exit(): | ||
with pytest.raises(SystemExit) as exc_info: | ||
process.run("bash", "-c", "exit 1") | ||
|
||
assert exc_info.value.code == 1 | ||
|
||
|
||
def test_process_run_handles_exception_interrupt(mocker, capsys, snapshot): | ||
mocked_process_run = mocker.patch( | ||
"subprocess.run", | ||
autospec=True, | ||
side_effect=KeyboardInterrupt("Ctrl+C"), | ||
) | ||
mocked_sys_exit = mocker.patch("sys.exit") | ||
args = ("bash", "-c", "echo 1") | ||
process.run(*args) | ||
mocked_process_run.assert_called_once_with(args, check=True, encoding="UTF-8") | ||
mocked_sys_exit.assert_called_once_with(constants.ErrorCode.KEYBOARD_INTERRUPT) | ||
captured = capsys.readouterr() | ||
snapshot.assert_match(process.clean_output(captured.out)) |