From af1e44a0d29c7b2e9c1aaeab96bc791cf6c5c6d2 Mon Sep 17 00:00:00 2001 From: Luna Chen Date: Wed, 18 Apr 2018 16:15:21 +0100 Subject: [PATCH] minor change in utils.py - strip_blank_recursive --- .gitignore | 1 - docs/guide/quickstart.rst | 2 +- logme/utils.py | 8 ++++---- tests/dummy_stubs.py | 9 +++++++++ tests/logme.ini | 10 ++++++++++ tests/test_log.py | 13 ++++++++++++- tests/test_utils.py | 1 + 7 files changed, 37 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index e0cdbbe..2e475a6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ logme.egg-info/ *.egg __pycache__ tests/__pycache__ -tests/test_real.py build/ cover/ diff --git a/docs/guide/quickstart.rst b/docs/guide/quickstart.rst index dc51717..c52d9a6 100644 --- a/docs/guide/quickstart.rst +++ b/docs/guide/quickstart.rst @@ -140,7 +140,7 @@ without having to configure each logger manually in your code. * **scope**: the scope of your logger: *class*, *function* or *module*. You can omit this parameter for class and function. **this is required for module level logger** * **config**: the name of logging config specified in logme.ini, default would be the *logme* config - * **name**: the name of the logger, default would be the __name__ of the file where you are calling logme.ini + * **name**: the name of the logger, default would be the __name__ of the file where you are calling logme.log, or using the logme.log decorator. diff --git a/logme/utils.py b/logme/utils.py index c8908bd..6b52e4d 100644 --- a/logme/utils.py +++ b/logme/utils.py @@ -10,9 +10,9 @@ def conf_to_dict(conf_section: List[tuple]) -> dict: """ - Converting the config section to a dictionary format + Converting the Configparser section to a dictionary format - :param conf_section: values from config.items('section') + :param conf_section: values from config.items('section') or config['section'] """ return {i[0]: conf_item_to_dict(i[1]) if '\n' in i[1] else i[1] @@ -76,9 +76,9 @@ def strip_blank_recursive(nested_list: list): if isinstance(v, list): strip_blank_recursive(v) elif isinstance(v, str): - if v.strip() in ['True', 'False', 'None']: + try: val_ = ast.literal_eval(v.strip()) - else: + except (ValueError, SyntaxError): val_ = v.strip() nested_list[i] = val_ diff --git a/tests/dummy_stubs.py b/tests/dummy_stubs.py index 1fe7f0a..d5805c6 100644 --- a/tests/dummy_stubs.py +++ b/tests/dummy_stubs.py @@ -45,3 +45,12 @@ def method_with_args(self, name, age, logger=None, **kwargs): def log_this(): module_logger.info('change my config.') return module_logger + + +@logme.log +def dummy_func_change_level(logger=None): + import logging + logger.master_level = logging.ERROR + logger.info('blah') + + return logger diff --git a/tests/logme.ini b/tests/logme.ini index 2bd2318..8b8e2cc 100644 --- a/tests/logme.ini +++ b/tests/logme.ini @@ -71,3 +71,13 @@ NullHandler = active: False level: NOTSET +[error_config] +level = ERROR +formatter = {name} :: {levelname} :: {message} +StreamHandler = + active: False + level: DEBUG +NullHandler = + active: False + level: NOTSET + diff --git a/tests/test_log.py b/tests/test_log.py index 7bff9f2..a05155b 100644 --- a/tests/test_log.py +++ b/tests/test_log.py @@ -62,7 +62,6 @@ def test_module_logger(caplog, scope): def test_class_with_method(caplog): obj = DummyClassWithMethods() - obj.method_one() assert caplog.record_tuples[0] == ('class_with_methods', 10, 'test class with method logging message.') @@ -91,6 +90,16 @@ def test_change_logging_config(file_config_content): assert file.readline() == "change_config::change my config.\n" +def test_change_logging_master_level(capsys): + logger = dummy_func_change_level() + + assert logger.level == 40 + + out, err = capsys.readouterr() + assert not out + assert not err + + # --------------------------------------------------------------------------- # Tests for others, _get_logger_decorator() # --------------------------------------------------------------------------- @@ -98,3 +107,5 @@ def test_get_logger_decorator_raise(): with pytest.raises(LogmeError) as e_info: _get_logger_decorator('hello') + + diff --git a/tests/test_utils.py b/tests/test_utils.py index 2f291fb..db69cb9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -9,6 +9,7 @@ class TestPackageUtils: + @classmethod def setup(cls):