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.songs.chordpro import ChordproSong
from patacrep.test import disable_logging
class ParserTxtRenderer(unittest.TestCase):
"""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:
chordproname = "{}.sgc".format(self.basename)
self.assertMultiLineEqual(
ChordproSong(None, chordproname, config).render(
output=chordproname,
output_format="chordpro",
).strip(),
expectfile.read().replace(
"DIRNAME",
os.path.dirname(self.basename),
).strip(),
)
with disable_logging():
self.assertMultiLineEqual(
ChordproSong(None, chordproname, config).render(
output=chordproname,
output_format="chordpro",
).strip(),
expectfile.read().replace(
"DIRNAME",
os.path.dirname(self.basename),
).strip(),
)
def load_tests(__loader, tests, __pattern):
"""Load several tests given test files present in the directory."""

10
patacrep/test.py

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

Loading…
Cancel
Save