From ab59217391a658fb460569c2c406db3743b4e8ca Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sun, 3 Apr 2016 22:03:10 +0100 Subject: [PATCH] tests fix --- tox.ini | 2 ++ tqdm/tests/tests_main.py | 49 ++++++++++++++++++++++++++++++++++++++++ tqdm/tests/tests_tqdm.py | 37 ++---------------------------- 3 files changed, 53 insertions(+), 35 deletions(-) create mode 100644 tqdm/tests/tests_main.py diff --git a/tox.ini b/tox.ini index fbd28a06..4e60867e 100644 --- a/tox.ini +++ b/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 diff --git a/tqdm/tests/tests_main.py b/tqdm/tests/tests_main.py new file mode 100644 index 00000000..eca77952 --- /dev/null +++ b/tqdm/tests/tests_main.py @@ -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 diff --git a/tqdm/tests/tests_tqdm.py b/tqdm/tests/tests_tqdm.py index 96522f23..3c1ac723 100644 --- a/tqdm/tests/tests_tqdm.py +++ b/tqdm/tests/tests_tqdm.py @@ -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