Commit 6b8d9e80 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

add tests for logger

parent 7eb6a5ba
Pipeline #2428 failed with stage
in 0 seconds
...@@ -16,7 +16,7 @@ from typing import Optional ...@@ -16,7 +16,7 @@ from typing import Optional
def get_logger(name: str = "CSST pipeline", filename: Optional[str] = None): def get_logger(name: str = "CSST pipeline", filename: Optional[str] = None):
""" """
Get a logger for CSST pipelines. Get a CSST starndard logger.
Messages with levels >= DEBUG will be output by stream. Messages with levels >= DEBUG will be output by stream.
Messages with levels >= INFO will be recorded by a log file. Messages with levels >= INFO will be recorded by a log file.
...@@ -68,16 +68,3 @@ def get_logger(name: str = "CSST pipeline", filename: Optional[str] = None): ...@@ -68,16 +68,3 @@ def get_logger(name: str = "CSST pipeline", filename: Optional[str] = None):
logger.addHandler(file_handler) logger.addHandler(file_handler)
return logger return logger
if __name__ == "__main__":
import os
print(os.getcwd())
logger = get_logger(filename="test_logger.log")
print("Type of logger:", type(logger))
print("Name of logger:", logger.name)
logger.debug("Well ..")
logger.info("Hello ...")
logger.warning("There ...")
logger.error("Good morning ...")
"""
Identifier: tests/test_logger.py
Name: test_logger.py
Description: test logger
Author: Bo Zhang
Created: 2023-12-15
Modified-History:
2023-12-15, Bo Zhang, add TestLogger
"""
import os
import unittest
from csst_common.logger import get_logger
class TestFile(unittest.TestCase):
def test_file(self):
logger = get_logger(filename="test_logger.log")
print(os.getcwd())
print("Type of logger:", type(logger))
print("Name of logger:", logger.name)
logger.debug("Well ..")
logger.info("Hello ...")
logger.warning("There ...")
logger.error("Good morning ...")
with open("test_logger.log", "r") as f:
lines = f.readlines()
self.assertTrue(lines[0].endswith("Hello ..."))
self.assertTrue(lines[1].endswith("There ..."))
self.assertTrue(lines[2].endswith("Good morning ..."))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment