From 752da520713f0cff7f06ebbc729e2d7688f03459 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Wed, 2 Oct 2024 17:51:37 +0300 Subject: [PATCH] test: failing test for isort's skip_glob setting --- src/darker/tests/test_main_isort.py | 31 ++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/darker/tests/test_main_isort.py b/src/darker/tests/test_main_isort.py index 97db9a51c..7207f71a6 100644 --- a/src/darker/tests/test_main_isort.py +++ b/src/darker/tests/test_main_isort.py @@ -1,5 +1,5 @@ """Tests for the ``--isort`` option of the ``darker`` command-line interface.""" - +from textwrap import dedent # pylint: disable=redefined-outer-name,unused-argument,use-dict-literal from types import SimpleNamespace @@ -81,3 +81,32 @@ def test_isort_option_with_isort_calls_sortimports(run_isort, isort_args): settings_path=str(run_isort.root), **isort_args, ) + + +def test_isort_respects_skip_glob(tmp_path, monkeypatch): + """Test that Darker respects isort's skip_glob setting.""" + # Create a pyproject.toml file with isort skip_glob configuration + configuration = dedent( + """ + [tool.isort] + skip_glob = ['*/conf/settings/*'] + filter_files = true + """ + ) + (tmp_path / "pyproject.toml").write_text(configuration) + # Create a file that should be skipped + settings_dir = tmp_path / "conf" / "settings" + settings_dir.mkdir(parents=True) + backoffice_py = settings_dir / "backoffice.py" + backoffice_py.write_text("import sys\nimport os\n") + + # Run darker with --isort + darker.__main__.main(["--isort", str(settings_dir / "backoffice.py")]) + ## Strangely, calling isort as a subprocess instead respects the configuration: + # import subprocess + # subprocess.run( + # f"isort --settings-path={settings_dir} {settings_dir / 'backoffice.py'}", + # shell=True + # ) + + assert backoffice_py.read_text() == "import sys\nimport os\n"