forked from wolph/python-progressbar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterminal.py
More file actions
128 lines (91 loc) · 3.13 KB
/
terminal.py
File metadata and controls
128 lines (91 loc) · 3.13 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
from __future__ import print_function
import sys
import signal
import progressbar
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_stdout_redirection():
p = progressbar.ProgressBar(max_value=10, redirect_stdout=True)
for i in range(10):
print('', file=sys.stdout)
p.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):
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