Skip to content

Commit

Permalink
minor change in utils.py - strip_blank_recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
BNMetrics committed Apr 18, 2018
1 parent 586b720 commit af1e44a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 7 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ logme.egg-info/
*.egg
__pycache__
tests/__pycache__
tests/test_real.py

build/
cover/
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.



Expand Down
8 changes: 4 additions & 4 deletions logme/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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_
Expand Down
9 changes: 9 additions & 0 deletions tests/dummy_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions tests/logme.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

13 changes: 12 additions & 1 deletion tests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down Expand Up @@ -91,10 +90,22 @@ 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()
# ---------------------------------------------------------------------------
def test_get_logger_decorator_raise():
with pytest.raises(LogmeError) as e_info:
_get_logger_decorator('hello')



1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class TestPackageUtils:


@classmethod
def setup(cls):

Expand Down

0 comments on commit af1e44a

Please sign in to comment.