-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_terminal.py
More file actions
188 lines (141 loc) · 4.29 KB
/
test_terminal.py
File metadata and controls
188 lines (141 loc) · 4.29 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import signal
import sys
import time
from datetime import timedelta
import progressbar
from progressbar import terminal
def test_left_justify():
'''Left justify using the terminal width'''
p = progressbar.ProgressBar(
widgets=[progressbar.BouncingBar(marker=progressbar.RotatingMarker())],
max_value=100,
term_width=20,
left_justify=True,
)
assert p.term_width is not None
for i in range(100):
p.update(i)
def test_right_justify():
'''Right justify using the terminal width'''
p = progressbar.ProgressBar(
widgets=[progressbar.BouncingBar(marker=progressbar.RotatingMarker())],
max_value=100,
term_width=20,
left_justify=False,
)
assert p.term_width is not None
for i in range(100):
p.update(i)
def test_auto_width(monkeypatch):
'''Right justify using the terminal width'''
def ioctl(*args):
return '\xbf\x00\xeb\x00\x00\x00\x00\x00'
def fake_signal(signal, func):
pass
try:
import fcntl
monkeypatch.setattr(fcntl, 'ioctl', ioctl)
monkeypatch.setattr(signal, 'signal', fake_signal)
p = progressbar.ProgressBar(
widgets=[
progressbar.BouncingBar(marker=progressbar.RotatingMarker()),
],
max_value=100,
left_justify=True,
term_width=None,
)
assert p.term_width is not None
for i in range(100):
p.update(i)
except ImportError:
pass # Skip on Windows
def test_fill_right():
'''Right justify using the terminal width'''
p = progressbar.ProgressBar(
widgets=[progressbar.BouncingBar(fill_left=False)],
max_value=100,
term_width=20,
)
assert p.term_width is not None
for i in range(100):
p.update(i)
def test_fill_left():
'''Right justify using the terminal width'''
p = progressbar.ProgressBar(
widgets=[progressbar.BouncingBar(fill_left=True)],
max_value=100,
term_width=20,
)
assert p.term_width is not None
for i in range(100):
p.update(i)
def test_no_fill(monkeypatch):
'''Simply bounce within the terminal width'''
bar = progressbar.BouncingBar()
bar.INTERVAL = timedelta(seconds=1)
p = progressbar.ProgressBar(
widgets=[bar],
max_value=progressbar.UnknownLength,
term_width=20,
)
assert p.term_width is not None
for i in range(30):
p.update(i, force=True)
# Fake the start time so we can actually emulate a moving progress bar
p.start_time = p.start_time - timedelta(seconds=i)
def test_stdout_redirection():
p = progressbar.ProgressBar(
fd=sys.stdout,
max_value=10,
redirect_stdout=True,
)
for i in range(10):
print('', file=sys.stdout)
p.update(i)
def test_double_stdout_redirection():
p = progressbar.ProgressBar(max_value=10, redirect_stdout=True)
p2 = progressbar.ProgressBar(max_value=10, redirect_stdout=True)
for i in range(10):
print('', file=sys.stdout)
p.update(i)
p2.update(i)
def test_stderr_redirection():
p = progressbar.ProgressBar(max_value=10, redirect_stderr=True)
for i in range(10):
print('', file=sys.stderr)
p.update(i)
def test_stdout_stderr_redirection():
p = progressbar.ProgressBar(
max_value=10,
redirect_stdout=True,
redirect_stderr=True,
)
p.start()
for i in range(10):
time.sleep(0.01)
print('', file=sys.stdout)
print('', file=sys.stderr)
p.update(i)
p.finish()
def test_resize(monkeypatch):
def ioctl(*args):
return '\xbf\x00\xeb\x00\x00\x00\x00\x00'
def fake_signal(signal, func):
pass
try:
import fcntl
monkeypatch.setattr(fcntl, 'ioctl', ioctl)
monkeypatch.setattr(signal, 'signal', fake_signal)
p = progressbar.ProgressBar(max_value=10)
p.start()
for i in range(10):
p.update(i)
p._handle_resize()
p.finish()
except ImportError:
pass # Skip on Windows
def test_base():
assert str(terminal.CUP)
assert str(terminal.CLEAR_SCREEN_ALL_AND_HISTORY)
terminal.clear_line(0)
terminal.clear_line(1)