Skip to content

Commit

Permalink
Test for run_black() converting to Unix newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Jun 26, 2021
1 parent 26d333a commit dfa23f5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/darker/tests/test_black_diff.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from pathlib import Path
from unittest.mock import ANY, patch

import pytest

from darker import black_diff
from darker.black_diff import BlackArgs, read_black_config, run_black
from darker.utils import TextDocument

Expand Down Expand Up @@ -55,3 +57,15 @@ def test_run_black(tmpdir, encoding, newline):
)
assert result.encoding == encoding
assert result.newline == newline


@pytest.mark.parametrize("newline", ["\n", "\r\n"])
def test_run_black_always_uses_unix_newlines(tmpdir, newline):
"""Content is always passed to Black with Unix newlines"""
src = TextDocument.from_str(f"print ( 'touché' ){newline}")
with patch.object(black_diff, "format_str") as format_str:
format_str.return_value = 'print("touché")\n'

_ = run_black(Path(tmpdir / "src.py"), src, BlackArgs())

format_str.assert_called_once_with("print ( 'touché' )\n", mode=ANY)

0 comments on commit dfa23f5

Please sign in to comment.