Browse Source

Merge disable_logging and logging_reduced

pull/179/head
Oliverpool 9 years ago
parent
commit
1a54b29233
  1. 13
      patacrep/utils.py
  2. 19
      test/__init__.py
  3. 2
      test/test_content/test_content.py
  4. 4
      test/test_song/test_parser.py

13
patacrep/utils.py

@ -1,8 +1,5 @@
"""Some utility functions"""
import contextlib
import logging
from collections import UserDict
class DictOfDict(UserDict):
@ -78,13 +75,3 @@ def yesno(string):
string,
", ".join(["'{}'".format(string) for string in yes_strings + no_strings]),
))
@contextlib.contextmanager
def logging_reduced(module_name, tmp_level=logging.CRITICAL):
"""Temporarly reduce the logging level of a specific module
"""
logger = logging.getLogger(module_name)
old_level = logger.getEffectiveLevel()
logger.setLevel(tmp_level)
yield
logger.setLevel(old_level)

19
test/__init__.py

@ -9,11 +9,20 @@ import unittest
import patacrep
@contextlib.contextmanager
def disable_logging():
"""Context locally disabling logging."""
logging.disable(logging.CRITICAL)
yield
logging.disable(logging.NOTSET)
def logging_reduced(module_name=None, tmp_level=logging.CRITICAL):
"""Temporarly reduce the logging level of a specific module
or globally if None
"""
if module_name:
logger = logging.getLogger(module_name)
old_level = logger.getEffectiveLevel()
logger.setLevel(tmp_level)
yield
logger.setLevel(old_level)
else:
logging.disable(logging.CRITICAL)
yield
logging.disable(logging.NOTSET)
def suite():
"""Return a :class:`TestSuite` object, testing all module :mod:`patacrep`.

2
test/test_content/test_content.py

@ -10,8 +10,8 @@ import json
from patacrep.songs import DataSubpath, DEFAULT_CONFIG
from patacrep import content, files
from patacrep.content import song, section, songsection, tex
from patacrep.utils import logging_reduced
from .. import logging_reduced
from .. import dynamic # pylint: disable=unused-import
class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):

4
test/test_song/test_parser.py

@ -12,7 +12,7 @@ from patacrep import files
from patacrep.songs import DEFAULT_CONFIG
from patacrep.encoding import open_read
from .. import disable_logging
from .. import logging_reduced
from .. import dynamic # pylint: disable=unused-import
OUTPUTS = {
@ -59,7 +59,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
destname = "{}.{}".format(base, out_format)
with self.chdir():
with open_read(destname) as expectfile:
with disable_logging():
with logging_reduced():
song = self.song_plugins[out_format][in_format](sourcename, self.config)
expected = expectfile.read().strip().replace(
"@TEST_FOLDER@",

Loading…
Cancel
Save