mirror of https://github.com/tqdm/tqdm.git
tests fix
This commit is contained in:
parent
53206c3614
commit
ab59217391
2
tox.ini
2
tox.ini
|
@ -13,6 +13,7 @@ deps =
|
|||
nose-timer
|
||||
coverage<4
|
||||
coveralls
|
||||
docopt
|
||||
commands =
|
||||
nosetests --with-coverage --with-timer --cover-package=tqdm --ignore-files="tests_perf\.py" -d -v tqdm/
|
||||
coveralls
|
||||
|
@ -37,5 +38,6 @@ commands =
|
|||
deps =
|
||||
nose
|
||||
nose-timer
|
||||
docopt
|
||||
commands =
|
||||
nosetests --with-timer tqdm/tests/tests_perf.py -d -v
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
import sys
|
||||
import subprocess
|
||||
from tqdm import main
|
||||
from docopt import DocoptExit
|
||||
from copy import deepcopy
|
||||
|
||||
from tests_tqdm import with_setup, pretest, posttest, _range
|
||||
|
||||
|
||||
# WARNING: this should be the last test as it messes with sys.stdin, argv
|
||||
@with_setup(pretest, posttest)
|
||||
def test_main():
|
||||
""" Test command line pipes """
|
||||
ls_out = subprocess.Popen(('ls'), stdout=subprocess.PIPE).communicate()[0]
|
||||
ls = subprocess.Popen(('ls'), stdout=subprocess.PIPE)
|
||||
res = subprocess.Popen(('python', '-c', 'from tqdm import main; main()'),
|
||||
stdout=subprocess.PIPE,
|
||||
stdin=ls.stdout,
|
||||
stderr=subprocess.STDOUT).communicate()[0]
|
||||
ls.wait()
|
||||
|
||||
# actual test:
|
||||
|
||||
assert (ls_out in res)
|
||||
|
||||
# semi-fake test which gets coverage:
|
||||
try:
|
||||
_SYS = (deepcopy(sys.stdin), deepcopy(sys.argv))
|
||||
except:
|
||||
pass
|
||||
|
||||
sys.stdin = map(str, _range(int(1e3)))
|
||||
sys.argv = ['', '--desc', 'Test command line pipes',
|
||||
'--ascii', 'True', '--unit_scale', 'True']
|
||||
main()
|
||||
|
||||
sys.argv = ['', '--bad', 'arg',
|
||||
'--ascii', 'True', '--unit_scale', 'True']
|
||||
try:
|
||||
main()
|
||||
except DocoptExit as e:
|
||||
if """Usage:
|
||||
tqdm [--help | options]""" not in str(e):
|
||||
raise
|
||||
|
||||
try:
|
||||
sys.stdin, sys.argv = _SYS
|
||||
except:
|
||||
pass
|
|
@ -306,8 +306,8 @@ def test_max_interval():
|
|||
cpu_timify(t, timer)
|
||||
|
||||
# without maxinterval
|
||||
t2 = tqdm(total=total, file=our_file2, miniters=None, mininterval=0,
|
||||
smoothing=1, maxinterval=None)
|
||||
t2 = tqdm(total=total, file=our_file2, miniters=None,
|
||||
mininterval=0, smoothing=1, maxinterval=None)
|
||||
cpu_timify(t2, timer)
|
||||
|
||||
assert t.dynamic_miniters
|
||||
|
@ -1029,36 +1029,3 @@ def test_repr():
|
|||
with closing(StringIO()) as our_file:
|
||||
with tqdm(total=10, ascii=True, file=our_file) as t:
|
||||
assert str(t) == ' 0%| | 0/10 [00:00<?, ?it/s]'
|
||||
|
||||
|
||||
# WARNING: this should be the last test as it messes with sys.stdin, argv
|
||||
@with_setup(pretest, posttest)
|
||||
def test_main():
|
||||
""" Test command line pipes """
|
||||
import subprocess
|
||||
from tqdm import main
|
||||
from docopt import DocoptExit
|
||||
|
||||
ls_out = subprocess.check_output(('ls'))
|
||||
ls = subprocess.Popen(('ls'), stdout=subprocess.PIPE)
|
||||
res = subprocess.check_output(('python', '-m', 'tqdm'),
|
||||
stdin=ls.stdout,
|
||||
stderr=subprocess.STDOUT)
|
||||
ls.wait()
|
||||
assert (ls_out in res)
|
||||
|
||||
# _sys = (sys.stdin, sys.argv)
|
||||
sys.stdin = map(str, _range(int(1e3)))
|
||||
sys.argv = ['', '--desc', 'Test command line pipes',
|
||||
'--ascii', 'True', '--unit_scale', 'True']
|
||||
main()
|
||||
|
||||
sys.argv = ['', '--bad', 'arg',
|
||||
'--ascii', 'True', '--unit_scale', 'True']
|
||||
try:
|
||||
main()
|
||||
except DocoptExit as e:
|
||||
if """Usage:
|
||||
tqdm [--help | options]""" not in str(e):
|
||||
raise
|
||||
# sys.stdin, sys.argv = _sys
|
||||
|
|
Loading…
Reference in New Issue