This commit is contained in:
Edwin Eefting 2021-04-13 16:32:43 +02:00
parent 4b97f789df
commit f9719ba87e
2 changed files with 56 additions and 2 deletions

54
tests/test_log.py Normal file
View File

@ -0,0 +1,54 @@
import zfs_autobackup.LogConsole
from basetest import *
class TestLog(unittest2.TestCase):
def test_colored(self):
"""test with color output"""
with OutputIO() as buf:
with redirect_stdout(buf):
l=LogConsole(show_verbose=False, show_debug=False)
l.verbose("verbose")
l.debug("debug")
with redirect_stdout(buf):
l=LogConsole(show_verbose=True, show_debug=True)
l.verbose("verbose")
l.debug("debug")
with redirect_stderr(buf):
l=LogConsole()
l.error("error")
print(list(buf.getvalue()))
self.assertEqual(list(buf.getvalue()), ['\x1b', '[', '2', '2', 'm', ' ', ' ', 'v', 'e', 'r', 'b', 'o', 's', 'e', '\x1b', '[', '0', 'm', '\n', '\x1b', '[', '3', '2', 'm', '#', ' ', 'd', 'e', 'b', 'u', 'g', '\x1b', '[', '0', 'm', '\n', '\x1b', '[', '3', '1', 'm', '\x1b', '[', '1', 'm', '!', ' ', 'e', 'r', 'r', 'o', 'r', '\x1b', '[', '0', 'm', '\n'])
def test_nocolor(self):
"""test without color output"""
zfs_autobackup.LogConsole.colorama=False
with OutputIO() as buf:
with redirect_stdout(buf):
l=LogConsole(show_verbose=False, show_debug=False)
l.verbose("verbose")
l.debug("debug")
with redirect_stdout(buf):
l=LogConsole(show_verbose=True, show_debug=True)
l.verbose("verbose")
l.debug("debug")
with redirect_stderr(buf):
l=LogConsole()
l.error("error")
print(list(buf.getvalue()))
self.assertEqual(list(buf.getvalue()), [' ', ' ', 'v', 'e', 'r', 'b', 'o', 's', 'e', '\n', '#', ' ', 'd', 'e', 'b', 'u', 'g', '\n', '!', ' ', 'e', 'r', 'r', 'o', 'r', '\n'])
zfs_autobackup.LogConsole.colorama=False

View File

@ -138,5 +138,5 @@ class TestThinner(unittest2.TestCase):
self.assertEqual(result, ok)
if __name__ == '__main__':
unittest.main()
# if __name__ == '__main__':
# unittest.main()