-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Install command implementation and tests
- Loading branch information
1 parent
1f301a0
commit b9ae8e3
Showing
6 changed files
with
201 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""install CLI command implementation.""" | ||
# dem/cli/command/install_cmd.py | ||
|
||
from dem.core.dev_env import DevEnv | ||
from dem.core.platform import Platform, PlatformError | ||
from dem.cli.console import stderr, stdout | ||
|
||
def execute(platform: Platform, dev_env_name: str) -> None: | ||
""" | ||
Install the given Development Environment. | ||
Args: | ||
platform -- the platform | ||
dev_env_name -- the name of the Development Environment to install | ||
""" | ||
dev_env_to_install: DevEnv | None = platform.get_dev_env_by_name(dev_env_name) | ||
|
||
if dev_env_to_install is None: | ||
stderr.print(f"[red]Error: The {dev_env_name} Development Environment does not exist.[/]") | ||
elif dev_env_to_install.is_installed == True: | ||
stderr.print(f"[red]Error: The {dev_env_name} Development Environment is already installed.[/]") | ||
else: | ||
try: | ||
platform.install_dev_env(dev_env_to_install) | ||
except PlatformError as e: | ||
stderr.print(f"[red]Error: {e}[/]") | ||
else: | ||
stdout.print(f"[green]Successfully installed the {dev_env_name}![/]") |
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,93 @@ | ||
"""Tests for the install command.""" | ||
|
||
# Unit under test: | ||
import dem.cli.main as main | ||
import dem.cli.command.install_cmd as install_cmd | ||
|
||
# Test framework | ||
from typer.testing import CliRunner | ||
from unittest.mock import patch, MagicMock | ||
|
||
## Global test variables | ||
runner = CliRunner() | ||
|
||
@patch("dem.cli.command.install_cmd.stderr.print") | ||
def test_install_dev_env_invalid_name(mock_stderr_print): | ||
# Test setup | ||
test_invalid_name = "fake_dev_env_name" | ||
|
||
mock_platform = MagicMock() | ||
mock_platform.get_dev_env_by_name.return_value = None | ||
main.platform = mock_platform | ||
|
||
# Run unit under test | ||
runner_result = runner.invoke(main.typer_cli, ["install", test_invalid_name], color=True) | ||
|
||
# Check expectations | ||
assert 0 == runner_result.exit_code | ||
|
||
mock_platform.get_dev_env_by_name.assert_called_once_with(test_invalid_name) | ||
mock_stderr_print.assert_called_once_with(f"[red]Error: The {test_invalid_name} Development Environment does not exist.[/]") | ||
|
||
|
||
|
||
@patch("dem.cli.command.install_cmd.stdout.print") | ||
def test_install_dev_env_valid_name(mock_stdout_print): | ||
# Test setup | ||
fake_dev_env_to_install = MagicMock() | ||
fake_dev_env_to_install.name = "dev_env" | ||
fake_dev_env_to_install.is_installed = False | ||
mock_platform = MagicMock() | ||
mock_platform.get_dev_env_by_name.return_value = fake_dev_env_to_install | ||
main.platform = mock_platform | ||
|
||
# Run unit under test | ||
runner_result = runner.invoke(main.typer_cli, ["install", fake_dev_env_to_install.name ], color=True) | ||
|
||
# Check expectations | ||
assert 0 == runner_result.exit_code | ||
|
||
mock_platform.get_dev_env_by_name.assert_called_once_with(fake_dev_env_to_install.name ) | ||
mock_platform.install_dev_env.assert_called_once_with(fake_dev_env_to_install) | ||
mock_stdout_print.assert_called_once_with(f"[green]Successfully installed the {fake_dev_env_to_install.name}![/]") | ||
|
||
|
||
@patch("dem.cli.command.install_cmd.stderr.print") | ||
def test_install_dev_env_already_installed(mock_stderr_print): | ||
# Test setup | ||
fake_dev_env_to_install = MagicMock() | ||
fake_dev_env_to_install.name = "dev_env" | ||
fake_dev_env_to_install.is_installed = True | ||
mock_platform = MagicMock() | ||
mock_platform.get_dev_env_by_name.return_value = fake_dev_env_to_install | ||
main.platform = mock_platform | ||
|
||
# Run unit under test | ||
runner_result = runner.invoke(main.typer_cli, ["install", fake_dev_env_to_install.name ], color=True) | ||
|
||
# Check expectations | ||
assert 0 == runner_result.exit_code | ||
|
||
mock_stderr_print.assert_called_once_with(f"[red]Error: The {fake_dev_env_to_install.name} Development Environment is already installed.[/]") | ||
|
||
@patch("dem.cli.command.install_cmd.stderr.print") | ||
def test_install_dev_env_valid_name_failed(mock_stderr_print): | ||
# Test setup | ||
fake_dev_env_to_install = MagicMock() | ||
fake_dev_env_to_install.name = "dev_env" | ||
fake_dev_env_to_install.is_installed = False | ||
mock_platform = MagicMock() | ||
mock_platform.get_dev_env_by_name.return_value = fake_dev_env_to_install | ||
test_exception_text = "test_exception_text" | ||
mock_platform.install_dev_env.side_effect = install_cmd.PlatformError(test_exception_text) | ||
main.platform = mock_platform | ||
|
||
# Run unit under test | ||
runner_result = runner.invoke(main.typer_cli, ["install", fake_dev_env_to_install.name ], color=True) | ||
|
||
# Check expectations | ||
assert 0 == runner_result.exit_code | ||
|
||
mock_platform.get_dev_env_by_name.assert_called_once_with(fake_dev_env_to_install.name ) | ||
mock_stderr_print.assert_called_once_with(f"[red]Error: Platform error: {test_exception_text}[/]") | ||
|
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