diff options
author | Benjamin Klimczak <benjamin.klimczak@arm.com> | 2022-07-11 12:33:42 +0100 |
---|---|---|
committer | Benjamin Klimczak <benjamin.klimczak@arm.com> | 2022-07-26 14:08:21 +0100 |
commit | 5d81f37de09efe10f90512e50252be9c36925fcf (patch) | |
tree | b4d7cdfd051da0a6e882bdfcf280fd7ca7b39e57 /tests/test_utils_console.py | |
parent | 7899b908c1fe6d86b92a80f3827ddd0ac05b674b (diff) | |
download | mlia-5d81f37de09efe10f90512e50252be9c36925fcf.tar.gz |
MLIA-551 Rework remains of AIET architecture
Re-factoring the code base to further merge the old AIET code into MLIA.
- Remove last traces of the backend type 'tool'
- Controlled systems removed, including SSH protocol, controller,
RunningCommand, locks etc.
- Build command / build dir and deploy functionality removed from
Applications and Systems
- Moving working_dir()
- Replace module 'output_parser' with new module 'output_consumer' and
merge Base64 parsing into it
- Change the output consumption to optionally remove (i.e. actually
consume) lines
- Use Base64 parsing in GenericInferenceOutputParser, replacing the
regex-based parsing and remove the now unused regex parsing
- Remove AIET reporting
- Pre-install applications by moving them to src/mlia/resources/backends
- Rename aiet-config.json to backend-config.json
- Move tests from tests/mlia/ to tests/
- Adapt unit tests to code changes
- Dependencies removed: paramiko, filelock, psutil
- Fix bug in corstone.py: The wrong resource directory was used which
broke the functionality to download backends.
- Use f-string formatting.
- Use logging instead of print.
Change-Id: I768bc3bb6b2eda57d219ad01be4a8e0a74167d76
Diffstat (limited to 'tests/test_utils_console.py')
-rw-r--r-- | tests/test_utils_console.py | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/tests/test_utils_console.py b/tests/test_utils_console.py new file mode 100644 index 0000000..36975f8 --- /dev/null +++ b/tests/test_utils_console.py @@ -0,0 +1,100 @@ +# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates. +# SPDX-License-Identifier: Apache-2.0 +"""Tests for console utility functions.""" +from typing import Iterable +from typing import List +from typing import Optional + +import pytest + +from mlia.utils.console import apply_style +from mlia.utils.console import create_section_header +from mlia.utils.console import produce_table +from mlia.utils.console import remove_ascii_codes + + +@pytest.mark.parametrize( + "rows, headers, table_style, expected_result", + [ + [[], [], "no_borders", ""], + [ + [["1", "2", "3"]], + ["Col 1", "Col 2", "Col 3"], + "default", + """ +┌───────┬───────┬───────┐ +│ Col 1 │ Col 2 │ Col 3 │ +╞═══════╪═══════╪═══════╡ +│ 1 │ 2 │ 3 │ +└───────┴───────┴───────┘ +""".strip(), + ], + [ + [["1", "2", "3"]], + ["Col 1", "Col 2", "Col 3"], + "nested", + "Col 1 Col 2 Col 3 \n \n1 2 3", + ], + [ + [["1", "2", "3"]], + ["Col 1", "Col 2", "Col 3"], + "no_borders", + " Col 1 Col 2 Col 3 \n 1 2 3", + ], + ], +) +def test_produce_table( + rows: Iterable, headers: Optional[List[str]], table_style: str, expected_result: str +) -> None: + """Test produce_table function.""" + result = produce_table(rows, headers, table_style) + assert remove_ascii_codes(result) == expected_result + + +def test_produce_table_unknown_style() -> None: + """Test that function should fail if unknown style provided.""" + with pytest.raises(Exception, match="Unsupported table style unknown_style"): + produce_table([["1", "2", "3"]], [], "unknown_style") + + +@pytest.mark.parametrize( + "value, expected_result", + [ + ["some text", "some text"], + ["\033[32msome text\033[0m", "some text"], + ], +) +def test_remove_ascii_codes(value: str, expected_result: str) -> None: + """Test remove_ascii_codes function.""" + assert remove_ascii_codes(value) == expected_result + + +def test_apply_style() -> None: + """Test function apply_style.""" + assert apply_style("some text", "green") == "[green]some text" + + +@pytest.mark.parametrize( + "section_header, expected_result", + [ + [ + "Section header", + "\n--- Section header -------------------------------" + "------------------------------\n", + ], + [ + "", + f"\n{'-' * 80}\n", + ], + ], +) +def test_create_section_header(section_header: str, expected_result: str) -> None: + """Test function test_create_section.""" + assert create_section_header(section_header) == expected_result + + +def test_create_section_header_too_long_value() -> None: + """Test that header could not be created for the too long section names.""" + section_name = "section name" * 100 + with pytest.raises(ValueError, match="Section name too long"): + create_section_header(section_name) |