Skip to content

Commit

Permalink
bump version, Merge pull request #86 from tqdm/unpause
Browse files Browse the repository at this point in the history
Add tqdm.unpause()
  • Loading branch information
casperdcl committed Dec 27, 2015
2 parents 2d143f2 + 338724d commit 5c2ad1f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ Documentation
def __init__(self, iterable=None, desc=None, total=None, leave=False,
file=sys.stderr, ncols=None, mininterval=0.1,
maxinterval= 10.0, miniters=None, ascii=None,
maxinterval=10.0, miniters=None, ascii=None,
disable=False, unit='it', unit_scale=False,
dynamic_ncols=False, smoothing=0.3, nested =False,
dynamic_ncols=False, smoothing=0.3, nested=False,
bar_format=None, initial=0, gui=False):
Parameters
Expand Down
12 changes: 10 additions & 2 deletions tqdm/_tqdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ class tqdm(object):
"""
def __init__(self, iterable=None, desc=None, total=None, leave=False,
file=sys.stderr, ncols=None, mininterval=0.1,
maxinterval= 10.0, miniters=None, ascii=None,
maxinterval=10.0, miniters=None, ascii=None,
disable=False, unit='it', unit_scale=False,
dynamic_ncols=False, smoothing=0.3, nested =False,
dynamic_ncols=False, smoothing=0.3, nested=False,
bar_format=None, initial=0, gui=False):
"""
Parameters
Expand Down Expand Up @@ -590,6 +590,14 @@ def close(self):
self.sp('') # clear up last bar
self.fp.write('\r' + _term_move_up() if self.nested else '\r')

def unpause(self):
"""
Restart tqdm timer from last print time.
"""
cur_t = time()
self.start_t += cur_t - self.last_print_t
self.last_print_t = cur_t

def set_description(self, desc=None):
"""
Set/modify description of the progress bar.
Expand Down
2 changes: 1 addition & 1 deletion tqdm/_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Definition of the version number
version_info = 3, 5, 0 # major, minor, patch, -extra
version_info = 3, 6, 0 # major, minor, patch, -extra

# Nice string for the version
__version__ = '.'.join(map(str, version_info)).replace('.-', '-').strip('.-')
37 changes: 31 additions & 6 deletions tqdm/tests/tests_tqdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def closing(arg):
RE_rate = re.compile(r'(\d+\.\d+)it/s')


def get_bar(all_bars, i):
""" Get a specific update from a whole bar traceback """
return all_bars.strip('\r').split('\r')[i]


def progressbar_rate(bar_str):
return float(RE_rate.search(bar_str).group(1))

Expand Down Expand Up @@ -520,10 +525,10 @@ def test_smoothing():
t.update()
# Get result for iter-based bar
our_file.seek(0)
a = progressbar_rate(our_file.read().strip('\r').split('\r')[3])
a = progressbar_rate(get_bar(our_file.read(), 3))
# Get result for manually updated bar
our_file2.seek(0)
a2 = progressbar_rate(our_file2.read().strip('\r').split('\r')[3])
a2 = progressbar_rate(get_bar(our_file2.read(), 3))

# 2nd case: use max smoothing (= instant rate)
with closing(StringIO()) as our_file2:
Expand All @@ -539,10 +544,10 @@ def test_smoothing():
t.update()
# Get result for iter-based bar
our_file.seek(0)
b = progressbar_rate(our_file.read().strip('\r').split('\r')[3])
b = progressbar_rate(get_bar(our_file.read(), 3))
# Get result for manually updated bar
our_file2.seek(0)
b2 = progressbar_rate(our_file2.read().strip('\r').split('\r')[3])
b2 = progressbar_rate(get_bar(our_file2.read(), 3))

# 3rd case: use medium smoothing
with closing(StringIO()) as our_file2:
Expand All @@ -558,10 +563,10 @@ def test_smoothing():
t.update()
# Get result for iter-based bar
our_file.seek(0)
c = progressbar_rate(our_file.read().strip('\r').split('\r')[3])
c = progressbar_rate(get_bar(our_file.read(), 3))
# Get result for manually updated bar
our_file2.seek(0)
c2 = progressbar_rate(our_file2.read().strip('\r').split('\r')[3])
c2 = progressbar_rate(get_bar(our_file2.read(), 3))

# Check that medium smoothing's rate is between no and max smoothing rates
assert a < c < b
Expand Down Expand Up @@ -709,6 +714,26 @@ def test_bar_format():
assert isinstance(t.bar_format, _unicode)


def test_unpause():
""" Test unpause """
with closing(StringIO()) as our_file:
t = trange(10, file=our_file, leave=True, mininterval=0)
sleep(0.01)
t.update()
sleep(0.01)
t.update()
sleep(0.1) # longer wait time
t.unpause()
sleep(0.01)
t.update()
sleep(0.01)
t.update()
t.close()
r_before = progressbar_rate(get_bar(our_file.getvalue(), 2))
r_after = progressbar_rate(get_bar(our_file.getvalue(), 3))
assert abs(r_before - r_after) < 1 # TODO: replace equal when DiscreteTimer


def test_set_description():
""" Test set description """
t = tqdm(desc='Hello')
Expand Down

0 comments on commit 5c2ad1f

Please sign in to comment.