1
|
|
|
# pylint: disable=attribute-defined-outside-init |
2
|
|
|
|
3
|
|
|
from unittest.mock import Mock, call |
4
|
|
|
|
5
|
|
|
from gitman import common |
6
|
|
|
from gitman.common import _Config |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class TestShowConsole: |
10
|
|
|
|
11
|
|
|
def setup_method(self, _): |
12
|
|
|
_Config.indent_level = 0 |
13
|
|
|
_Config.verbosity = 0 |
14
|
|
|
self.file = Mock() |
15
|
|
|
|
16
|
|
|
def test_show(self): |
17
|
|
|
common.show("Hello, world!", file=self.file) |
18
|
|
|
|
19
|
|
|
assert [ |
20
|
|
|
call.write("Hello, world!"), |
21
|
|
|
call.write("\n"), |
22
|
|
|
] == self.file.mock_calls |
23
|
|
|
|
24
|
|
|
def test_show_after_indent(self): |
25
|
|
|
common.indent() |
26
|
|
|
common.show("|\n", file=self.file) |
27
|
|
|
|
28
|
|
|
assert [ |
29
|
|
|
call.write(" |\n"), |
30
|
|
|
call.write("\n"), |
31
|
|
|
] == self.file.mock_calls |
32
|
|
|
|
33
|
|
|
def test_show_after_1_indent_2_dedent(self): |
34
|
|
|
common.indent() |
35
|
|
|
common.dedent() |
36
|
|
|
common.dedent() |
37
|
|
|
common.show("|\n", file=self.file) |
38
|
|
|
|
39
|
|
|
assert [ |
40
|
|
|
call.write("|\n"), |
41
|
|
|
call.write("\n"), |
42
|
|
|
] == self.file.mock_calls |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
class TestShowLog: |
46
|
|
|
|
47
|
|
|
def setup_method(self, _): |
48
|
|
|
_Config.indent_level = 0 |
49
|
|
|
_Config.verbosity = 1 |
50
|
|
|
self.log = Mock() |
51
|
|
|
|
52
|
|
|
def test_show(self): |
53
|
|
|
common.show("Hello, world!", log=self.log) |
54
|
|
|
|
55
|
|
|
assert [ |
56
|
|
|
call.info("Hello, world!"), |
57
|
|
|
] == self.log.mock_calls |
58
|
|
|
|
59
|
|
|
def test_show_after_indent(self): |
60
|
|
|
common.indent() |
61
|
|
|
common.show("|\n", log=self.log) |
62
|
|
|
|
63
|
|
|
assert [ |
64
|
|
|
call.info("|"), |
65
|
|
|
] == self.log.mock_calls |
66
|
|
|
|
67
|
|
|
def test_show_after_1_indent_2_dedent(self): |
68
|
|
|
common.indent() |
69
|
|
|
common.dedent() |
70
|
|
|
common.dedent() |
71
|
|
|
common.show("|\n", log=self.log) |
72
|
|
|
|
73
|
|
|
assert [ |
74
|
|
|
call.info("|"), |
75
|
|
|
] == self.log.mock_calls |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
class TestShowQuiet: |
79
|
|
|
|
80
|
|
|
def setup_method(self, _): |
81
|
|
|
_Config.indent_level = 0 |
82
|
|
|
_Config.verbosity = -1 |
83
|
|
|
self.file = Mock() |
84
|
|
|
self.log = Mock() |
85
|
|
|
|
86
|
|
|
def test_show(self): |
87
|
|
|
common.show("Hello, world!", file=self.file, log=self.log) |
88
|
|
|
|
89
|
|
|
assert [] == self.file.mock_calls |
90
|
|
|
assert [] == self.log.mock_calls |
91
|
|
|
|