FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-progressbar/tests/test_windows.py at develop · commit-0/python-progressbar · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
commit-0
/
python-progressbar
Public
forked from
wolph/python-progressbar
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-progressbar
/
tests
/
test_windows.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
90 lines (71 loc) · 2.25 KB
Breadcrumbs
python-progressbar
/
tests
/
test_windows.py
Copy path
File metadata and controls
90 lines (71 loc) · 2.25 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
os
import
sys
import
time
import
pytest
if
os
.
name
==
'nt'
:
import
win32console
# "pip install pypiwin32" to get this
else
:
pytest
.
skip
(
'skipping windows-only tests'
,
allow_module_level
=
True
)
import
progressbar
pytest_plugins
=
'pytester'
_WIDGETS
=
[
progressbar
.
Percentage
(),
' '
,
progressbar
.
Bar
(),
' '
,
progressbar
.
FileTransferSpeed
(),
' '
,
progressbar
.
ETA
(),
]
_MB
:
int
=
1024
*
1024
# ---------------------------------------------------------------------------
def
scrape_console
(
line_count
):
pcsb
=
win32console
.
GetStdHandle
(
win32console
.
STD_OUTPUT_HANDLE
)
csbi
=
pcsb
.
GetConsoleScreenBufferInfo
()
col_max
=
csbi
[
'Size'
].
X
row_max
=
csbi
[
'CursorPosition'
].
Y
line_count
=
min
(
line_count
,
row_max
)
lines
=
[]
for
row
in
range
(
line_count
):
pct
=
win32console
.
PyCOORDType
(
0
,
row
+
row_max
-
line_count
)
line
=
pcsb
.
ReadConsoleOutputCharacter
(
col_max
,
pct
)
lines
.
append
(
line
.
rstrip
())
return
lines
# ---------------------------------------------------------------------------
def
runprogress
()
->
int
:
print
(
'***BEGIN***'
)
b
=
progressbar
.
ProgressBar
(
widgets
=
[
'example.m4v: '
,
*
_WIDGETS
],
max_value
=
10
*
_MB
,
)
for
i
in
range
(
10
):
b
.
update
((
i
+
1
)
*
_MB
)
time
.
sleep
(
0.25
)
b
.
finish
()
print
(
'***END***'
)
return
0
# ---------------------------------------------------------------------------
def
find
(
lines
,
x
):
try
:
return
lines
.
index
(
x
)
except
ValueError
:
return
-
sys
.
maxsize
# ---------------------------------------------------------------------------
def
test_windows
(
testdir
:
pytest
.
Testdir
)
->
None
:
testdir
.
run
(
sys
.
executable
,
'-c'
,
'import progressbar; print(progressbar.__file__)'
)
def
main
()
->
int
:
runprogress
()
scraped_lines
=
scrape_console
(
100
)
# reverse lines so we find the LAST instances of output.
scraped_lines
.
reverse
()
index_begin
=
find
(
scraped_lines
,
'***BEGIN***'
)
index_end
=
find
(
scraped_lines
,
'***END***'
)
if
index_end
+
2
!=
index_begin
:
print
(
'ERROR: Unexpected multi-line output from progressbar'
)
print
(
f'
{
index_begin
=
}
{
index_end
=
}
'
)
return
1
return
0
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL