summaryrefslogtreecommitdiff
path: root/tests/test_termui.py
diff options
context:
space:
mode:
authorChristopher Palmer <thecav@gmail.com>2019-05-31 12:52:25 -0400
committerDavid Lord <davidism@gmail.com>2019-08-01 13:07:20 -0700
commit04a17ae5a0113b268502a6c1cb0e15789f7e44ea (patch)
treeb4cdf14d416cb37b5f4dc9d9955002379d1709c8 /tests/test_termui.py
parenta43832228f19d041050940e513652e4e28461ab9 (diff)
downloadclick-04a17ae5a0113b268502a6c1cb0e15789f7e44ea.tar.gz
allow ProgressBar.update to set current_item
This allows updating what item is displayed when using ProgressBar.update to control the exact progress.
Diffstat (limited to 'tests/test_termui.py')
-rw-r--r--tests/test_termui.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/test_termui.py b/tests/test_termui.py
index 79fb7c6..b6cd516 100644
--- a/tests/test_termui.py
+++ b/tests/test_termui.py
@@ -239,6 +239,50 @@ def test_progressbar_update(runner, monkeypatch):
assert '100% ' in lines[3]
+def test_progressbar_item_show_func(runner, monkeypatch):
+ fake_clock = FakeClock()
+
+ @click.command()
+ def cli():
+ with click.progressbar(range(4), item_show_func=lambda x: "Custom {}".format(x)) as progress:
+ for _ in progress:
+ fake_clock.advance_time()
+ print("")
+
+ monkeypatch.setattr(time, 'time', fake_clock.time)
+ monkeypatch.setattr(click._termui_impl, 'isatty', lambda _: True)
+ output = runner.invoke(cli, []).output
+
+ lines = [line for line in output.split('\n') if '[' in line]
+
+ assert 'Custom 0' in lines[0]
+ assert 'Custom 1' in lines[1]
+ assert 'Custom 2' in lines[2]
+ assert 'Custom None' in lines[3]
+
+
+def test_progressbar_update_with_item_show_func(runner, monkeypatch):
+ fake_clock = FakeClock()
+
+ @click.command()
+ def cli():
+ with click.progressbar(length=6, item_show_func=lambda x: "Custom {}".format(x)) as progress:
+ while not progress.finished:
+ fake_clock.advance_time()
+ progress.update(2, progress.pos)
+ print("")
+
+ monkeypatch.setattr(time, 'time', fake_clock.time)
+ monkeypatch.setattr(click._termui_impl, 'isatty', lambda _: True)
+ output = runner.invoke(cli, []).output
+
+ lines = [line for line in output.split('\n') if '[' in line]
+
+ assert 'Custom 0' in lines[0]
+ assert 'Custom 2' in lines[1]
+ assert 'Custom 4' in lines[2]
+
+
@pytest.mark.parametrize(
'key_char', (u'h', u'H', u'é', u'À', u' ', u'字', u'àH', u'àR')
)