aboutsummaryrefslogtreecommitdiff
path: root/tests/test_cli_options.py
diff options
context:
space:
mode:
authorDiego Russo <diego.russo@arm.com>2023-02-02 22:04:05 +0000
committerDiego Russo <diego.russo@arm.com>2023-02-03 17:48:11 +0000
commitf1eaff3c9790464bed3183ff76555cf815166f50 (patch)
treebba288bb051925a692e1e1f998f7cc48df755df6 /tests/test_cli_options.py
parentd1b2374cda6811a93d1174400fc2eecd7100a8c3 (diff)
downloadmlia-f1eaff3c9790464bed3183ff76555cf815166f50.tar.gz
MLIA-782 Remove --output parameter
* Remove --output parameter from argument parser * Remove FormattedFilePath class and its presence across the codebase * Move logging module from cli to core * The output format is now injected in the execution context and used across MLIA * Depending on the output format, TextReporter and JSONReporter have been created and used accordingly. * The whole output to standard output and/or logfile is driven via the logging module: the only case where the print is used is when the --json parameter is specified. This is needed becase all output (including third party application as well) needs to be disabled otherwise it might corrupt the json output in the standard output. * Debug information is logged into the log file and printed to stdout when the output format is plain_text. * Update E2E test and config to cope with the new mechanism of outputting json data to standard output. Change-Id: I4395800b0b1af4d24406a828d780bdeef98cd413
Diffstat (limited to 'tests/test_cli_options.py')
-rw-r--r--tests/test_cli_options.py60
1 files changed, 14 insertions, 46 deletions
diff --git a/tests/test_cli_options.py b/tests/test_cli_options.py
index a889a93..94c3111 100644
--- a/tests/test_cli_options.py
+++ b/tests/test_cli_options.py
@@ -5,16 +5,14 @@ from __future__ import annotations
import argparse
from contextlib import ExitStack as does_not_raise
-from pathlib import Path
from typing import Any
import pytest
-from mlia.cli.options import add_output_options
+from mlia.cli.options import get_output_format
from mlia.cli.options import get_target_profile_opts
from mlia.cli.options import parse_optimization_parameters
-from mlia.cli.options import parse_output_parameters
-from mlia.core.common import FormattedFilePath
+from mlia.core.typing import OutputFormat
@pytest.mark.parametrize(
@@ -164,54 +162,24 @@ def test_get_target_opts(args: dict | None, expected_opts: list[str]) -> None:
@pytest.mark.parametrize(
- "output_parameters, expected_path",
- [
- [["--output", "report.json"], "report.json"],
- [["--output", "REPORT.JSON"], "REPORT.JSON"],
- [["--output", "some_folder/report.json"], "some_folder/report.json"],
- ],
-)
-def test_output_options(output_parameters: list[str], expected_path: str) -> None:
- """Test output options resolving."""
- parser = argparse.ArgumentParser()
- add_output_options(parser)
-
- args = parser.parse_args(output_parameters)
- assert str(args.output) == expected_path
-
-
-@pytest.mark.parametrize(
- "path, json, expected_error, output",
+ "args, expected_output_format",
[
[
- None,
- True,
- pytest.raises(
- argparse.ArgumentError,
- match=r"To enable JSON output you need to specify the output path. "
- r"\(e.g. --output out.json --json\)",
- ),
- None,
+ {},
+ "plain_text",
],
- [None, False, does_not_raise(), None],
[
- Path("test_path"),
- False,
- does_not_raise(),
- FormattedFilePath(Path("test_path"), "plain_text"),
+ {"json": True},
+ "json",
],
[
- Path("test_path"),
- True,
- does_not_raise(),
- FormattedFilePath(Path("test_path"), "json"),
+ {"json": False},
+ "plain_text",
],
],
)
-def test_parse_output_parameters(
- path: Path | None, json: bool, expected_error: Any, output: FormattedFilePath | None
-) -> None:
- """Test parsing for output parameters."""
- with expected_error:
- formatted_output = parse_output_parameters(path, json)
- assert formatted_output == output
+def test_get_output_format(args: dict, expected_output_format: OutputFormat) -> None:
+ """Test get_output_format function."""
+ arguments = argparse.Namespace(**args)
+ output_format = get_output_format(arguments)
+ assert output_format == expected_output_format