Skip to content

Commit

Permalink
Separate a test case of apply_flynt()
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Dec 28, 2022
1 parent f1a6c4a commit ab438ab
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/darker/tests/test_fstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ def test_fstring_importable_with_and_without_flynt(present):

@pytest.mark.parametrize("encoding", ["utf-8", "iso-8859-1"])
@pytest.mark.parametrize("newline", ["\n", "\r\n"])
@pytest.mark.kwparametrize(
dict(exclude=set(), expect=FLYNTED_SOURCE),
dict(exclude={"**/*"}, expect=MODIFIED_SOURCE),
)
def test_apply_flynt_exclude(git_repo, encoding, newline, exclude, expect):
"""Flynt skipped if path matches exclusion patterns, encoding and newline intact"""
def test_apply_flynt_exclude(git_repo, encoding, newline):
"""Encoding and newline are intact after Flynt fstringification"""
git_repo.add({"test1.py": joinlines(ORIGINAL_SOURCE, newline)}, commit="Initial")
edited_linenums_differ = EditedLinenumsDiffer(
git_repo.root, RevisionRange("HEAD", ":WORKTREE:")
Expand All @@ -47,10 +43,8 @@ def test_apply_flynt_exclude(git_repo, encoding, newline, exclude, expect):
MODIFIED_SOURCE, encoding=encoding, newline=newline
)

result = darker.fstring.apply_flynt(
content_, src, exclude=exclude, edited_linenums_differ=edited_linenums_differ
)
result = darker.fstring.apply_flynt(content_, src, edited_linenums_differ)

assert result.lines == expect
assert result.lines == FLYNTED_SOURCE
assert result.encoding == encoding
assert result.newline == newline
27 changes: 27 additions & 0 deletions src/darker/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from darker.exceptions import MissingPackageError
from darker.git import WORKTREE, EditedLinenumsDiffer, RevisionRange
from darker.tests.helpers import isort_present
from darker.tests.test_fstring import FLYNTED_SOURCE, MODIFIED_SOURCE, ORIGINAL_SOURCE
from darker.utils import TextDocument, joinlines
from darker.verification import NotEquivalentError

Expand Down Expand Up @@ -749,6 +750,32 @@ def test_print_diff(tmp_path, capsys):
]


@pytest.mark.parametrize("encoding", ["utf-8", "iso-8859-1"])
@pytest.mark.parametrize("newline", ["\n", "\r\n"])
@pytest.mark.kwparametrize(
dict(exclude=set(), expect=FLYNTED_SOURCE),
dict(exclude={"**/*"}, expect=MODIFIED_SOURCE),
)
def test_maybe_flynt_single_file(git_repo, encoding, newline, exclude, expect):
"""Flynt skipped if path matches exclusion patterns, encoding and newline intact"""
git_repo.add({"test1.py": joinlines(ORIGINAL_SOURCE, newline)}, commit="Initial")
edited_linenums_differ = EditedLinenumsDiffer(
git_repo.root, RevisionRange("HEAD", ":WORKTREE:")
) # pylint: disable=duplicate-code
src = Path("test1.py")
content_ = TextDocument.from_lines(
MODIFIED_SOURCE, encoding=encoding, newline=newline
)

result = darker.__main__._maybe_flynt_single_file(
src, exclude, edited_linenums_differ, content_
)

assert result.lines == expect
assert result.encoding == encoding
assert result.newline == newline


@pytest.mark.kwparametrize(
dict(new_content=TextDocument(), expect=b""),
dict(new_content=TextDocument(lines=["touché"]), expect=b"touch\xc3\xa9\n"),
Expand Down

0 comments on commit ab438ab

Please sign in to comment.