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/mlia/test_utils_logging.py | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/mlia/test_utils_logging.py (limited to 'tests/mlia/test_utils_logging.py') diff --git a/tests/mlia/test_utils_logging.py b/tests/mlia/test_utils_logging.py new file mode 100644 index 0000000..75ebceb --- /dev/null +++ b/tests/mlia/test_utils_logging.py @@ -0,0 +1,63 @@ +# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates. +# SPDX-License-Identifier: Apache-2.0 +"""Tests for the logging utility functions.""" +import logging +import sys +from contextlib import ExitStack as does_not_raise +from pathlib import Path +from typing import Any +from typing import Optional + +import pytest + +from mlia.cli.logging import create_log_handler + + +@pytest.mark.parametrize( + "file_path, stream, log_filter, delay, expected_error, expected_class", + [ + ( + "test.log", + None, + None, + True, + does_not_raise(), + logging.FileHandler, + ), + ( + None, + sys.stdout, + None, + None, + does_not_raise(), + logging.StreamHandler, + ), + ( + None, + None, + None, + None, + pytest.raises(Exception, match="Unable to create logging handler"), + None, + ), + ], +) +def test_create_log_handler( + file_path: Optional[Path], + stream: Optional[Any], + log_filter: Optional[logging.Filter], + delay: bool, + expected_error: Any, + expected_class: type, +) -> None: + """Test function test_create_log_handler.""" + with expected_error: + handler = create_log_handler( + file_path=file_path, + stream=stream, + log_level=logging.INFO, + log_format="%(name)s - %(message)s", + log_filter=log_filter, + delay=delay, + ) + assert isinstance(handler, expected_class) -- cgit v1.2.1