summaryrefslogtreecommitdiffstats
path: root/gitlint/tests/test_display.py
blob: f7cf765296d9356808ce324ca6c7943235bccada (plain)
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
53
54
try:
    # python 2.x
    from StringIO import StringIO
except ImportError:
    # python 3.x
    from io import StringIO

from mock import patch

from gitlint.display import Display
from gitlint.config import LintConfig
from gitlint.tests.base import BaseTestCase


class DisplayTests(BaseTestCase):
    def test_v(self):
        display = Display(LintConfig())
        display.config.verbosity = 2

        with patch('gitlint.display.stderr', new=StringIO()) as stderr:
            # Non exact outputting, should output both v and vv output
            with patch('gitlint.display.stdout', new=StringIO()) as stdout:
                display.v("test")
                display.vv("test2")
                self.assertEqual("test\ntest2\n", stdout.getvalue())

            # exact outputting, should only output v
            with patch('gitlint.display.stdout', new=StringIO()) as stdout:
                display.v("test", exact=True)
                display.vv("test2", exact=True)
                self.assertEqual("test2\n", stdout.getvalue())

            # standard error should be empty throughtout all of this
            self.assertEqual('', stderr.getvalue())

    def test_e(self):
        display = Display(LintConfig())
        display.config.verbosity = 2

        with patch('gitlint.display.stdout', new=StringIO()) as stdout:
            # Non exact outputting, should output both v and vv output
            with patch('gitlint.display.stderr', new=StringIO()) as stderr:
                display.e("test")
                display.ee("test2")
                self.assertEqual("test\ntest2\n", stderr.getvalue())

            # exact outputting, should only output v
            with patch('gitlint.display.stderr', new=StringIO()) as stderr:
                display.e("test", exact=True)
                display.ee("test2", exact=True)
                self.assertEqual("test2\n", stderr.getvalue())

            # standard error should be empty throughtout all of this
            self.assertEqual('', stdout.getvalue())