Skip to content

Commit

Permalink
tidy, flake8, fix tox
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Feb 10, 2019
1 parent a7718b4 commit d9da314
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tqdm/_tqdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
30 changes: 7 additions & 23 deletions tqdm/tests/tests_tqdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit d9da314

Please sign in to comment.