Browse Source

[test] Disabling logging during tests

pull/79/head
Louis 9 years ago
parent
commit
eb9c8618d8
  1. 23
      patacrep/songs/chordpro/test/test_parser.py
  2. 10
      patacrep/test.py

23
patacrep/songs/chordpro/test/test_parser.py

@ -8,6 +8,8 @@ import unittest
from patacrep.build import DEFAULT_CONFIG from patacrep.build import DEFAULT_CONFIG
from patacrep.songs.chordpro import ChordproSong from patacrep.songs.chordpro import ChordproSong
from patacrep.test import disable_logging
class ParserTxtRenderer(unittest.TestCase): class ParserTxtRenderer(unittest.TestCase):
"""Test parser, and renderer as a txt file.""" """Test parser, and renderer as a txt file."""
@ -34,16 +36,17 @@ class ParserTxtRenderer(unittest.TestCase):
}) })
with open("{}.txt".format(self.basename), 'r', encoding='utf8') as expectfile: with open("{}.txt".format(self.basename), 'r', encoding='utf8') as expectfile:
chordproname = "{}.sgc".format(self.basename) chordproname = "{}.sgc".format(self.basename)
self.assertMultiLineEqual( with disable_logging():
ChordproSong(None, chordproname, config).render( self.assertMultiLineEqual(
output=chordproname, ChordproSong(None, chordproname, config).render(
output_format="chordpro", output=chordproname,
).strip(), output_format="chordpro",
expectfile.read().replace( ).strip(),
"DIRNAME", expectfile.read().replace(
os.path.dirname(self.basename), "DIRNAME",
).strip(), os.path.dirname(self.basename),
) ).strip(),
)
def load_tests(__loader, tests, __pattern): def load_tests(__loader, tests, __pattern):
"""Load several tests given test files present in the directory.""" """Load several tests given test files present in the directory."""

10
patacrep/test.py

@ -1,11 +1,20 @@
"""Tests""" """Tests"""
import contextlib
import doctest import doctest
import logging
import os import os
import unittest import unittest
import patacrep import patacrep
@contextlib.contextmanager
def disable_logging():
"""Context locally disabling logging."""
logging.disable(logging.CRITICAL)
yield
logging.disable(logging.NOTSET)
def suite(): def suite():
"""Return a TestSuite object, to test whole `patacrep` package. """Return a TestSuite object, to test whole `patacrep` package.
@ -24,3 +33,4 @@ def load_tests(__loader, tests, __pattern):
if __name__ == "__main__": if __name__ == "__main__":
unittest.TextTestRunner().run(suite()) unittest.TextTestRunner().run(suite())

Loading…
Cancel
Save