diff options
author | Ruomei Yan <ruomei.yan@arm.com> | 2022-11-02 16:47:56 +0000 |
---|---|---|
committer | Ruomei Yan <ruomei.yan@arm.com> | 2022-11-15 13:02:56 +0000 |
commit | 47fc50576e7040680c19e152592b2c5e5cc297f5 (patch) | |
tree | f10fc331e7bc7358c7da8cf3582d9428db4e7367 /tests/test_tools_metadata_common.py | |
parent | ef73bb773df214f3f33f8e4ca7d276041106cad2 (diff) | |
download | mlia-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_tools_metadata_common.py')
-rw-r--r-- | tests/test_tools_metadata_common.py | 63 |
1 files changed, 57 insertions, 6 deletions
diff --git a/tests/test_tools_metadata_common.py b/tests/test_tools_metadata_common.py index 69bc3e5..fefb024 100644 --- a/tests/test_tools_metadata_common.py +++ b/tests/test_tools_metadata_common.py @@ -18,6 +18,30 @@ from mlia.tools.metadata.common import InstallationType from mlia.tools.metadata.common import InstallFromPath +def get_default_installation_manager_mock( + name: str, + already_installed: bool = False, +) -> MagicMock: + """Get mock instance for DefaultInstallationManager.""" + mock = MagicMock(spec=DefaultInstallationManager) + + props = { + "name": name, + "already_installed": already_installed, + } + for prop, value in props.items(): + setattr(type(mock), prop, PropertyMock(return_value=value)) + + return mock + + +def _ready_for_uninstall_mock() -> MagicMock: + return get_default_installation_manager_mock( + name="already_installed", + already_installed=True, + ) + + def get_installation_mock( name: str, already_installed: bool = False, @@ -107,14 +131,14 @@ def test_installation_manager_filtering() -> None: could_be_downloaded_and_installed, ] ) - assert manager.already_installed() == [already_installed] + assert manager.already_installed("already_installed") == [already_installed] assert manager.ready_for_installation() == [ ready_for_installation, could_be_downloaded_and_installed, ] - assert manager.could_be_downloaded_and_installed() == [ - could_be_downloaded_and_installed - ] + assert manager.could_be_downloaded_and_installed( + "could_be_downloaded_and_installed" + ) == [could_be_downloaded_and_installed] assert manager.could_be_downloaded_and_installed("some_installation") == [] @@ -146,7 +170,7 @@ def test_installation_manager_download_and_install( install_mock: MagicMock, noninteractive: bool, eula_agreement: bool, - backend_name: str | None, + backend_name: str, expected_call: Any, monkeypatch: pytest.MonkeyPatch, ) -> None: @@ -183,7 +207,7 @@ def test_installation_manager_download_and_install( def test_installation_manager_install_from( install_mock: MagicMock, noninteractive: bool, - backend_name: str | None, + backend_name: str, expected_call: Any, monkeypatch: pytest.MonkeyPatch, ) -> None: @@ -194,3 +218,30 @@ def test_installation_manager_install_from( manager.install_from(Path("some_path"), backend_name) assert install_mock.install.mock_calls == expected_call + + +@pytest.mark.parametrize("noninteractive", [True, False]) +@pytest.mark.parametrize( + "install_mock, backend_name, expected_call", + [ + [ + _ready_for_uninstall_mock(), + "already_installed", + [call()], + ], + ], +) +def test_installation_manager_uninstall( + install_mock: MagicMock, + noninteractive: bool, + backend_name: str, + expected_call: Any, + monkeypatch: pytest.MonkeyPatch, +) -> None: + """Test uninstallation.""" + install_mock.reset_mock() + + manager = get_installation_manager(noninteractive, [install_mock], monkeypatch) + manager.uninstall(backend_name) + + assert install_mock.uninstall.mock_calls == expected_call |