From 0efca3cadbad5517a59884576ddb90cfe7ac30f8 Mon Sep 17 00:00:00 2001 From: Diego Russo Date: Mon, 30 May 2022 13:34:14 +0100 Subject: Add MLIA codebase Add MLIA codebase including sources and tests. Change-Id: Id41707559bd721edd114793618d12ccd188d8dbd --- tests/aiet/test_backend_tool.py | 60 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/aiet/test_backend_tool.py (limited to 'tests/aiet/test_backend_tool.py') diff --git a/tests/aiet/test_backend_tool.py b/tests/aiet/test_backend_tool.py new file mode 100644 index 0000000..fd5960d --- /dev/null +++ b/tests/aiet/test_backend_tool.py @@ -0,0 +1,60 @@ +# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates. +# SPDX-License-Identifier: Apache-2.0 +# pylint: disable=no-self-use +"""Tests for the tool backend.""" +from collections import Counter + +import pytest + +from aiet.backend.common import ConfigurationException +from aiet.backend.config import ToolConfig +from aiet.backend.tool import get_available_tool_directory_names +from aiet.backend.tool import get_available_tools +from aiet.backend.tool import get_tool +from aiet.backend.tool import Tool + + +def test_get_available_tool_directory_names() -> None: + """Test get_available_tools mocking get_resources.""" + directory_names = get_available_tool_directory_names() + assert Counter(directory_names) == Counter(["tool1", "tool2", "vela"]) + + +def test_get_available_tools() -> None: + """Test get_available_tools mocking get_resources.""" + available_tools = get_available_tools() + expected_tool_names = sorted( + [ + "tool_1", + "tool_2", + "vela", + "vela", + "vela", + ] + ) + + assert all(isinstance(s, Tool) for s in available_tools) + assert all(s != 42 for s in available_tools) + assert any(s == available_tools[0] for s in available_tools) + assert len(available_tools) == len(expected_tool_names) + available_tool_names = sorted(str(s) for s in available_tools) + assert available_tool_names == expected_tool_names + + +def test_get_tool() -> None: + """Test get_tool mocking get_resoures.""" + tools = get_tool("tool_1") + assert len(tools) == 1 + tool = tools[0] + assert tool is not None + assert isinstance(tool, Tool) + assert tool.name == "tool_1" + + tools = get_tool("unknown tool") + assert not tools + + +def test_tool_creation() -> None: + """Test edge cases when creating a Tool instance.""" + with pytest.raises(ConfigurationException): + Tool(ToolConfig(name="test", commands={"test": []})) # no 'run' command -- cgit v1.2.1