Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Sep 27, 2020
1 parent c89b0fe commit 06fb6ec
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tqdm/tests/tests_tqdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from tqdm import tqdm
from tqdm import trange
from tqdm import TqdmDeprecationWarning
from tqdm import TqdmDeprecationWarning, TqdmWarning
from tqdm.std import Bar
from tqdm.contrib import DummyTqdmFile

Expand Down Expand Up @@ -1895,7 +1895,7 @@ def test_float_progress():
with closing(StringIO()) as our_file:
with trange(10, total=9.6, file=our_file) as t:
with catch_warnings(record=True) as w:
simplefilter("always")
simplefilter("always", category=TqdmWarning)
for i in t:
if i < 9:
assert not w
Expand Down Expand Up @@ -1987,3 +1987,26 @@ def test_initial():
out = our_file.getvalue()
assert '10/19' in out
assert '19/19' in out


@with_setup(pretest, posttest)
def test_colour():
"""Test `colour`"""
with closing(StringIO()) as our_file:
for _ in tqdm(_range(9), file=our_file, colour="#beefed"):
pass
out = our_file.getvalue()
assert '\x1b[38;2;%d;%d;%dm' % (0xbe, 0xef, 0xed) in out

with catch_warnings(record=True) as w:
simplefilter("always", category=TqdmWarning)
with tqdm(total=1, file=our_file, colour="charm") as t:
assert w
t.update()
assert "Unknown colour" in str(w[-1].message)

with closing(StringIO()) as our_file2:
for _ in tqdm(_range(9), file=our_file2, colour="blue"):
pass
out = our_file2.getvalue()
assert '\x1b[34m' in out

0 comments on commit 06fb6ec

Please sign in to comment.