Skip to content

Commit

Permalink
Fix: Don't double unwrap config (#46)
Browse files Browse the repository at this point in the history
* Don't double unwrap config

Config values passed via pyproject.toml weren't being
found because the config was being xx
  • Loading branch information
grahamtt authored Nov 2, 2023
1 parent debfaec commit 401d42f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 1 addition & 2 deletions autohooks/plugins/ruff/ruff.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ def get_ruff_arguments(config: Optional[Config]) -> Iterable[str]:
if not config:
return DEFAULT_ARGUMENTS

ruff_config = get_ruff_config(config)
arguments = ensure_iterable(
ruff_config.get_value("arguments", DEFAULT_ARGUMENTS)
config.get_value("arguments", DEFAULT_ARGUMENTS)
)

return arguments
Expand Down
17 changes: 13 additions & 4 deletions tests/test_ruff.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def test_ruff_installed(self):
), patch("importlib.util.find_spec", return_value=None):
check_ruff_installed()

def test_get_ruff_config(self):
def test_get_ruff_config(
self,
):
config_path = get_test_config_path("pyproject.test.toml")
self.assertTrue(config_path.is_file())

Expand All @@ -50,12 +52,19 @@ def test_get_default_ruff_arguments(self):
args = get_ruff_arguments(None)
self.assertEqual(args, DEFAULT_ARGUMENTS)

def test_get_ruff_arguments(self):
@patch("autohooks.plugins.ruff.ruff.get_ruff_config")
def test_get_ruff_arguments(
self,
_get_ruff_config: MagicMock,
):
config_path = get_test_config_path("pyproject.test.toml")
args = get_ruff_arguments(
load_config_from_pyproject_toml(config_path).get_config()
load_config_from_pyproject_toml(config_path)
.get_config()
.get("tool", "autohooks", "plugins", "ruff")
)
self.assertEqual(args, ["--test", "foo,bar", "--foo", "bar"])
_get_ruff_config.assert_not_called()

@patch("autohooks.plugins.ruff.ruff.get_staged_status")
def test_precommit_no_files(
Expand All @@ -79,7 +88,7 @@ def test_precommit_errors(
error_mock: MagicMock,
out_mock: MagicMock,
ok_mock: MagicMock,
_get_ruff_config,
_get_ruff_config: MagicMock,
get_ruff_arguments_mock: MagicMock,
):
code = """import subprocess
Expand Down

0 comments on commit 401d42f

Please sign in to comment.