(runner)
| 137 | |
| 138 | |
| 139 | def test_file_atomics(runner): |
| 140 | @click.command() |
| 141 | @click.argument("output", type=click.File("wb", atomic=True)) |
| 142 | def inout(output): |
| 143 | output.write(b"Foo bar baz\n") |
| 144 | output.flush() |
| 145 | with open(output.name, "rb") as f: |
| 146 | old_content = f.read() |
| 147 | assert old_content == b"OLD\n" |
| 148 | |
| 149 | with runner.isolated_filesystem(): |
| 150 | with open("foo.txt", "wb") as f: |
| 151 | f.write(b"OLD\n") |
| 152 | result = runner.invoke(inout, ["foo.txt"], input="Hey!", catch_exceptions=False) |
| 153 | assert result.output == "" |
| 154 | assert result.exit_code == 0 |
| 155 | with open("foo.txt", "rb") as f: |
| 156 | assert f.read() == b"Foo bar baz\n" |
| 157 | |
| 158 | |
| 159 | def test_stdout_default(runner): |
nothing calls this directly
no test coverage detected