test_utils.py
This file
Path
tests/test_utils.py
384 lines · 11.5 KiB · Python
Last changed by
Merge pull request #1591 from andy-maier/andy/fix-unsupportedoperationDavid Lordbefore adoption090ff26
History of this fileTake it
The walk stopped after 200 commits: lines older than 950463b point at it.
Fix typo (#817)scottbeldenbefore adoption950463b
line 1why, one step back1import osMerge branch '7.x'David Lordbefore adoption2269786
line 2why, one step back2import statFix typo (#817)scottbeldenbefore adoption950463b
line 3why, one step back3import sysMerge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 4why, one step back4from io import StringIOFix typo (#817)scottbeldenbefore adoption950463b
lines 5–8why, one step back56import pytest78import click._termui_implMerge branch '7.x'David Lordbefore adoption7239794
lines 9–10why, one step back9import click.utils10from click._compat import WINFix typo (#817)scottbeldenbefore adoption950463b
lines 11–13why, one step back111213def test_echo(runner):CliRunner: add stdout / stderr, allow separating standard streams (#868)Dave Carlsonbefore adoptionfdceb39
line 14why, one step back14 with runner.isolation() as outstreams:Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 15why, one step back15 click.echo("\N{SNOWMAN}")Merge branch '7.x'David Lordbefore adoption7239794
line 16why, one step back16 click.echo(b"\x44\x44")Fix typo (#817)scottbeldenbefore adoption950463b
line 17why, one step back17 click.echo(42, nl=False)Merge branch '7.x'David Lordbefore adoption7239794
lines 18–21why, one step back18 click.echo(b"a", nl=False)19 click.echo("\x1b[31mx\x1b[39m", nl=False)20 bytes = outstreams[0].getvalue().replace(b"\r\n", b"\n")21 assert bytes == b"\xe2\x98\x83\nDD\n42ax"Fix typo (#817)scottbeldenbefore adoption950463b
line 22why, one step back22Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 23why, one step back23 # if wrapped, we expect bytes to survive.Fix typo (#817)scottbeldenbefore adoption950463b
lines 24–25why, one step back24 @click.command()25 def cli():Merge branch '7.x'David Lordbefore adoption7239794
lines 26–27why, one step back26 click.echo(b"\xf6")27Fix typo (#817)scottbeldenbefore adoption950463b
line 28why, one step back28 result = runner.invoke(cli, [])Merge branch '7.x'David Lordbefore adoption7239794
line 29why, one step back29 assert result.stdout_bytes == b"\xf6\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 30–31why, one step back3031 # Ensure we do not strip for bytes.CliRunner: add stdout / stderr, allow separating standard streams (#868)Dave Carlsonbefore adoptionfdceb39
line 32why, one step back32 with runner.isolation() as outstreams:Merge branch '7.x'David Lordbefore adoption7239794
lines 33–34why, one step back33 click.echo(bytearray(b"\x1b[31mx\x1b[39m"), nl=False)34 assert outstreams[0].getvalue() == b"\x1b[31mx\x1b[39m"Fix typo (#817)scottbeldenbefore adoption950463b
lines 35–38why, one step back353637def test_echo_custom_file():38 import ioMerge branch '7.x'David Lordbefore adoption7239794
line 39why, one step back39Fix typo (#817)scottbeldenbefore adoption950463b
line 40why, one step back40 f = io.StringIO()Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
lines 41–42why, one step back41 click.echo("hello", file=f)42 assert f.getvalue() == "hello\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 43–44why, one step back4344Merge branch '7.x'David Lordbefore adoption2269786
lines 45–74why, one step back45@pytest.mark.parametrize(46 ("styles", "ref"),47 [48 ({"fg": "black"}, "\x1b[30mx y\x1b[0m"),49 ({"fg": "red"}, "\x1b[31mx y\x1b[0m"),50 ({"fg": "green"}, "\x1b[32mx y\x1b[0m"),51 ({"fg": "yellow"}, "\x1b[33mx y\x1b[0m"),52 ({"fg": "blue"}, "\x1b[34mx y\x1b[0m"),53 ({"fg": "magenta"}, "\x1b[35mx y\x1b[0m"),54 ({"fg": "cyan"}, "\x1b[36mx y\x1b[0m"),55 ({"fg": "white"}, "\x1b[37mx y\x1b[0m"),56 ({"bg": "black"}, "\x1b[40mx y\x1b[0m"),57 ({"bg": "red"}, "\x1b[41mx y\x1b[0m"),58 ({"bg": "green"}, "\x1b[42mx y\x1b[0m"),59 ({"bg": "yellow"}, "\x1b[43mx y\x1b[0m"),60 ({"bg": "blue"}, "\x1b[44mx y\x1b[0m"),61 ({"bg": "magenta"}, "\x1b[45mx y\x1b[0m"),62 ({"bg": "cyan"}, "\x1b[46mx y\x1b[0m"),63 ({"bg": "white"}, "\x1b[47mx y\x1b[0m"),64 ({"blink": True}, "\x1b[5mx y\x1b[0m"),65 ({"underline": True}, "\x1b[4mx y\x1b[0m"),66 ({"bold": True}, "\x1b[1mx y\x1b[0m"),67 ({"dim": True}, "\x1b[2mx y\x1b[0m"),68 ],69)70def test_styling(styles, ref):71 assert click.style("x y", **styles) == ref72 assert click.unstyle(ref) == "x y"7374Merge branch '7.x'David Lordbefore adoption7239794
line 75why, one step back75@pytest.mark.parametrize(("text", "expect"), [("\x1b[?25lx y\x1b[?25h", "x y")])Merge branch '7.x'David Lordbefore adoption2269786
lines 76–77why, one step back76def test_unstyle_other_ansi(text, expect):77 assert click.unstyle(text) == expectFix typo (#817)scottbeldenbefore adoption950463b
lines 78–80why, one step back787980def test_filename_formatting():Merge branch '7.x'David Lordbefore adoption7239794
lines 81–82why, one step back81 assert click.format_filename(b"foo.txt") == "foo.txt"82 assert click.format_filename(b"/x/foo.txt") == "/x/foo.txt"Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
lines 83–84why, one step back83 assert click.format_filename("/x/foo.txt") == "/x/foo.txt"84 assert click.format_filename("/x/foo.txt", shorten=True) == "foo.txt"Fix typo (#817)scottbeldenbefore adoption950463b
lines 85–87why, one step back8586 # filesystem encoding on windows permits this.87 if not WIN:Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 88why, one step back88 assert click.format_filename(b"/x/foo\xff.txt", shorten=True) == "foo\ufffd.txt"Fix typo (#817)scottbeldenbefore adoption950463b
lines 89–93why, one step back899091def test_prompts(runner):92 @click.command()93 def test():Merge branch '7.x'David Lordbefore adoption7239794
lines 94–95why, one step back94 if click.confirm("Foo"):95 click.echo("yes!")Fix typo (#817)scottbeldenbefore adoption950463b
line 96why, one step back96 else:Merge branch '7.x'David Lordbefore adoption7239794
line 97why, one step back97 click.echo("no :(")Fix typo (#817)scottbeldenbefore adoption950463b
line 98why, one step back98Merge branch '7.x'David Lordbefore adoption7239794
line 99why, one step back99 result = runner.invoke(test, input="y\n")Fix typo (#817)scottbeldenbefore adoption950463b
line 100why, one step back100 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 101why, one step back101 assert result.output == "Foo [y/N]: y\nyes!\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 102why, one step back102Merge branch '7.x'David Lordbefore adoption7239794
line 103why, one step back103 result = runner.invoke(test, input="\n")Fix typo (#817)scottbeldenbefore adoption950463b
line 104why, one step back104 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 105why, one step back105 assert result.output == "Foo [y/N]: \nno :(\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 106why, one step back106Merge branch '7.x'David Lordbefore adoption7239794
line 107why, one step back107 result = runner.invoke(test, input="n\n")Fix typo (#817)scottbeldenbefore adoption950463b
line 108why, one step back108 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 109why, one step back109 assert result.output == "Foo [y/N]: n\nno :(\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 110–112why, one step back110111 @click.command()112 def test_no():Merge branch '7.x'David Lordbefore adoption7239794
lines 113–114why, one step back113 if click.confirm("Foo", default=True):114 click.echo("yes!")Fix typo (#817)scottbeldenbefore adoption950463b
line 115why, one step back115 else:Merge branch '7.x'David Lordbefore adoption7239794
line 116why, one step back116 click.echo("no :(")Fix typo (#817)scottbeldenbefore adoption950463b
line 117why, one step back117Merge branch '7.x'David Lordbefore adoption7239794
line 118why, one step back118 result = runner.invoke(test_no, input="y\n")Fix typo (#817)scottbeldenbefore adoption950463b
line 119why, one step back119 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 120why, one step back120 assert result.output == "Foo [Y/n]: y\nyes!\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 121why, one step back121Merge branch '7.x'David Lordbefore adoption7239794
line 122why, one step back122 result = runner.invoke(test_no, input="\n")Fix typo (#817)scottbeldenbefore adoption950463b
line 123why, one step back123 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 124why, one step back124 assert result.output == "Foo [Y/n]: \nyes!\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 125why, one step back125Merge branch '7.x'David Lordbefore adoption7239794
line 126why, one step back126 result = runner.invoke(test_no, input="n\n")Fix typo (#817)scottbeldenbefore adoption950463b
line 127why, one step back127 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 128why, one step back128 assert result.output == "Foo [Y/n]: n\nno :(\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 129–130why, one step back129130Merge branch '7.x'David Lordbefore adoption7239794
line 131why, one step back131@pytest.mark.skipif(WIN, reason="Different behavior on windows.")Fix typo (#817)scottbeldenbefore adoption950463b
lines 132–135why, one step back132def test_prompts_abort(monkeypatch, capsys):133 def f(_):134 raise KeyboardInterrupt()135Merge branch '7.x'David Lordbefore adoption7239794
line 136why, one step back136 monkeypatch.setattr("click.termui.hidden_prompt_func", f)Fix typo (#817)scottbeldenbefore adoption950463b
lines 137–138why, one step back137138 try:Merge branch '7.x'David Lordbefore adoption7239794
line 139why, one step back139 click.prompt("Password", hide_input=True)Fix typo (#817)scottbeldenbefore adoption950463b
line 140why, one step back140 except click.Abort:Merge branch '7.x'David Lordbefore adoption7239794
line 141why, one step back141 click.echo("Screw you.")Fix typo (#817)scottbeldenbefore adoption950463b
lines 142–143why, one step back142143 out, err = capsys.readouterr()Merge branch '7.x'David Lordbefore adoption7239794
line 144why, one step back144 assert out == "Password: \nScrew you.\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 145–146why, one step back145146Merge pull request #889 from stefreak/masterDan Sullybefore adoptionb1b4449
line 147why, one step back147def _test_gen_func():Merge branch '7.x'David Lordbefore adoption7239794
lines 148–151why, one step back148 yield "a"149 yield "b"150 yield "c"151 yield "abc"Merge pull request #889 from stefreak/masterDan Sullybefore adoptionb1b4449
lines 152–153why, one step back152153Merge branch '7.x'David Lordbefore adoption7239794
lines 154–168why, one step back154@pytest.mark.skipif(WIN, reason="Different behavior on windows.")155@pytest.mark.parametrize("cat", ["cat", "cat ", "cat "])156@pytest.mark.parametrize(157 "test",158 [159 # We need lambda here, because pytest will160 # reuse the parameters, and then the generators161 # are already used and will not yield anymore162 ("just text\n", lambda: "just text"),163 ("iterable\n", lambda: ["itera", "ble"]),164 ("abcabc\n", lambda: _test_gen_func),165 ("abcabc\n", lambda: _test_gen_func()),166 ("012345\n", lambda: (c for c in range(6))),167 ],168)Merge pull request #889 from stefreak/masterDan Sullybefore adoptionb1b4449
line 169why, one step back169def test_echo_via_pager(monkeypatch, capfd, cat, test):Merge branch '7.x'David Lordbefore adoption7239794
lines 170–171why, one step back170 monkeypatch.setitem(os.environ, "PAGER", cat)171 monkeypatch.setattr(click._termui_impl, "isatty", lambda x: True)Merge pull request #889 from stefreak/masterDan Sullybefore adoptionb1b4449
lines 172–177why, one step back172173 expected_output = test[0]174 test_input = test[1]()175176 click.echo_via_pager(test_input)177Fix typo (#817)scottbeldenbefore adoption950463b
line 178why, one step back178 out, err = capfd.readouterr()Merge pull request #889 from stefreak/masterDan Sullybefore adoptionb1b4449
line 179why, one step back179 assert out == expected_outputFix typo (#817)scottbeldenbefore adoption950463b
lines 180–181why, one step back180181Merge branch '7.x'David Lordbefore adoption7239794
line 182why, one step back182@pytest.mark.skipif(WIN, reason="Test does not make sense on Windows.")Fix typo (#817)scottbeldenbefore adoption950463b
lines 183–184why, one step back183def test_echo_color_flag(monkeypatch, capfd):184 isatty = TrueMerge branch '7.x'David Lordbefore adoption7239794
line 185why, one step back185 monkeypatch.setattr(click._compat, "isatty", lambda x: isatty)Fix typo (#817)scottbeldenbefore adoption950463b
line 186why, one step back186Merge branch '7.x'David Lordbefore adoption7239794
lines 187–189why, one step back187 text = "foo"188 styled_text = click.style(text, fg="red")189 assert styled_text == "\x1b[31mfoo\x1b[0m"Fix typo (#817)scottbeldenbefore adoption950463b
lines 190–192why, one step back190191 click.echo(styled_text, color=False)192 out, err = capfd.readouterr()Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 193why, one step back193 assert out == f"{text}\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 194–196why, one step back194195 click.echo(styled_text, color=True)196 out, err = capfd.readouterr()Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 197why, one step back197 assert out == f"{styled_text}\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 198–201why, one step back198199 isatty = True200 click.echo(styled_text)201 out, err = capfd.readouterr()Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 202why, one step back202 assert out == f"{styled_text}\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 203–206why, one step back203204 isatty = False205 click.echo(styled_text)206 out, err = capfd.readouterr()Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 207why, one step back207 assert out == f"{text}\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 208–209why, one step back208209Merge branch '7.x'David Lordbefore adoption7239794
line 210why, one step back210@pytest.mark.skipif(WIN, reason="Test too complex to make work windows.")Fix typo (#817)scottbeldenbefore adoption950463b
lines 211–213why, one step back211def test_echo_writing_to_standard_error(capfd, monkeypatch):212 def emulate_input(text):213 """Emulate keyboard input."""Merge branch '7.x'David Lordbefore adoption7239794
line 214why, one step back214 monkeypatch.setattr(sys, "stdin", StringIO(text))Fix typo (#817)scottbeldenbefore adoption950463b
line 215why, one step back215Merge branch '7.x'David Lordbefore adoption7239794
line 216why, one step back216 click.echo("Echo to standard output")Fix typo (#817)scottbeldenbefore adoption950463b
line 217why, one step back217 out, err = capfd.readouterr()Merge branch '7.x'David Lordbefore adoption7239794
lines 218–219why, one step back218 assert out == "Echo to standard output\n"219 assert err == ""Fix typo (#817)scottbeldenbefore adoption950463b
line 220why, one step back220Merge branch '7.x'David Lordbefore adoption7239794
line 221why, one step back221 click.echo("Echo to standard error", err=True)Fix typo (#817)scottbeldenbefore adoption950463b
line 222why, one step back222 out, err = capfd.readouterr()Merge branch '7.x'David Lordbefore adoption7239794
lines 223–224why, one step back223 assert out == ""224 assert err == "Echo to standard error\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 225why, one step back225Merge branch '7.x'David Lordbefore adoption7239794
lines 226–227why, one step back226 emulate_input("asdlkj\n")227 click.prompt("Prompt to stdin")Fix typo (#817)scottbeldenbefore adoption950463b
line 228why, one step back228 out, err = capfd.readouterr()Merge branch '7.x'David Lordbefore adoption7239794
lines 229–230why, one step back229 assert out == "Prompt to stdin: "230 assert err == ""Fix typo (#817)scottbeldenbefore adoption950463b
line 231why, one step back231Merge branch '7.x'David Lordbefore adoption7239794
lines 232–233why, one step back232 emulate_input("asdlkj\n")233 click.prompt("Prompt to stderr", err=True)Fix typo (#817)scottbeldenbefore adoption950463b
line 234why, one step back234 out, err = capfd.readouterr()Merge branch '7.x'David Lordbefore adoption7239794
lines 235–236why, one step back235 assert out == ""236 assert err == "Prompt to stderr: "Fix typo (#817)scottbeldenbefore adoption950463b
line 237why, one step back237Merge branch '7.x'David Lordbefore adoption7239794
lines 238–239why, one step back238 emulate_input("y\n")239 click.confirm("Prompt to stdin")Fix typo (#817)scottbeldenbefore adoption950463b
line 240why, one step back240 out, err = capfd.readouterr()Merge branch '7.x'David Lordbefore adoption7239794
lines 241–242why, one step back241 assert out == "Prompt to stdin [y/N]: "242 assert err == ""Fix typo (#817)scottbeldenbefore adoption950463b
line 243why, one step back243Merge branch '7.x'David Lordbefore adoption7239794
lines 244–245why, one step back244 emulate_input("y\n")245 click.confirm("Prompt to stderr", err=True)Fix typo (#817)scottbeldenbefore adoption950463b
line 246why, one step back246 out, err = capfd.readouterr()Merge branch '7.x'David Lordbefore adoption7239794
lines 247–248why, one step back247 assert out == ""248 assert err == "Prompt to stderr [y/N]: "Fix typo (#817)scottbeldenbefore adoption950463b
line 249why, one step back249Merge branch '7.x'David Lordbefore adoption7239794
lines 250–251why, one step back250 monkeypatch.setattr(click.termui, "isatty", lambda x: True)251 monkeypatch.setattr(click.termui, "getchar", lambda: " ")Fix typo (#817)scottbeldenbefore adoption950463b
line 252why, one step back252Merge branch '7.x'David Lordbefore adoption7239794
line 253why, one step back253 click.pause("Pause to stdout")Fix typo (#817)scottbeldenbefore adoption950463b
line 254why, one step back254 out, err = capfd.readouterr()Merge branch '7.x'David Lordbefore adoption7239794
lines 255–256why, one step back255 assert out == "Pause to stdout\n"256 assert err == ""Fix typo (#817)scottbeldenbefore adoption950463b
line 257why, one step back257Merge branch '7.x'David Lordbefore adoption7239794
line 258why, one step back258 click.pause("Pause to stderr", err=True)Fix typo (#817)scottbeldenbefore adoption950463b
line 259why, one step back259 out, err = capfd.readouterr()Merge branch '7.x'David Lordbefore adoption7239794
lines 260–261why, one step back260 assert out == ""261 assert err == "Pause to stderr\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 262–263why, one step back262263Merge pull request #1591 from andy-maier/andy/fix-unsupportedoperationDavid Lordbefore adoption090ff26
lines 264–269why, one step back264def test_echo_with_capsys(capsys):265 click.echo("Capture me.")266 out, err = capsys.readouterr()267 assert out == "Capture me.\n"268269Fix typo (#817)scottbeldenbefore adoption950463b
line 270why, one step back270def test_open_file(runner):Merge branch '7.x'David Lordbefore adoption2269786
line 271why, one step back271 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 272why, one step back272 @click.argument("filename")Merge branch '7.x'David Lordbefore adoption2269786
lines 273–276why, one step back273 def cli(filename):274 with click.open_file(filename) as f:275 click.echo(f.read())276Merge branch '7.x'David Lordbefore adoption7239794
line 277why, one step back277 click.echo("meep")Merge branch '7.x'David Lordbefore adoption2269786
line 278why, one step back278Fix typo (#817)scottbeldenbefore adoption950463b
line 279why, one step back279 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 280–281why, one step back280 with open("hello.txt", "w") as f:281 f.write("Cool stuff")Fix typo (#817)scottbeldenbefore adoption950463b
line 282why, one step back282Merge branch '7.x'David Lordbefore adoption7239794
line 283why, one step back283 result = runner.invoke(cli, ["hello.txt"])Fix typo (#817)scottbeldenbefore adoption950463b
line 284why, one step back284 assert result.exception is NoneMerge branch '7.x'David Lordbefore adoption7239794
line 285why, one step back285 assert result.output == "Cool stuff\nmeep\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 286why, one step back286Merge branch '7.x'David Lordbefore adoption7239794
line 287why, one step back287 result = runner.invoke(cli, ["-"], input="foobar")Fix typo (#817)scottbeldenbefore adoption950463b
line 288why, one step back288 assert result.exception is NoneMerge branch '7.x'David Lordbefore adoption7239794
line 289why, one step back289 assert result.output == "foobar\nmeep\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 290–291why, one step back290291Merge branch '7.x'David Lordbefore adoption2269786
lines 292–329why, one step back292def test_open_file_ignore_errors_stdin(runner):293 @click.command()294 @click.argument("filename")295 def cli(filename):296 with click.open_file(filename, errors="ignore") as f:297 click.echo(f.read())298299 result = runner.invoke(cli, ["-"], input=os.urandom(16))300 assert result.exception is None301302303def test_open_file_respects_ignore(runner):304 with runner.isolated_filesystem():305 with open("test.txt", "w") as f:306 f.write("Hello world!")307308 with click.open_file("test.txt", encoding="utf8", errors="ignore") as f:309 assert f.errors == "ignore"310311312def test_open_file_ignore_invalid_utf8(runner):313 with runner.isolated_filesystem():314 with open("test.txt", "wb") as f:315 f.write(b"\xe2\x28\xa1")316317 with click.open_file("test.txt", encoding="utf8", errors="ignore") as f:318 f.read()319320321def test_open_file_ignore_no_encoding(runner):322 with runner.isolated_filesystem():323 with open("test.bin", "wb") as f:324 f.write(os.urandom(16))325326 with click.open_file("test.bin", errors="ignore") as f:327 f.read()328329Merge branch '7.x'David Lordbefore adoption7239794
lines 330–331why, one step back330@pytest.mark.skipif(WIN, reason="os.chmod() is not fully supported on Windows.")331@pytest.mark.parametrize("permissions", [0o400, 0o444, 0o600, 0o644])Merge branch '7.x'David Lordbefore adoption2269786
lines 332–333why, one step back332def test_open_file_atomic_permissions_existing_file(runner, permissions):333 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 334–336why, one step back334 with open("existing.txt", "w") as f:335 f.write("content")336 os.chmod("existing.txt", permissions)Merge branch '7.x'David Lordbefore adoption2269786
lines 337–338why, one step back337338 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 339why, one step back339 @click.argument("filename")Merge branch '7.x'David Lordbefore adoption2269786
line 340why, one step back340 def cli(filename):Merge branch '7.x'David Lordbefore adoption7239794
line 341why, one step back341 click.open_file(filename, "w", atomic=True).close()Merge branch '7.x'David Lordbefore adoption2269786
line 342why, one step back342Merge branch '7.x'David Lordbefore adoption7239794
line 343why, one step back343 result = runner.invoke(cli, ["existing.txt"])Merge branch '7.x'David Lordbefore adoption2269786
line 344why, one step back344 assert result.exception is NoneMerge branch '7.x'David Lordbefore adoption7239794
line 345why, one step back345 assert stat.S_IMODE(os.stat("existing.txt").st_mode) == permissionsMerge branch '7.x'David Lordbefore adoption2269786
lines 346–347why, one step back346347Merge branch '7.x'David Lordbefore adoption7239794
line 348why, one step back348@pytest.mark.skipif(WIN, reason="os.stat() is not fully supported on Windows.")Merge branch '7.x'David Lordbefore adoption2269786
lines 349–350why, one step back349def test_open_file_atomic_permissions_new_file(runner):350 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
line 351why, one step back351Merge branch '7.x'David Lordbefore adoption2269786
line 352why, one step back352 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 353why, one step back353 @click.argument("filename")Merge branch '7.x'David Lordbefore adoption2269786
line 354why, one step back354 def cli(filename):Merge branch '7.x'David Lordbefore adoption7239794
line 355why, one step back355 click.open_file(filename, "w", atomic=True).close()Merge branch '7.x'David Lordbefore adoption2269786
lines 356–358why, one step back356357 # Create a test file to get the expected permissions for new files358 # according to the current umask.Merge branch '7.x'David Lordbefore adoption7239794
line 359why, one step back359 with open("test.txt", "w"):Merge branch '7.x'David Lordbefore adoption2269786
line 360why, one step back360 passMerge branch '7.x'David Lordbefore adoption7239794
line 361why, one step back361 permissions = stat.S_IMODE(os.stat("test.txt").st_mode)Merge branch '7.x'David Lordbefore adoption2269786
line 362why, one step back362Merge branch '7.x'David Lordbefore adoption7239794
line 363why, one step back363 result = runner.invoke(cli, ["new.txt"])Merge branch '7.x'David Lordbefore adoption2269786
line 364why, one step back364 assert result.exception is NoneMerge branch '7.x'David Lordbefore adoption7239794
line 365why, one step back365 assert stat.S_IMODE(os.stat("new.txt").st_mode) == permissionsMerge branch '7.x'David Lordbefore adoption2269786
lines 366–367why, one step back366367Fix typo (#817)scottbeldenbefore adoption950463b
lines 368–369why, one step back368def test_iter_keepopenfile(tmpdir):369 expected = list(map(str, range(10)))Merge branch '7.x'David Lordbefore adoption7239794
line 370why, one step back370 p = tmpdir.mkdir("testdir").join("testfile")Merge branch '7.x'David Lordbefore adoption2269786
line 371why, one step back371 p.write("\n".join(expected))Merge pull request #878 from jdufresne/resource-warningZachery Birbefore adoption3f66498
lines 372–374why, one step back372 with p.open() as f:373 for e_line, a_line in zip(expected, click.utils.KeepOpenFile(f)):374 assert e_line == a_line.strip()Fix typo (#817)scottbeldenbefore adoption950463b
lines 375–378why, one step back375376377def test_iter_lazyfile(tmpdir):378 expected = list(map(str, range(10)))Merge branch '7.x'David Lordbefore adoption7239794
line 379why, one step back379 p = tmpdir.mkdir("testdir").join("testfile")Merge branch '7.x'David Lordbefore adoption2269786
line 380why, one step back380 p.write("\n".join(expected))Merge pull request #878 from jdufresne/resource-warningZachery Birbefore adoption3f66498
lines 381–384why, one step back381 with p.open() as f:382 with click.utils.LazyFile(f.name) as lf:383 for e_line, a_line in zip(expected, lf):384 assert e_line == a_line.strip()