Skip to content

Commit

Permalink
test: try to reproduce --stdout double newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Aug 1, 2024
1 parent 720297a commit 9d932b6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/darker/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,27 @@ def test_stdout_path_resolution(git_repo, capsys):
assert capsys.readouterr().out == 'print("foo")\n'


@pytest.mark.parametrize("newline", ["\n", "\r\n"], ids=["unix", "windows"])
def test_stdout_newlines(tmp_path, monkeypatch, capsysbinary, newline):
"""When using ``--stdout``, newlines are not duplicated.
See: https://github.com/akaihola/darker/issues/604
"""
monkeypatch.chdir(tmp_path)
code = f"import collections{newline}import sys{newline}".encode()
Path("new-file.py").write_bytes(code)
with patch("sys.stdin.buffer.read", return_value=code):

result = darker.__main__.main(
["--stdout", "--isort", "--stdin-filename=new-file.py", "-"],
)

assert result == 0
expect = f"import collections{newline}import sys{newline}".encode()
assert capsysbinary.readouterr().out == expect


def test_long_command_length(git_repo):
"""Large amount of changed files does not break Git invocation even on Windows"""
# For PR #542 - large character count for changed files
Expand Down

0 comments on commit 9d932b6

Please sign in to comment.