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

Function test_edit

tests/test_termui.py:397–414  ·  view source on GitHub ↗
(runner)

Source from the content-addressed store, hash-verified

395
396@pytest.mark.skipif(platform.system() == "Windows", reason="No sed on Windows.")
397def test_edit(runner):
398 with tempfile.NamedTemporaryFile(mode="w") as named_tempfile:
399 named_tempfile.write("a\nb\n")
400 named_tempfile.flush()
401
402 result = click.edit(filename=named_tempfile.name, editor="sed -i~ 's/$/Test/'")
403 assert result is None
404
405 # We need to reopen the file as it becomes unreadable after the edit.
406 with open(named_tempfile.name) as reopened_file:
407 # POSIX says that when sed writes a pattern space to output then it
408 # is immediately followed by a newline and so the expected result
409 # should contain the newline. However, some sed implementations
410 # (e.g. GNU sed) does not terminate the last line in the output
411 # with the newline in a case the input data missed newline at the
412 # end of last line. Hence the input data (see above) should be
413 # terminated by newline too.
414 assert reopened_file.read() == "aTest\nbTest\n"
415
416
417@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 5

openFunction · 0.85
editMethod · 0.80
readMethod · 0.80
writeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…