safety and warning suppression

This commit is contained in:
Casper da Costa-Luis 2016-10-22 14:17:52 +01:00
parent bde013b1da
commit 929a4fdacf
4 changed files with 6 additions and 13 deletions

View File

@ -1,7 +1,7 @@
# How to import tqdm without enforcing it as a dependency # How to import tqdm without enforcing it as a dependency
try: try:
from tqdm import tqdm from tqdm import tqdm
except: except ImportError:
def tqdm(*args, **kwargs): def tqdm(*args, **kwargs):
if args: if args:
return args[0] return args[0]

View File

@ -215,7 +215,7 @@ class tqdm_notebook(tqdm):
else: else:
self.sp(close=True) self.sp(close=True)
def moveto(*args, **kwargs): def moveto(self, *args, **kwargs):
# void -> avoid extraneous `\n` in IPython output cell # void -> avoid extraneous `\n` in IPython output cell
return return

View File

@ -1,7 +1,6 @@
import sys import sys
import subprocess import subprocess
from tqdm import main, TqdmKeyError, TqdmTypeError from tqdm import main, TqdmKeyError, TqdmTypeError
from copy import deepcopy
from tests_tqdm import with_setup, pretest, posttest, _range, closing, UnicodeIO from tests_tqdm import with_setup, pretest, posttest, _range, closing, UnicodeIO
@ -29,10 +28,7 @@ def test_main():
assert (ls_out in res.replace('\r\n', '\n')) assert (ls_out in res.replace('\r\n', '\n'))
# semi-fake test which gets coverage: # semi-fake test which gets coverage:
try: _SYS = sys.stdin, sys.argv
_SYS = (deepcopy(sys.stdin), deepcopy(sys.argv))
except:
pass
with closing(UnicodeIO()) as sys.stdin: with closing(UnicodeIO()) as sys.stdin:
sys.argv = ['', '--desc', 'Test CLI delims', sys.argv = ['', '--desc', 'Test CLI delims',
@ -85,7 +81,4 @@ def test_main():
pass pass
# clean up # clean up
try: sys.stdin, sys.argv = _SYS
sys.stdin, sys.argv = _SYS
except:
pass

View File

@ -16,7 +16,7 @@ from tqdm import TqdmDeprecationWarning
try: try:
from StringIO import StringIO from StringIO import StringIO
except: except ImportError:
from io import StringIO from io import StringIO
from io import IOBase # to support unicode strings from io import IOBase # to support unicode strings
@ -1119,7 +1119,7 @@ def test_clear():
@with_setup(pretest, posttest) @with_setup(pretest, posttest)
def test_clear(): def test_clear_disabled():
""" Test clearing bar display """ """ Test clearing bar display """
with closing(StringIO()) as our_file: with closing(StringIO()) as our_file:
with tqdm(total=10, file=our_file, desc='pos0 bar', disable=True, with tqdm(total=10, file=our_file, desc='pos0 bar', disable=True,