def test_setup_logger_default(tmpdir, mocker): log_dirname = os.path.join(tmpdir, "log") setup_logger(log_dirname) teardown_logger() assert os.path.isfile(os.path.join(log_dirname, "20200801-123456.log")) datefmt = "%Y-%m-%d %H:%M" _logger = setup_logger(log_dirname, datefmt=datefmt) assert _logger.handlers[1].formatter.datefmt == datefmt
def test_setup_logger_default(tmpdir, mocker): log_dirname = os.path.join(tmpdir, "log") setup_logger(log_dirname) teardown_logger() assert os.path.isfile(os.path.join(log_dirname, "20200801-123456.log")) mock_formatter = mocker.patch("logging.Formatter") datefmt = "%Y-%m-%d %H:%M:%S" setup_logger(log_dirname, datefmt=datefmt) mock_formatter.assert_called_with(datefmt=datefmt)
def test_run_jtagboot(board, test_case): board_name, component = test_case.split("-") machine = board_name variant = get_variant(machine) board = board(test_name=component, params=[variant, machine], machine=machine) setup_logger(board.config.logDir, console_level=logging.DEBUG) config = board.config images_dir = config["deployDir"] jtag_boot(board.serial, board.xsdb, config, images_dir, variant) linux_login_cons( board.serial, user="******", password="******", login=True, timeout=300 )
def test_setup_logger_levels(tmpdir, teardown): log_dirname = os.path.join(tmpdir, "log") _logger = setup_logger(log_dirname, console_level=logging.DEBUG, file_level=logging.INFO) fh = _logger.handlers[1] ch = _logger.handlers[2] assert fh.level == logging.INFO assert ch.level == logging.DEBUG
def __init__(self, config, setup: bool = True): super().__init__(config) self.setup = setup # override workDir with customized option if config.get("work_root_dir"): work_dir = os.path.join( config.work_root_dir, *config.get("base_params", ""), *config.get("test_path_list", ""), *config.get("params", ""), "work", ) if self.setup: reset(work_dir) config["workDir"] = work_dir self.wsDir = config["wsDir"] self.workDir = config["workDir"] self.logDir = config["logDir"] self.imagesDir = config["imagesDir"] if self.setup: reset(config["wsDir"]) mkdir(config["workDir"]) mkdir(config["logDir"]) mkdir(config["imagesDir"]) log_filename = config.get("log_filename") console_level = config.get("console_level", logging.INFO) file_level = config.get("file_level", logging.DEBUG) console_format = config.get("console_format", "") file_format = config.get("file_format", "") time_format = config.get("time_format", "") report_summary = config.get("report_summary", False) report_tokens = config.get("report_tokens", []) self.logger = setup_logger( config["logDir"], log_filename=log_filename, console_level=console_level, file_level=file_level, console_format=console_format, file_format=file_format, time_format=time_format, report_summary=report_summary, report_tokens=report_tokens, ) log.info("Logger setup completed.") log.debug(f'wsDir={config["wsDir"]}') log.debug(f'workDir={config["workDir"]}') log.debug(f'logDir={config["logDir"]}') log.debug(f'imagesDir={config["imagesDir"]}') log.debug( f"logfile={self.logger.log_path}, console_level={console_level}, file_level={file_level}" ) log.debug( f"console_format={console_format}, file_format={file_format}") atexit.register(self.__del__)
def test_run(board): """Running hello world application demo""" # Use board fixture to acquired board object my_board = board() setup_logger(my_board.config.logDir, console_level=logging.DEBUG) # Set the processor my_board.xsdb.set_proc(my_board.config.proc) my_board.xsdb.rst_proc() # Load FSBL my_board.xsdb.load_elf(my_board.config.fsbl_path) my_board.xsdb.runcmd("con") # Load ELF time.sleep(60) my_board.xsdb.load_elf(my_board.config.elf_path) my_board.xsdb.runcmd("con") expected_list = ["Successfully", "PASSED"] my_board.serial.expect(expected=expected_list, timeout=300)
def test_setup_logger_kwargs(tmpdir, teardown): fmt = "%(asctime)s.%(msecs)03d - %(name)s - %(levelname)s - %(message)s" datefmt = "%Y-%m-%d" log_dirname = os.path.join(tmpdir, "log") _logger = setup_logger(log_dirname, fmt=fmt, datefmt=datefmt) fh = _logger.handlers[1] ch = _logger.handlers[2] assert fh.formatter._fmt == fmt assert fh.formatter.datefmt == datefmt assert ch.formatter._fmt == fmt assert ch.formatter.datefmt == datefmt
def test_run_jtagboot(board, test): test_dict = osl_tests.get_test_params(test) machine = test_dict["machine"] variant = get_variant(machine) board = board( test_name=test_dict["test"], params=[variant, machine], machine=machine, ) setup_logger(board.config.logDir, console_level=logging.DEBUG) config = board.config images_dir = config["deployDir"] jtag_boot(board.serial, board.xsdb, config, images_dir, variant) linux_login_cons(board.serial, user="******", password="******", login=True, timeout=300)
def test_setup_logger_default(tmpdir, teardown): log_dirname = os.path.join(tmpdir, "log") _logger = setup_logger(log_dirname) assert os.path.isfile(os.path.join(log_dirname, "20200801-123456.log")) fh = _logger.handlers[1] ch = _logger.handlers[2] assert fh.level == logging.DEBUG assert ch.level == logging.INFO formatter = logging.Formatter() assert fh.formatter._fmt == formatter._fmt assert fh.formatter.datefmt == formatter.datefmt assert ch.formatter._fmt == formatter._fmt assert ch.formatter.datefmt == formatter.datefmt
def test_setup_logger_fmt(tmpdir, teardown): console_fmt = {"fmt": "%(levelname)s - %(message)s", "datefmt": "%Y-%m-%d"} file_fmt = { "fmt": "{levelname} - {message}", "datefmt": "%Y-%m", "style": "{" } log_dirname = os.path.join(tmpdir, "log") _logger = setup_logger(log_dirname, console_fmt=console_fmt, file_fmt=file_fmt) fh = _logger.handlers[1] ch = _logger.handlers[2] assert fh.formatter._fmt == file_fmt["fmt"] assert fh.formatter.datefmt == file_fmt["datefmt"] assert ch.formatter._fmt == console_fmt["fmt"] assert ch.formatter.datefmt == console_fmt["datefmt"]
def test_setup_logger_dirname(tmpdir): log_dirname = os.path.join(tmpdir, "log") log_filename = "sometestfile.log" setup_logger(log_dirname, log_filename) teardown_logger() assert os.path.isfile(os.path.join(log_dirname, log_filename))