|
9 | 9 |
|
10 | 10 | from pylsp import lsp, uris |
11 | 11 | from pylsp.config.config import Config |
12 | | -from pylsp.plugins.rope_autoimport import _get_score, _should_insert, get_names |
| 12 | +from pylsp.plugins.rope_autoimport import ( |
| 13 | + _get_score, |
| 14 | + _should_insert, |
| 15 | + get_name_or_module, |
| 16 | + get_names, |
| 17 | +) |
13 | 18 | from pylsp.plugins.rope_autoimport import ( |
14 | 19 | pylsp_completions as pylsp_autoimport_completions, |
15 | | - pylsp_code_actions as pylsp_autoimport_code_actions, |
16 | 20 | ) |
17 | 21 | from pylsp.plugins.rope_autoimport import pylsp_initialize |
18 | 22 | from pylsp.workspace import Workspace |
@@ -227,26 +231,20 @@ class sfa: |
227 | 231 | "message", |
228 | 232 | ["Undefined name `os`", "F821 undefined name 'numpy'", "undefined name 'numpy'"], |
229 | 233 | ) |
230 | | -def test_autoimport_code_actions(config, autoimport_workspace, message): |
231 | | - source = "os" |
| 234 | +def test_autoimport_code_actions_get_correct_module_name(autoimport_workspace, message): |
| 235 | + source = "os.path.join('a', 'b')" |
232 | 236 | autoimport_workspace.put_document(DOC_URI, source=source) |
233 | 237 | doc = autoimport_workspace.get_document(DOC_URI) |
234 | | - context = { |
235 | | - "diagnostics": [ |
236 | | - { |
237 | | - "range": { |
238 | | - "start": {"line": 0, "character": 0}, |
239 | | - "end": {"line": 0, "character": 2}, |
240 | | - }, |
241 | | - "message": message, |
242 | | - } |
243 | | - ] |
| 238 | + diagnostic = { |
| 239 | + "range": { |
| 240 | + "start": {"line": 0, "character": 0}, |
| 241 | + "end": {"line": 0, "character": 2}, |
| 242 | + }, |
| 243 | + "message": message, |
244 | 244 | } |
245 | | - actions = pylsp_autoimport_code_actions( |
246 | | - config, autoimport_workspace, doc, None, context |
247 | | - ) |
| 245 | + module_name = get_name_or_module(doc, diagnostic) |
248 | 246 | autoimport_workspace.rm_document(DOC_URI) |
249 | | - assert any(action.get("title") == "import os" for action in actions) |
| 247 | + assert module_name == "os" |
250 | 248 |
|
251 | 249 |
|
252 | 250 | # rope autoimport launches a sqlite database which checks from which thread it is called. |
|
0 commit comments