Skip to content

Commit

Permalink
test: --formatter=none with Black installed or not [drop-black-depend…
Browse files Browse the repository at this point in the history
…ency]
  • Loading branch information
akaihola committed Oct 28, 2024
1 parent 4a43af4 commit 5de77da
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/darker/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from darker.help import LINTING_GUIDE
from darker.terminal import output
from darker.tests.examples import A_PY, A_PY_BLACK, A_PY_BLACK_FLYNT, A_PY_BLACK_ISORT
from darker.tests.helpers import black_present
from darker.tests.test_fstring import FLYNTED_SOURCE, MODIFIED_SOURCE, ORIGINAL_SOURCE
from darkgraylib.git import RevisionRange
from darkgraylib.testtools.highlighting_helpers import BLUE, CYAN, RESET, WHITE, YELLOW
Expand Down Expand Up @@ -630,3 +631,32 @@ def test_long_command_length(git_repo):
git_repo.add(files, commit="Add all the files")
result = darker.__main__.main(["--diff", "--check", "src"])
assert result == 0


@pytest.fixture(scope="module")
def formatter_none_repo(git_repo_m):
"""Create a Git repository with a single file and a formatter that does nothing."""
files = git_repo_m.add({"file1.py": "# old content\n"}, commit="Initial")
files["file1.py"].write_text(
"import sys, os\n"
"print ( 'untouched unformatted code' )\n"
)
return files


@pytest.mark.parametrize("has_black", [False, True])
def test_formatter_none(has_black, formatter_none_repo):
"""The dummy formatter works regardless of whether Black is installed or not."""
with black_present(present=has_black):
argv = ["--formatter=none", "--isort", "file1.py"]

result = darker.__main__.main(argv)

assert result == 0
expect = (
"import os\n"
"import sys\n"
"\n"
"print ( 'untouched unformatted code' )\n"
)
assert formatter_none_repo["file1.py"].read_text() == expect

0 comments on commit 5de77da

Please sign in to comment.