Skip to content
Myr

test_termui.py

This file

Path

tests/test_termui.py

71 lines · 1.9 KiB · Python

Last changed by

Merge branch 'Rovanion-master'Markus Unterwaditzerbefore adoption67f39e4

History of this file

Take it

1import click234def test_progressbar_strip_regression(runner, monkeypatch):5    label = '    padded line'67    @click.command()8    def cli():9        with click.progressbar(tuple(range(10)), label=label) as progress:10            for thing in progress:11                pass1213    monkeypatch.setattr(click._termui_impl, 'isatty', lambda _: True)14    assert label in runner.invoke(cli, []).output151617def test_progressbar_length_hint(runner, monkeypatch):18    class Hinted(object):19        def __init__(self, n):20            self.items = list(range(n))2122        def __length_hint__(self):23            return len(self.items)2425        def __iter__(self):26            return self2728        def __next__(self):29            if self.items:30                return self.items.pop()31            else:32                raise StopIteration3334        next = __next__3536    @click.command()37    def cli():38        with click.progressbar(Hinted(10), label='test') as progress:39            for thing in progress:40                pass4142    monkeypatch.setattr(click._termui_impl, 'isatty', lambda _: True)43    result = runner.invoke(cli, [])44    assert result.exception is None454647def test_choices_list_in_prompt(runner, monkeypatch):48    @click.command()49    @click.option('-g', type=click.Choice(['none', 'day', 'week', 'month']),50                  prompt=True)51    def cli_with_choices(g):52        pass5354    @click.command()55    @click.option('-g', type=click.Choice(['none', 'day', 'week', 'month']),56                  prompt=True, show_choices=False)57    def cli_without_choices(g):58        pass5960    result = runner.invoke(cli_with_choices, [], input='none')61    assert '(none, day, week, month)' in result.output6263    result = runner.invoke(cli_without_choices, [], input='none')64    assert '(none, day, week, month)' not in result.output656667def test_secho(runner):68    with runner.isolation() as out:69        click.secho(None, nl=False)70        bytes = out.getvalue()71        assert bytes == b''