From: Taewan Kim Date: Thu, 25 May 2023 16:04:36 +0000 (+0900) Subject: Add tmgr_logger unit test X-Git-Tag: 1.1.0~4^2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=6ba85016bc5758a81980a336145eea097ef78ca4;p=aiml-fw%2Fawmf%2Ftm.git Add tmgr_logger unit test Issue-ID: AIMLFW-13 Change-Id: Ifda85f883d72d2153dd54eb55d3e1577c95417e0 Signed-off-by: Taewan Kim --- diff --git a/tests/test_tmgr_logger.py b/tests/test_tmgr_logger.py new file mode 100644 index 0000000..0801929 --- /dev/null +++ b/tests/test_tmgr_logger.py @@ -0,0 +1,35 @@ +# ================================================================================== +# +# Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ================================================================================== + +from trainingmgr.common.tmgr_logger import TMLogger + +class Test_tmgr_logger: + def setup_method(self): + self.logger = TMLogger("tests/common/conf_log.yaml") + + def test_init_fail(self): + logger = TMLogger("tests/common/conf_log.yam") + assert vars(logger) == {} + assert 'logger' in vars(self.logger).keys() + assert 'log_level' in vars(self.logger).keys() + + def test_get_logger(self): + assert self.logger.get_logger.name == 'trainingmgr.common.tmgr_logger' + + def test_get_log_level(self): + assert self.logger.get_log_level == 'DEBUG' \ No newline at end of file diff --git a/trainingmgr/common/tmgr_logger.py b/trainingmgr/common/tmgr_logger.py index d06a226..9b00624 100644 --- a/trainingmgr/common/tmgr_logger.py +++ b/trainingmgr/common/tmgr_logger.py @@ -36,14 +36,17 @@ class TMLogger(object):# pylint: disable=too-few-public-methods def __init__(self, conf_file): """ The constructor for TMLogger class. - Parameters:None - """ + Parameters + ---------- + conf_file : str + a file path for the logger configuration + """ try: with open(conf_file, 'r') as file: log_config = yaml.safe_load(file.read()) logging.config.dictConfig(log_config) - self.loglevel = log_config["root"]["level"] + self.log_level = log_config["root"]["level"] self.logger = logging.getLogger(__name__) except FileNotFoundError as err: print("error opening yaml config file") @@ -60,6 +63,6 @@ class TMLogger(object):# pylint: disable=too-few-public-methods return self.logger @property - def get_logLevel(self): - return self.loglevel + def get_log_level(self): + return self.log_level