Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions tests/test_termui.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,22 @@ def test_fast_edit(runner):
@pytest.mark.skipif(platform.system() == "Windows", reason="No sed on Windows.")
def test_edit(runner):
with tempfile.NamedTemporaryFile(mode="w") as named_tempfile:
named_tempfile.write("a\nb")
named_tempfile.write("a\nb\n")
named_tempfile.flush()

result = click.edit(filename=named_tempfile.name, editor="sed -i~ 's/$/Test/'")
assert result is None

# We need ot reopen the file as it becomes unreadable after the edit.
with open(named_tempfile.name) as reopened_file:
assert reopened_file.read() == "aTest\nbTest"
# POSIX says that when sed writes a pattern space to output then it
# is immediately followed by a newline and so the expected result
# should contain the newline. However, some sed implementations
# (e.g. GNU sed) does not terminate the last line in the output
# with the newline in a case the input data missed newline at the
# end of last line. Hence the input data (see above) should be
# terminated by newline too.
assert reopened_file.read() == "aTest\nbTest\n"


@pytest.mark.parametrize(
Expand Down