-
-
Notifications
You must be signed in to change notification settings - Fork 86
/
test_progress_indicator.py
103 lines (82 loc) · 2.65 KB
/
test_progress_indicator.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: utf-8 -*-
import time
import os
from io import BytesIO
from cleo.outputs.stream_output import StreamOutput
from cleo._compat import decode
from cleo.helpers.progress_indicator import ProgressIndicator
from .. import CleoTestCase
class ProgressIndicatorTestCase(CleoTestCase):
def test_default_indicator(self):
output = self.get_output_stream()
bar = ProgressIndicator(output)
bar.start('Starting...')
time.sleep(0.101)
bar.advance()
time.sleep(0.101)
bar.advance()
time.sleep(0.101)
bar.advance()
time.sleep(0.101)
bar.advance()
time.sleep(0.101)
bar.advance()
time.sleep(0.101)
bar.set_message('Advancing...')
bar.advance()
bar.finish('Done...')
bar.start('Starting Again...')
time.sleep(0.101)
bar.advance()
bar.finish('Done Again...')
bar.start('Starting Again...')
time.sleep(0.101)
bar.advance()
bar.finish('Done Again...', reset_indicator=True)
expected = self.generate_output([
' - Starting...',
' \\ Starting...',
' | Starting...',
' / Starting...',
' - Starting...',
' \\ Starting...',
' \\ Advancing...',
' | Advancing...',
' | Done...'
])
expected += os.linesep
expected += self.generate_output([
' - Starting Again...',
' \\ Starting Again...',
' \\ Done Again...'
])
expected += os.linesep
expected += self.generate_output([
' - Starting Again...',
' \\ Starting Again...',
' - Done Again...'
])
expected += os.linesep
self.assertEqual(
expected,
self.get_output_content(output)
)
def get_output_stream(self, decorated=True, verbosity=StreamOutput.VERBOSITY_NORMAL):
stream = BytesIO()
return StreamOutput(stream, decorated=decorated, verbosity=verbosity)
def generate_output(self, expected):
if isinstance(expected, list):
expected_out = ''
for exp in expected:
expected_out += self.generate_output(exp)
else:
count = expected.count('\n')
expected_out = '\x0D\x1B[2K'
if count:
expected_out += '\033[%dA' % count
expected_out += expected
return decode(expected_out)
def get_output_content(self, output):
output.get_stream().seek(0)
value = output.get_stream().getvalue()
return decode(value)