aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDmitrii Agibov <dmitrii.agibov@arm.com>2023-02-15 09:08:14 +0000
committerDmitrii Agibov <dmitrii.agibov@arm.com>2023-02-15 12:11:59 +0000
commitaf251a19c623dc371c959c75e823ef11aeeccdf2 (patch)
tree8aa89585cc6f5455cce26498a6bbdd6b4b6df6c5 /tests
parent49dfd03617ed28a4fcbd847dd958c27442c84556 (diff)
downloadmlia-af251a19c623dc371c959c75e823ef11aeeccdf2.tar.gz
MLIA-813 Change default output directory
- If no output directory provided then create one in the current working directory - Update documentation and tests Change-Id: Id1f2acef14e1bd2edffbfa6139a961a5c5018211
Diffstat (limited to 'tests')
-rw-r--r--tests/test_cli_main.py4
-rw-r--r--tests/test_core_context.py37
2 files changed, 36 insertions, 5 deletions
diff --git a/tests/test_cli_main.py b/tests/test_cli_main.py
index 3472e31..c129c4b 100644
--- a/tests/test_cli_main.py
+++ b/tests/test_cli_main.py
@@ -311,7 +311,7 @@ def test_commands_execution_backend_main(
MagicMock(side_effect=Exception("Error")),
[
"Execution finished with error: Error",
- "Please check the log files in the /tmp/mlia-",
+ "Please check the log files in the",
"/logs for more details",
],
],
@@ -320,7 +320,7 @@ def test_commands_execution_backend_main(
MagicMock(side_effect=Exception("Error")),
[
"Execution finished with error: Error",
- "Please check the log files in the /tmp/mlia-",
+ "Please check the log files in the",
"/logs for more details, or enable debug mode (--debug)",
],
],
diff --git a/tests/test_core_context.py b/tests/test_core_context.py
index 814cb6a..09b34e9 100644
--- a/tests/test_core_context.py
+++ b/tests/test_core_context.py
@@ -3,13 +3,16 @@
"""Tests for the module context."""
from __future__ import annotations
+import re
from pathlib import Path
import pytest
from mlia.core.common import AdviceCategory
+from mlia.core.context import create_output_dir_with_timestamp
from mlia.core.context import ExecutionContext
from mlia.core.events import DefaultEventPublisher
+from mlia.utils.filesystem import working_directory
@pytest.mark.parametrize(
@@ -39,9 +42,8 @@ def test_execution_context_category_enabled(
) -> None:
"""Test category enabled method of execution context."""
for category in expected_enabled_categories:
- assert ExecutionContext(
- advice_category=context_advice_category
- ).category_enabled(category)
+ ctx = ExecutionContext(advice_category=context_advice_category)
+ assert ctx.category_enabled(category)
def test_execution_context(tmpdir: str) -> None:
@@ -79,6 +81,9 @@ def test_execution_context(tmpdir: str) -> None:
"output_format=json"
)
+
+def test_execution_context_with_default_params(tmpdir: str) -> None:
+ """Test execution context with the default parameters."""
context_with_default_params = ExecutionContext(output_dir=tmpdir)
assert context_with_default_params.advice_category == {AdviceCategory.COMPATIBILITY}
assert context_with_default_params.config_parameters is None
@@ -101,3 +106,29 @@ def test_execution_context(tmpdir: str) -> None:
"output_format=plain_text"
)
assert str(context_with_default_params) == expected_str
+
+
+def test_create_output_dir_with_timestamp(tmp_path: Path) -> None:
+ """Test function generate_output_dir_with_timestamp."""
+ working_dir = tmp_path / "sample"
+ with working_directory(working_dir, create_dir=True):
+ create_output_dir_with_timestamp()
+
+ working_dir_content = list(working_dir.iterdir())
+ assert len(working_dir_content) == 1
+
+ parent_dir = working_dir_content[0]
+ assert parent_dir.is_dir()
+ assert parent_dir.name == "mlia-output"
+
+ parent_dir_content = list(parent_dir.iterdir())
+ assert len(parent_dir_content) == 1
+
+ output_dir = parent_dir_content[0]
+ assert output_dir.is_dir()
+
+ pattern = re.compile(r"mlia-output-\d{4}-\d{2}-\d{2}T\d+[.]\d+")
+ assert pattern.match(output_dir.name)
+
+ output_dir_content = list(output_dir.iterdir())
+ assert not output_dir_content