File: test_log.py

package info (click to toggle)
zfs-autobackup 3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 616 kB
  • sloc: python: 5,044; sh: 94; makefile: 3
file content (52 lines) | stat: -rw-r--r-- 2,053 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from zfs_autobackup.LogConsole import 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, color=True)
                l.verbose("verbose")
                l.debug("debug")

            with redirect_stdout(buf):
                l=LogConsole(show_verbose=True, show_debug=True, color=True)
                l.verbose("verbose")
                l.debug("debug")

            with redirect_stderr(buf):
                l=LogConsole(show_verbose=False, show_debug=False, color=True)
                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"""

        with OutputIO() as buf:
            with redirect_stdout(buf):
                l=LogConsole(show_verbose=False, show_debug=False, color=False)
                l.verbose("verbose")
                l.debug("debug")

            with redirect_stdout(buf):
                l=LogConsole(show_verbose=True, show_debug=True, color=False)
                l.verbose("verbose")
                l.debug("debug")

            with redirect_stderr(buf):
                l=LogConsole(show_verbose=False, show_debug=False, color=False)
                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