How to use init_logger method in lisa

Best Python code snippet using lisa_python

test_logging.py

Source:test_logging.py Github

copy

Full Screen

...4from dfds_ds_toolbox.logging.logging import init_logger5@pytest.fixture6def default_logger():7 """Fixture. Call logger setup with WARNING level(default level)."""8 return init_logger()9@pytest.fixture10def info_logger():11 """Fixture. Call logger setup with INFO level."""12 return init_logger(stream_level="INFO")13@pytest.fixture14def debug_logger():15 """Fixture. Call logger setup with DEBUG level."""16 return init_logger(stream_level="DEBUG")17@pytest.fixture18def debug_file_info_logger(debug_file):19 """Fixture. Call info logger setup with debug file."""20 return init_logger(debug_file=debug_file, stream_level="INFO")21@pytest.fixture22def debug_file(tmp_path):23 """Fixture. Generate debug file location for tests."""24 return tmp_path.joinpath("pytest-plugin.log")25def test_instance_logger():26 """Test we can create instance of logger."""27 logger = init_logger()28 assert isinstance(logger, logging.Logger)29def test_instance_for_stream_levels():30 for stream_level in ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]:31 logger = init_logger(stream_level=stream_level)32 assert isinstance(logger, logging.Logger)33def test_debug_level(debug_logger):34 """Test the handle level is set to DEBUG"""35 [rich_handler] = [36 handler for handler in debug_logger.handlers if isinstance(handler, RichHandler)37 ]38 assert rich_handler.level == logging.DEBUG39 assert isinstance(rich_handler, RichHandler)40def test_info_level(info_logger):41 """Test the handle level is set to INFO"""42 [rich_handler] = [43 handler for handler in info_logger.handlers if isinstance(handler, RichHandler)44 ]45 assert rich_handler.level == logging.INFO46 assert isinstance(rich_handler, RichHandler)47def test_default_level(default_logger):48 """Test the handle level is set to WARNING (default value)"""49 [rich_handler] = [50 handler for handler in default_logger.handlers if isinstance(handler, RichHandler)51 ]52 assert rich_handler.level == logging.WARNING53 assert isinstance(rich_handler, RichHandler)54def test_debug_file_logging(debug_file_info_logger, debug_file):55 """Test that logging to stdout uses a different format and level than \56 the the file handler."""57 [file_handler, rich_handler] = [58 handler59 for handler in debug_file_info_logger.handlers60 if (isinstance(handler, RichHandler) or isinstance(handler, logging.FileHandler))61 ]62 assert isinstance(file_handler, logging.FileHandler)63 assert isinstance(rich_handler, RichHandler)64 assert rich_handler.level == logging.INFO65 assert file_handler.level == logging.DEBUG66 debug_file_info_logger.info("Text in log file.")67 assert debug_file.exists()68def test_unsupported_combination_rich_and_custom_log_format():69 """Test that we get KeyError when specifying a unsupported stream level"""70 with pytest.raises(ValueError):71 init_logger(stream_level="INF")72def test_wrong_combination_of_args():73 """Test that we get ValueError when specifying unsupported combination of args"""74 with pytest.raises(ValueError):75 init_logger(76 stream_level="INFO", rich_handler_enabled=True, log_format="%(module)s - %(message)s"77 )78def test_custom_format():79 """Test that we can use custom format logger"""80 custom_format_logger = init_logger(81 stream_level="DEBUG", log_format="%(module)s - %(message)s", rich_handler_enabled=False82 )83 assert isinstance(84 custom_format_logger, logging.Logger85 ), "Custom format logger could not be initialized"86def test_no_rich_handler():87 """Test that we can use logger without rich handler"""88 no_rich_logger = init_logger(stream_level="DEBUG", rich_handler_enabled=False)89 assert isinstance(90 no_rich_logger, logging.Logger91 ), "Logger without rich handler could not be initialized"92def test_info_level_no_rich_handler():93 """Test that the level is right for logger without rich handler"""94 no_rich_logger_info = init_logger(stream_level="INFO", rich_handler_enabled=False)95 assert (96 no_rich_logger_info.handlers[0].level == logging.INFO97 ), "Stream level of the handler is not INFO"98def test_default_level_no_rich_handler():99 """Test that the default level is right for logger without rich handler"""100 no_rich_logger_default = init_logger(rich_handler_enabled=False)101 assert (102 no_rich_logger_default.handlers[0].level == logging.WARNING...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

1import random2import math34import tensorflow as tf5import numpy as np6import logging78__author__ = "Jocelyn"91011def uniform_initializer_variable(width, shape, name=""):12 var = tf.Variable(tf.random_uniform(shape, -width, width), name=name)13 return var141516def truncated_normal_initializer_variable(width, shape, name=""):17 var = tf.Variable(tf.truncated_normal(shape=shape, stddev=1.0 / tf.sqrt(float(width))), name=name, dtype=tf.float32)18 return var192021def zero_initializer_variable(shape, name=""):22 var = tf.Variable(tf.zeros(shape=shape), name=name)23 return var242526def matrix_initializer(w, name=""):27 var = tf.Variable(w, name=name)28 return var293031def pre_logger(log_file_name, file_log_level=logging.DEBUG, screen_log_level=logging.INFO):32 """33 set log format34 :param log_file_name:35 :param file_log_level:36 :param screen_log_level:37 :return:38 """39 log_formatter = logging.Formatter(fmt='%(asctime)s [%(processName)s, %(process)s] [%(levelname)-5.5s] %(message)s',40 datefmt='%m-%d %H:%M')41 init_logger = logging.getLogger(log_file_name)42 init_logger.setLevel(logging.DEBUG)4344 # file handler45 file_handler = logging.FileHandler("log/{}.log".format(log_file_name))46 file_handler.setFormatter(log_formatter)47 file_handler.setLevel(file_log_level)4849 # screen handler50 screen_handler = logging.StreamHandler()51 screen_handler.setLevel(screen_log_level)5253 init_logger.addHandler(file_handler)54 init_logger.addHandler(screen_handler)55 return init_logger5657 ...

Full Screen

Full Screen

test_log.py

Source:test_log.py Github

copy

Full Screen

...3import pytest4from colorama import Fore, Style5from six import StringIO6from mozregression import log7def init_logger(mocker, **kwargs):8 stream = StringIO()9 kwargs["output"] = stream10 mocker.patch("mozregression.log.set_default_logger")11 return log.init_logger(**kwargs), stream12def test_logger_without_color(mocker):13 logger, stream = init_logger(mocker, allow_color=False)14 logger.error("argh")15 assert "ERROR: argh" in stream.getvalue()16def test_logger_with_color(mocker):17 logger, stream = init_logger(mocker, allow_color=True)18 logger.error("argh")19 assert re.search(".+ERROR.+: argh", stream.getvalue())20@pytest.mark.parametrize("debug", [False, True])21def test_logger_debug(mocker, debug):22 logger, stream = init_logger(mocker, allow_color=False, debug=debug)23 logger.info("info")24 logger.debug("debug")25 data = stream.getvalue()26 assert "info" in data27 if debug:28 assert "debug" in data29 else:30 assert "debug" not in data31def test_colorize():32 assert log.colorize("stuff", allow_color=True) == "stuff"33 assert log.colorize("{fRED}stuff{sRESET_ALL}", allow_color=True) == (34 Fore.RED + "stuff" + Style.RESET_ALL35 )36 assert log.colorize("{fRED}stuf{sRESET_ALL}", allow_color=False) == "stuf"

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful