aboutsummaryrefslogtreecommitdiff
path: root/tests/test_cli_main.py
diff options
context:
space:
mode:
authorRuomei Yan <ruomei.yan@arm.com>2022-11-02 16:47:56 +0000
committerRuomei Yan <ruomei.yan@arm.com>2022-11-15 13:02:56 +0000
commit47fc50576e7040680c19e152592b2c5e5cc297f5 (patch)
treef10fc331e7bc7358c7da8cf3582d9428db4e7367 /tests/test_cli_main.py
parentef73bb773df214f3f33f8e4ca7d276041106cad2 (diff)
downloadmlia-47fc50576e7040680c19e152592b2c5e5cc297f5.tar.gz
MLIA-649 Strip mlia backend management into a new command
* add entry point for mlia-backend in setup.cfg and main.py * add --force option for install from path: uninstall existing backend in ML Inference Advisor and install from given path * add uninstall and list program parameters: uninstall has backend_name as input arg, install has backend_name as a mandatory argument * add unit tests in test_cli_commands.py, test_cli_main.py, test_tools_metadata_common.py, test_tools_metadata_corstone.py * updated README.md * remove --download option for installing backend * add new lines for the display section when we do mlia-backen list * add case insensitive support for backend names in command line argument Change-Id: Icb89d8957fa6be4b767710e24fa074f26472674b
Diffstat (limited to 'tests/test_cli_main.py')
-rw-r--r--tests/test_cli_main.py51
1 files changed, 40 insertions, 11 deletions
diff --git a/tests/test_cli_main.py b/tests/test_cli_main.py
index 4b16ac5..d0f7152 100644
--- a/tests/test_cli_main.py
+++ b/tests/test_cli_main.py
@@ -15,6 +15,7 @@ from unittest.mock import MagicMock
import pytest
import mlia
+from mlia.cli.main import backend_main
from mlia.cli.main import CommandInfo
from mlia.cli.main import main
from mlia.core.context import ExecutionContext
@@ -122,6 +123,17 @@ def test_default_command(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Non
non_default_command.assert_called_once_with(param="test")
+def wrap_mock_command(mock: MagicMock, command: Callable) -> Callable:
+ """Wrap the command with the mock."""
+
+ @wraps(command)
+ def mock_command(*args: Any, **kwargs: Any) -> Any:
+ """Mock the command."""
+ mock(*args, **kwargs)
+
+ return mock_command
+
+
@pytest.mark.parametrize(
"params, expected_call",
[
@@ -273,16 +285,6 @@ def test_commands_execution(
"""Test calling commands from the main function."""
mock = MagicMock()
- def wrap_mock_command(command: Callable) -> Callable:
- """Wrap the command with the mock."""
-
- @wraps(command)
- def mock_command(*args: Any, **kwargs: Any) -> Any:
- """Mock the command."""
- mock(*args, **kwargs)
-
- return mock_command
-
monkeypatch.setattr(
"mlia.cli.options.get_default_backends", MagicMock(return_value=["Vela"])
)
@@ -295,7 +297,7 @@ def test_commands_execution(
for command in ["all_tests", "operators", "performance", "optimization"]:
monkeypatch.setattr(
f"mlia.cli.main.{command}",
- wrap_mock_command(getattr(mlia.cli.main, command)),
+ wrap_mock_command(mock, getattr(mlia.cli.main, command)),
)
main(params)
@@ -304,6 +306,33 @@ def test_commands_execution(
@pytest.mark.parametrize(
+ "params, expected_call",
+ [
+ [
+ ["list"],
+ call(),
+ ],
+ ],
+)
+def test_commands_execution_backend_main(
+ monkeypatch: pytest.MonkeyPatch,
+ params: list[str],
+ expected_call: Any,
+) -> None:
+ """Test calling commands from the backend_main function."""
+ mock = MagicMock()
+
+ monkeypatch.setattr(
+ "mlia.cli.main.backend_list",
+ wrap_mock_command(mock, getattr(mlia.cli.main, "backend_list")),
+ )
+
+ backend_main(params)
+
+ mock.assert_called_once_with(*expected_call.args, **expected_call.kwargs)
+
+
+@pytest.mark.parametrize(
"verbose, exc_mock, expected_output",
[
[