From 72bf7ab022fc18d0d13c6167d0f9c009e35e954e Mon Sep 17 00:00:00 2001 From: Jonas Jelten Date: Thu, 12 Sep 2024 17:55:23 +0200 Subject: [PATCH] fake a ruff executable for testing the executable parameter --- tests/test_ruff_lint.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/test_ruff_lint.py b/tests/test_ruff_lint.py index 2933d26..dd17ef7 100644 --- a/tests/test_ruff_lint.py +++ b/tests/test_ruff_lint.py @@ -1,6 +1,7 @@ # Copyright 2017-2020 Palantir Technologies, Inc. # Copyright 2021- Python Language Server Contributors. +import chmod import os import sys import tempfile @@ -100,17 +101,22 @@ def test_ruff_config_param(workspace): def test_ruff_executable_param(workspace): with patch("pylsp_ruff.plugin.Popen") as popen_mock: - mock_instance = popen_mock.return_value - mock_instance.communicate.return_value = [bytes(), bytes()] + with tempfile.NamedTemporaryFile() as ruff_exe: + mock_instance = popen_mock.return_value + mock_instance.communicate.return_value = [bytes(), bytes()] - ruff_executable = "/tmp/ruff" - workspace._config.update({"plugins": {"ruff": {"executable": ruff_executable}}}) + ruff_executable = ruff_exe.name + # chmod +x the file + st = os.stat(ruff_executable) + os.chmod(ruff_executable, st.st_mode | stat.S_IEXEC) - _name, doc = temp_document(DOC, workspace) - ruff_lint.pylsp_lint(workspace, doc) + workspace._config.update({"plugins": {"ruff": {"executable": ruff_executable}}}) - (call_args,) = popen_mock.call_args[0] - assert ruff_executable in call_args + _name, doc = temp_document(DOC, workspace) + ruff_lint.pylsp_lint(workspace, doc) + + (call_args,) = popen_mock.call_args[0] + assert ruff_executable in call_args def get_ruff_settings(workspace, doc, config_str):