def test_reconfig_handler(self, file_config_content): log_file = file_config_content['FileHandler']['filename'] color_config = get_color_config(__file__) logger = LogmeLogger('reconfig_handler_test', file_config_content, color_config=color_config) # Check original level assert list(logger.handlers.values()) == logger.logger.handlers assert logger.handlers['StreamHandler'].level == 10 assert logger.handlers['FileHandler'].level == 10 logger.debug('hello, there') lines_before = self.get_log_file_lines(log_file) # Reconfigure and check current level logger.reconfig_handler('FileHandler', level=50) assert list(logger.handlers.values()) == logger.logger.handlers assert logger.handlers['StreamHandler'].level == 10 assert logger.handlers['FileHandler'].level == 50 logger.info('hello') lines_after = self.get_log_file_lines(log_file) assert lines_before == lines_after
def logger_from_provider(): config = get_logger_config(__file__) color_conf = get_color_config(__file__) logger = LogmeLogger(name='test_logger', config=config, color_config=color_conf) yield logger del logging.Logger.manager.loggerDict['test_logger']
def test_get_color_config(): expected = { 'CRITICAL': {'bg': 'red', 'color': 'white', 'style': 'Bold'}, 'ERROR': 'PURPLE', 'WARNING': 'YELLOW', 'INFO': 'GREEN', 'DEBUG': 'WHITE' } color_conf = get_color_config(__file__) assert expected == color_conf
def test_color_config_none_exist(tmpdir): """ Ensure color config returns None if none existent """ logme_file = tmpdir.join('logme.ini') logger_conifg = get_logger_config(__file__) config_dict = {'logme': logger_conifg} config = ConfigParser.from_dict(config_dict) with open(logme_file, 'w') as file: config.write(file) color_config = get_color_config(logme_file) assert color_config is None
import pytest import logging from logme.color_provider import Color, ColorFormatter from logme.utils import get_color_config, get_config_content from logme.exceptions import InvalidColorConfig COLOR_CONFIG = get_color_config(__file__) NULL_COLOR_CONFIG = get_config_content(__file__, 'colors_null') @pytest.mark.parametrize('parse_args, result, text_style', [ pytest.param({'color': 'red'}, "\033[0;31m", {'color': '31'}, id='With color only, no style passed in'), pytest.param({ 'color': 'Blue', 'style': 'BOLD' }, "\033[0;1;34m", { 'color': '34', 'style': '1' }, id='With both color and style passed in, and cap on values'), pytest.param({'style': 'bold'}, "\033[0;1m", {'style': '1'}, id='With only style passed in'), pytest.param({ 'color': 'purple', 'style': 'underline',