Add tmgr_logger unit test 24/11224/1
authorTaewan Kim <t25.kim@samsung.com>
Thu, 25 May 2023 16:04:36 +0000 (01:04 +0900)
committerTaewan Kim <t25.kim@samsung.com>
Thu, 25 May 2023 16:23:47 +0000 (01:23 +0900)
Issue-ID: AIMLFW-13

Change-Id: Ifda85f883d72d2153dd54eb55d3e1577c95417e0
Signed-off-by: Taewan Kim <t25.kim@samsung.com>
tests/test_tmgr_logger.py [new file with mode: 0644]
trainingmgr/common/tmgr_logger.py

diff --git a/tests/test_tmgr_logger.py b/tests/test_tmgr_logger.py
new file mode 100644 (file)
index 0000000..0801929
--- /dev/null
@@ -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
index d06a226..9b00624 100644 (file)
@@ -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