Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next release: v4.56.2 #1126

Merged
merged 4 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/tests_tqdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,18 @@ def test_unpause():
assert r_before == r_after


def test_disabled_unpause(capsys):
"""Test disabled unpause"""
with tqdm(total=10, disable=True) as t:
t.update()
t.unpause()
t.update()
print(t)
out, err = capsys.readouterr()
assert not err
assert out == ' 0%| | 0/10 [00:00<?, ?it/s]\n'


def test_reset():
"""Test resetting a bar for re-use"""
with closing(StringIO()) as our_file:
Expand All @@ -1186,6 +1198,20 @@ def test_reset():
assert '| 10/12' in our_file.getvalue()


def test_disabled_reset(capsys):
"""Test disabled reset"""
with tqdm(total=10, disable=True) as t:
t.update(9)
t.reset()
t.update()
t.reset(total=12)
t.update(10)
print(t)
out, err = capsys.readouterr()
assert not err
assert out == ' 0%| | 0/12 [00:00<?, ?it/s]\n'


@mark.skipif(nt_and_no_colorama, reason="Windows without colorama")
def test_position():
"""Test positioned progress bars"""
Expand Down
17 changes: 9 additions & 8 deletions tqdm/contrib/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ def __init__(self, *args, **kwargs):

See `tqdm.auto.tqdm.__init__` for other parameters.
"""
kwargs = kwargs.copy()
logging.getLogger("HTTPClient").setLevel(logging.WARNING)
self.dio = DiscordIO(
kwargs.pop('token', getenv("TQDM_DISCORD_TOKEN")),
kwargs.pop('channel_id', getenv("TQDM_DISCORD_CHANNEL_ID")))

kwargs['mininterval'] = max(1.5, kwargs.get('mininterval', 1.5))
if not kwargs.get('disable'):
kwargs = kwargs.copy()
logging.getLogger("HTTPClient").setLevel(logging.WARNING)
self.dio = DiscordIO(
kwargs.pop('token', getenv("TQDM_DISCORD_TOKEN")),
kwargs.pop('channel_id', getenv("TQDM_DISCORD_CHANNEL_ID")))
kwargs['mininterval'] = max(1.5, kwargs.get('mininterval', 1.5))
super(tqdm_discord, self).__init__(*args, **kwargs)

def display(self, **kwargs):
Expand All @@ -106,7 +106,8 @@ def display(self, **kwargs):

def clear(self, *args, **kwargs):
super(tqdm_discord, self).clear(*args, **kwargs)
self.dio.write("")
if not self.disable:
self.dio.write("")


def tdrange(*args, **kwargs):
Expand Down
11 changes: 7 additions & 4 deletions tqdm/contrib/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ def __init__(self, *args, **kwargs):

See `tqdm.auto.tqdm.__init__` for other parameters.
"""
kwargs = kwargs.copy()
self.tgio = TelegramIO(kwargs.pop('token', getenv('TQDM_TELEGRAM_TOKEN')),
kwargs.pop('chat_id', getenv('TQDM_TELEGRAM_CHAT_ID')))
if not kwargs.get('disable'):
kwargs = kwargs.copy()
self.tgio = TelegramIO(
kwargs.pop('token', getenv('TQDM_TELEGRAM_TOKEN')),
kwargs.pop('chat_id', getenv('TQDM_TELEGRAM_CHAT_ID')))
super(tqdm_telegram, self).__init__(*args, **kwargs)

def display(self, **kwargs):
Expand All @@ -108,7 +110,8 @@ def display(self, **kwargs):

def clear(self, *args, **kwargs):
super(tqdm_telegram, self).clear(*args, **kwargs)
self.tgio.write("")
if not self.disable:
self.tgio.write("")


def ttgrange(*args, **kwargs):
Expand Down
2 changes: 2 additions & 0 deletions tqdm/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ def reset(self, total=None):
----------
total : int or float, optional. Total to use for the new bar.
"""
if self.disable:
return super(tqdm_notebook, self).reset(total=total)
_, pbar, _ = self.container.children
pbar.bar_style = ''
if total is not None:
Expand Down
11 changes: 8 additions & 3 deletions tqdm/std.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,8 @@ def refresh(self, nolock=False, lock_args=None):

def unpause(self):
"""Restart tqdm timer from last print time."""
if self.disable:
return
cur_t = self._time()
self.start_t += cur_t - self.last_print_t
self.last_print_t = cur_t
Expand All @@ -1344,13 +1346,16 @@ def reset(self, total=None):
----------
total : int or float, optional. Total to use for the new bar.
"""
self.last_print_n = self.n = 0
self.n = 0
if total is not None:
self.total = total
if self.disable:
return
self.last_print_n = 0
self.last_print_t = self.start_t = self._time()
self._ema_dn = EMA(self.smoothing)
self._ema_dt = EMA(self.smoothing)
self._ema_miniters = EMA(self.smoothing)
if total is not None:
self.total = total
self.refresh()

def set_description(self, desc=None, refresh=True):
Expand Down