Skip to content

Commit

Permalink
test: failing test for dropping changes for a non-ascii file
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Dec 30, 2024
1 parent 573e0aa commit 29b7ace
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/darker/tests/test_main_drop_changes_on_unedited_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""Tests for `__main__._drop_changes_on_unedited_lines`"""

from pathlib import Path
from unittest.mock import Mock

import pytest

from darker.__main__ import _drop_changes_on_unedited_lines
from darkgraylib.utils import TextDocument


@pytest.mark.kwparametrize(
dict(

Check failure on line 13 in src/darker/tests/test_main_drop_changes_on_unedited_lines.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/tests/test_main_drop_changes_on_unedited_lines.py#L13

Consider using '{"content": TextDocument("s = 'reformat'\n"), "new_chunks": [(1, ("s = 'reformat'", ), ('s = "reformat"', ))], ... }' instead of a call to 'dict'. (use-dict-literal, R1735)
content=TextDocument("s = 'reformat'\n"),
new_chunks=[(1, ("s = 'reformat'",), ('s = "reformat"',))],
),
dict(

Check failure on line 17 in src/darker/tests/test_main_drop_changes_on_unedited_lines.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/tests/test_main_drop_changes_on_unedited_lines.py#L17

Consider using '{"content": TextDocument('s = "keep"\n'), "new_chunks": [(1, ('s = "keep"', ), ('s = "keep"', ))], ... }' instead of a call to 'dict'. (use-dict-literal, R1735)
content=TextDocument('s = "keep"\n'),
new_chunks=[(1, ('s = "keep"',), ('s = "keep"',))],
),
dict(

Check failure on line 21 in src/darker/tests/test_main_drop_changes_on_unedited_lines.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/tests/test_main_drop_changes_on_unedited_lines.py#L21

Consider using '{"content": TextDocument('l1 = "first line"\nl2 = \'second line\'\n'), ... }' instead of a call to 'dict'. (use-dict-literal, R1735)
content=TextDocument("""l1 = "first line"\nl2 = 'second line'\n"""),
new_chunks=[
(
1,
('l1 = "first line"', "l2 = 'second line'"),
('l1 = "first line"', 'l2 = "second line"'),
)
],
),
dict(

Check failure on line 31 in src/darker/tests/test_main_drop_changes_on_unedited_lines.py

View workflow job for this annotation

GitHub Actions / Pylint

src/darker/tests/test_main_drop_changes_on_unedited_lines.py#L31

Consider using '{"content": TextDocument('# coding: iso-8859-5\n# б\x85б\x86\n', encoding='iso-8859-5'), ... }' instead of a call to 'dict'. (use-dict-literal, R1735)
content=TextDocument(
"# coding: iso-8859-5\n# б\x85б\x86\n", encoding="iso-8859-5"
),
new_chunks=[
(
1,
("# coding: iso-8859-5", "# б\x85б\x86"),
("# coding: iso-8859-5", "# б\x85б\x86"),
)
],
),
)
def test_unchanged_content(tmp_path, content, new_chunks):
"""Test that no reformats make it through for unmodified files."""
# A mock object that always returns an empty list of changed lines
edited_linenums_differ = Mock()
edited_linenums_differ.revision_vs_lines = Mock(return_value=[])
# The expected result is the same as the input content, unmodified
expect = content

result = _drop_changes_on_unedited_lines(
new_chunks,
abspath_in_rev2=tmp_path / "file.py",
relpath_in_repo=Path("file.py"),
edited_linenums_differ=edited_linenums_differ,
rev2_content=content,
rev2_isorted=content,
has_isort_changes=False,
has_fstring_changes=False,
)

assert result == expect

0 comments on commit 29b7ace

Please sign in to comment.