diff --git a/Makefile b/Makefile index 034310cf8..98b979a29 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ all: flake8: @+flake8 --max-line-length=80 --exclude .asv,.tox,.ipynb_checkpoints,build \ - -j 8 --count --statistics --exit-zero . + --ignore=W503,W504 -j 8 --count --statistics --exit-zero . test: tox --skip-missing-interpreters diff --git a/tox.ini b/tox.ini index fef7be2e3..e49b6d8ad 100644 --- a/tox.ini +++ b/tox.ini @@ -77,12 +77,14 @@ commands = [testenv:flake8] deps = flake8 commands = - flake8 --max-line-length=80 -j 8 --count --statistics --exit-zero . + flake8 --max-line-length=80 --exclude .asv,.tox,.ipynb_checkpoints,build \ + --ignore=W503,W504 -j 8 --count --statistics --exit-zero . [testenv:setup.py] deps = docutils pygments + py-make>=0.1.0 commands = python setup.py check --restructuredtext --metadata --strict python setup.py make none diff --git a/tqdm/_tqdm.py b/tqdm/_tqdm.py index 209baa4f9..614d86f5d 100755 --- a/tqdm/_tqdm.py +++ b/tqdm/_tqdm.py @@ -431,7 +431,7 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False, ascii = UTF_FMT nsyms = len(ascii) - 1 bar_length, frac_bar_length = divmod( - int(frac * N_BARS * nsyms), nsyms) + int(frac * N_BARS * nsyms), nsyms) bar = ascii[-1] * bar_length frac_bar = ascii[frac_bar_length] diff --git a/tqdm/tests/tests_tqdm.py b/tqdm/tests/tests_tqdm.py index 35c62a780..2aed9e719 100644 --- a/tqdm/tests/tests_tqdm.py +++ b/tqdm/tests/tests_tqdm.py @@ -74,11 +74,11 @@ def pos_line_diff(res_list, expected_list, raise_nonempty=True): elif ln > len(expected_list): res = [(r, None) for r in res_list[ln:]] res = [(r, e) for r, e in zip(res_list, expected_list) - for pos in [len(e)-len(e.lstrip('\n'))] # bar position + for pos in [len(e) - len(e.lstrip('\n'))] # bar position if not r.startswith(e) # start matches or not (r.endswith('\x1b[A' * pos) # move up at end or r == '\n') # final bar - or r[(-1-pos) * len('\x1b[A'):] == '\x1b[A'] # extra move up + or r[(-1 - pos) * len('\x1b[A'):] == '\x1b[A'] # extra move up if res and raise_nonempty: raise AssertionError( "Got => Expected\n" + '\n'.join('"%r" => "%r"' % i for i in res)) @@ -355,21 +355,9 @@ def test_native_string_io_for_default_file(): stderr = sys.stderr try: sys.stderr = WriteTypeChecker(expected_type=type('')) - for _ in tqdm(range(3)): pass - finally: - sys.stderr = stderr - - -@with_setup(pretest, posttest) -def test_native_string_io_for_default_file_with_encoding_none(): - """Native strings written to unspecified files""" - stderr = sys.stderr - try: - sys.stderr = WriteTypeChecker(expected_type=type('')) - sys.stderr.encoding = None - + sys.stderr.encoding = None # py2 behaviour for _ in tqdm(range(3)): pass finally: @@ -384,20 +372,16 @@ def test_unicode_string_io_for_specified_file(): @with_setup(pretest, posttest) -def test_byte_string_io_for_specified_file_with_forced_bytes(): - """Byte strings written to specified files when forced""" +def test_write_bytes(): + """Test write_bytes argument with and without `file`""" + # specified file (and bytes) for _ in tqdm(range(3), file=WriteTypeChecker(expected_type=type(b'')), write_bytes=True): pass - - -@with_setup(pretest, posttest) -def test_unicode_string_io_for_unspecified_file_with_forced_unicode(): - """Unicode strings written to unspecified file when forced""" + # unspecified file (and unicode) stderr = sys.stderr try: sys.stderr = WriteTypeChecker(expected_type=type(u'')) - for _ in tqdm(range(3), write_bytes=False): pass finally: