From 752d51fb49ae1de0ca25d2c269b9c83b229642cc Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:50:45 +0200 Subject: [PATCH] test: --formatter=none with Black installed or not --- src/darker/tests/test_main.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/darker/tests/test_main.py b/src/darker/tests/test_main.py index 446690ee7..c57d6ec75 100644 --- a/src/darker/tests/test_main.py +++ b/src/darker/tests/test_main.py @@ -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 @@ -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