Skip to content
Myr

Make confirm, prompt, style files.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Edward G · committed by Edward G · parent a391797 · Browse files · 4 files+113 added−90 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+113 added−90 removed

  • tests:+113 added−90 removed

4 files+113 added−90 removed

added:tests/test_utils_2/test_confirm.py+49 added
1import click234def test_prompts(runner):5 @click.command()6 def test():7 if click.confirm("Foo"):8 click.echo("yes!")9 else:10 click.echo("no :(")1112 result = runner.invoke(test, input="y\n")13 assert not result.exception14 assert result.output == "Foo [y/N]: y\nyes!\n"1516 result = runner.invoke(test, input="\n")17 assert not result.exception18 assert result.output == "Foo [y/N]: \nno :(\n"1920 result = runner.invoke(test, input="n\n")21 assert not result.exception22 assert result.output == "Foo [y/N]: n\nno :(\n"2324 @click.command()25 def test_no():26 if click.confirm("Foo", default=True):27 click.echo("yes!")28 else:29 click.echo("no :(")3031 result = runner.invoke(test_no, input="y\n")32 assert not result.exception33 assert result.output == "Foo [Y/n]: y\nyes!\n"3435 result = runner.invoke(test_no, input="\n")36 assert not result.exception37 assert result.output == "Foo [Y/n]: \nyes!\n"3839 result = runner.invoke(test_no, input="n\n")40 assert not result.exception41 assert result.output == "Foo [Y/n]: n\nno :(\n"424344def test_confirm_repeat(runner):45 cli = click.Command(46 "cli", params=[click.Option(["--a/--no-a"], default=None, prompt=True)]47 )48 result = runner.invoke(cli, input="\ny\n")49 assert result.output == "A [y/n]: \nError: invalid input\nA [y/n]: y\n"
added:tests/test_utils_2/test_prompt.py+11 added
1import sys2from io import StringIO34import click567def test_prompt_cast_default(capfd, monkeypatch):8 monkeypatch.setattr(sys, "stdin", StringIO("\n"))9 value = click.prompt("value", default="100", type=int)10 capfd.readouterr()11 assert isinstance(value, int)
added:tests/test_utils_2/test_style.py+53 added
1import pytest23import click456@pytest.mark.parametrize(7 ("styles", "ref"),8 [9 ({"fg": "black"}, "\x1b[30mx y\x1b[0m"),10 ({"fg": "red"}, "\x1b[31mx y\x1b[0m"),11 ({"fg": "green"}, "\x1b[32mx y\x1b[0m"),12 ({"fg": "yellow"}, "\x1b[33mx y\x1b[0m"),13 ({"fg": "blue"}, "\x1b[34mx y\x1b[0m"),14 ({"fg": "magenta"}, "\x1b[35mx y\x1b[0m"),15 ({"fg": "cyan"}, "\x1b[36mx y\x1b[0m"),16 ({"fg": "white"}, "\x1b[37mx y\x1b[0m"),17 ({"bg": "black"}, "\x1b[40mx y\x1b[0m"),18 ({"bg": "red"}, "\x1b[41mx y\x1b[0m"),19 ({"bg": "green"}, "\x1b[42mx y\x1b[0m"),20 ({"bg": "yellow"}, "\x1b[43mx y\x1b[0m"),21 ({"bg": "blue"}, "\x1b[44mx y\x1b[0m"),22 ({"bg": "magenta"}, "\x1b[45mx y\x1b[0m"),23 ({"bg": "cyan"}, "\x1b[46mx y\x1b[0m"),24 ({"bg": "white"}, "\x1b[47mx y\x1b[0m"),25 ({"bg": 91}, "\x1b[48;5;91mx y\x1b[0m"),26 ({"bg": (135, 0, 175)}, "\x1b[48;2;135;0;175mx y\x1b[0m"),27 ({"bold": True}, "\x1b[1mx y\x1b[0m"),28 ({"dim": True}, "\x1b[2mx y\x1b[0m"),29 ({"underline": True}, "\x1b[4mx y\x1b[0m"),30 ({"overline": True}, "\x1b[53mx y\x1b[0m"),31 ({"italic": True}, "\x1b[3mx y\x1b[0m"),32 ({"blink": True}, "\x1b[5mx y\x1b[0m"),33 ({"reverse": True}, "\x1b[7mx y\x1b[0m"),34 ({"strikethrough": True}, "\x1b[9mx y\x1b[0m"),35 ({"bold": False}, "\x1b[22mx y\x1b[0m"),36 ({"dim": False}, "\x1b[22mx y\x1b[0m"),37 ({"underline": False}, "\x1b[24mx y\x1b[0m"),38 ({"overline": False}, "\x1b[55mx y\x1b[0m"),39 ({"italic": False}, "\x1b[23mx y\x1b[0m"),40 ({"blink": False}, "\x1b[25mx y\x1b[0m"),41 ({"reverse": False}, "\x1b[27mx y\x1b[0m"),42 ({"strikethrough": False}, "\x1b[29mx y\x1b[0m"),43 ({"fg": "black", "reset": False}, "\x1b[30mx y"),44 ],45)46def test_styling(styles, ref):47 assert click.style("x y", **styles) == ref48 assert click.unstyle(ref) == "x y"495051@pytest.mark.parametrize(("text", "expect"), [("\x1b[?25lx y\x1b[?25h", "x y")])52def test_unstyle_other_ansi(text, expect):53 assert click.unstyle(text) == expect
modified:tests/test_utils.py-90 removed
58 unmodified lines
5960 assert value not in real_values616263@pytest.mark.parametrize(64 ("styles", "ref"),65 [66 ({"fg": "black"}, "\x1b[30mx y\x1b[0m"),67 ({"fg": "red"}, "\x1b[31mx y\x1b[0m"),68 ({"fg": "green"}, "\x1b[32mx y\x1b[0m"),69 ({"fg": "yellow"}, "\x1b[33mx y\x1b[0m"),70 ({"fg": "blue"}, "\x1b[34mx y\x1b[0m"),71 ({"fg": "magenta"}, "\x1b[35mx y\x1b[0m"),72 ({"fg": "cyan"}, "\x1b[36mx y\x1b[0m"),73 ({"fg": "white"}, "\x1b[37mx y\x1b[0m"),74 ({"bg": "black"}, "\x1b[40mx y\x1b[0m"),75 ({"bg": "red"}, "\x1b[41mx y\x1b[0m"),76 ({"bg": "green"}, "\x1b[42mx y\x1b[0m"),77 ({"bg": "yellow"}, "\x1b[43mx y\x1b[0m"),78 ({"bg": "blue"}, "\x1b[44mx y\x1b[0m"),79 ({"bg": "magenta"}, "\x1b[45mx y\x1b[0m"),80 ({"bg": "cyan"}, "\x1b[46mx y\x1b[0m"),81 ({"bg": "white"}, "\x1b[47mx y\x1b[0m"),82 ({"bg": 91}, "\x1b[48;5;91mx y\x1b[0m"),83 ({"bg": (135, 0, 175)}, "\x1b[48;2;135;0;175mx y\x1b[0m"),84 ({"bold": True}, "\x1b[1mx y\x1b[0m"),85 ({"dim": True}, "\x1b[2mx y\x1b[0m"),86 ({"underline": True}, "\x1b[4mx y\x1b[0m"),87 ({"overline": True}, "\x1b[53mx y\x1b[0m"),88 ({"italic": True}, "\x1b[3mx y\x1b[0m"),89 ({"blink": True}, "\x1b[5mx y\x1b[0m"),90 ({"reverse": True}, "\x1b[7mx y\x1b[0m"),91 ({"strikethrough": True}, "\x1b[9mx y\x1b[0m"),92 ({"bold": False}, "\x1b[22mx y\x1b[0m"),93 ({"dim": False}, "\x1b[22mx y\x1b[0m"),94 ({"underline": False}, "\x1b[24mx y\x1b[0m"),95 ({"overline": False}, "\x1b[55mx y\x1b[0m"),96 ({"italic": False}, "\x1b[23mx y\x1b[0m"),97 ({"blink": False}, "\x1b[25mx y\x1b[0m"),98 ({"reverse": False}, "\x1b[27mx y\x1b[0m"),99 ({"strikethrough": False}, "\x1b[29mx y\x1b[0m"),100 ({"fg": "black", "reset": False}, "\x1b[30mx y"),101 ],102)103def test_styling(styles, ref):104 assert click.style("x y", **styles) == ref105 assert click.unstyle(ref) == "x y"106107108@pytest.mark.parametrize(("text", "expect"), [("\x1b[?25lx y\x1b[?25h", "x y")])109def test_unstyle_other_ansi(text, expect):110 assert click.unstyle(text) == expect11111263def test_filename_formatting():64 assert click.format_filename(b"foo.txt") == "foo.txt"65 assert click.format_filename(b"/x/foo.txt") == "/x/foo.txt"66 assert click.format_filename("/x/foo.txt") == "/x/foo.txt"67 assert click.format_filename("/x/foo.txt", shorten=True) == "foo.txt"68 assert click.format_filename("/x/\ufffd.txt", shorten=True) == "�.txt"6970121def test_prompts(runner):122 @click.command()123 def test():124 if click.confirm("Foo"):125 click.echo("yes!")126 else:127 click.echo("no :(")128129 result = runner.invoke(test, input="y\n")130 assert not result.exception131 assert result.output == "Foo [y/N]: y\nyes!\n"132133 result = runner.invoke(test, input="\n")134 assert not result.exception135 assert result.output == "Foo [y/N]: \nno :(\n"136137 result = runner.invoke(test, input="n\n")138 assert not result.exception139 assert result.output == "Foo [y/N]: n\nno :(\n"140141 @click.command()142 def test_no():143 if click.confirm("Foo", default=True):144 click.echo("yes!")145 else:146 click.echo("no :(")147148 result = runner.invoke(test_no, input="y\n")149 assert not result.exception150 assert result.output == "Foo [Y/n]: y\nyes!\n"151152 result = runner.invoke(test_no, input="\n")153 assert not result.exception154 assert result.output == "Foo [Y/n]: \nyes!\n"155156 result = runner.invoke(test_no, input="n\n")157 assert not result.exception158 assert result.output == "Foo [Y/n]: n\nno :(\n"15916071def test_confirm_repeat(runner):72 cli = click.Command(73 "cli", params=[click.Option(["--a/--no-a"], default=None, prompt=True)]74 )
267 unmodified lines