Skip to content

Commit d9993ae

Browse files
committed
fake a ruff executable for testing the executable parameter
1 parent 40640cd commit d9993ae

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

tests/test_ruff_lint.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright 2021- Python Language Server Contributors.
33

44
import os
5+
import stat
56
import sys
67
import tempfile
78
from unittest.mock import Mock, patch
@@ -100,17 +101,24 @@ def test_ruff_config_param(workspace):
100101

101102
def test_ruff_executable_param(workspace):
102103
with patch("pylsp_ruff.plugin.Popen") as popen_mock:
103-
mock_instance = popen_mock.return_value
104-
mock_instance.communicate.return_value = [bytes(), bytes()]
104+
with tempfile.NamedTemporaryFile() as ruff_exe:
105+
mock_instance = popen_mock.return_value
106+
mock_instance.communicate.return_value = [bytes(), bytes()]
105107

106-
ruff_executable = "/tmp/ruff"
107-
workspace._config.update({"plugins": {"ruff": {"executable": ruff_executable}}})
108+
ruff_executable = ruff_exe.name
109+
# chmod +x the file
110+
st = os.stat(ruff_executable)
111+
os.chmod(ruff_executable, st.st_mode | stat.S_IEXEC)
108112

109-
_name, doc = temp_document(DOC, workspace)
110-
ruff_lint.pylsp_lint(workspace, doc)
113+
workspace._config.update(
114+
{"plugins": {"ruff": {"executable": ruff_executable}}}
115+
)
111116

112-
(call_args,) = popen_mock.call_args[0]
113-
assert ruff_executable in call_args
117+
_name, doc = temp_document(DOC, workspace)
118+
ruff_lint.pylsp_lint(workspace, doc)
119+
120+
(call_args,) = popen_mock.call_args[0]
121+
assert ruff_executable in call_args
114122

115123

116124
def get_ruff_settings(workspace, doc, config_str):

0 commit comments

Comments
 (0)