moved test_customLogger.py

This commit is contained in:
Lex Berezhny 2018-07-25 01:49:14 -04:00 committed by Jack Robison
parent a937aff80f
commit 855fd8bf9a
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -1,16 +1,16 @@
from io import StringIO import StringIO
import logging import logging
import mock import mock
from unittest import skipIf import unittest
from twisted.internet import defer from twisted.internet import defer
from twisted.trial import unittest from twisted import trial
from lbrynet.core import log_support from lbrynet import custom_logger
from tests.util import is_android from lbrynet.tests.util import is_android
class TestLogger(unittest.TestCase): class TestLogger(trial.unittest.TestCase):
def raiseError(self): def raiseError(self):
raise Exception('terrible things happened') raise Exception('terrible things happened')
@ -22,27 +22,27 @@ class TestLogger(unittest.TestCase):
return d return d
def setUp(self): def setUp(self):
self.log = log_support.Logger('test') self.log = custom_logger.Logger('test')
self.stream = StringIO() self.stream = StringIO.StringIO()
handler = logging.StreamHandler(self.stream) handler = logging.StreamHandler(self.stream)
handler.setFormatter(logging.Formatter("%(filename)s:%(lineno)d - %(message)s")) handler.setFormatter(logging.Formatter("%(filename)s:%(lineno)d - %(message)s"))
self.log.addHandler(handler) self.log.addHandler(handler)
@skipIf(is_android(), @unittest.skipIf(is_android(),
'Test cannot pass on Android because the tests package is compiled ' 'Test cannot pass on Android because the tests package is compiled '
'which results in a different method call stack') 'which results in a different method call stack')
def test_can_log_failure(self): def test_can_log_failure(self):
def output_lines(): def output_lines():
return self.stream.getvalue().split('\n') return self.stream.getvalue().split('\n')
# the line number could change if this file gets refactored # the line number could change if this file gets refactored
expected_first_line = 'test_log_support.py:20 - My message: terrible things happened' expected_first_line = 'test_customLogger.py:20 - My message: terrible things happened'
# testing the entirety of the message is futile as the # testing the entirety of the message is futile as the
# traceback will depend on the system the test is being run on # traceback will depend on the system the test is being run on
# but hopefully these two tests are good enough # but hopefully these two tests are good enough
d = self.triggerErrback() d = self.triggerErrback()
d.addCallback(lambda _: self.assertEqual(expected_first_line, output_lines()[0])) d.addCallback(lambda _: self.assertEquals(expected_first_line, output_lines()[0]))
d.addCallback(lambda _: self.assertEqual(10, len(output_lines()))) d.addCallback(lambda _: self.assertEqual(10, len(output_lines())))
return d return d