MCPcopy
hub / github.com/pallets/click / test_file_atomics

Function test_file_atomics

tests/test_arguments.py:139–156  ·  view source on GitHub ↗
(runner)

Source from the content-addressed store, hash-verified

137
138
139def 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
159def test_stdout_default(runner):

Callers

nothing calls this directly

Calls 5

openFunction · 0.85
isolated_filesystemMethod · 0.80
readMethod · 0.80
writeMethod · 0.45
invokeMethod · 0.45

Tested by

no test coverage detected