Skip to content

Commit d178670

Browse files
committed
test remove action
1 parent 6812993 commit d178670

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

pyls/plugins/importmagic_lint.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def _get_imports_list(source, index=None):
6464

6565
@hookimpl
6666
def pyls_initialize():
67+
_index_cache['default'] = None
6768
pool = ThreadPoolExecutor()
6869
builder = pool.submit(_build_index, (sys.path))
6970
builder.add_done_callback(_cache_index_callback)

test/plugins/test_importmagic_lint.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
from pyls.workspace import Document
88

99
DOC_URI = uris.from_fs_path(__file__)
10-
DOC = """
10+
DOC_ADD = """
1111
time.sleep(10)
1212
print("test")
1313
"""
14+
DOC_REMOVE = """
15+
import time
16+
print("useless import")
17+
"""
1418

1519

1620
def temp_document(doc_text):
@@ -38,10 +42,10 @@ def test_importmagic_lint():
3842
os.remove(name)
3943

4044

41-
def test_importmagic_actions(config):
45+
def test_importmagic_add_import_action(config):
4246
try:
4347
importmagic_lint.pyls_initialize()
44-
name, doc = temp_document(DOC)
48+
name, doc = temp_document(DOC_ADD)
4549
while importmagic_lint._index_cache.get('default') is None:
4650
# wait for the index to be ready
4751
sleep(1)
@@ -57,4 +61,22 @@ def test_importmagic_actions(config):
5761
finally:
5862
os.remove(name)
5963

60-
# TODO(youben) write test for remove action
64+
65+
def test_importmagic_remove_import_action(config):
66+
try:
67+
importmagic_lint.pyls_initialize()
68+
name, doc = temp_document(DOC_REMOVE)
69+
while importmagic_lint._index_cache.get('default') is None:
70+
# wait for the index to be ready
71+
sleep(1)
72+
actions = importmagic_lint.pyls_code_actions(config, doc)
73+
action = [a for a in actions if a['title'] == 'Remove unused import "time"'][0]
74+
arguments = action['arguments'][0]
75+
76+
assert action['command'] == importmagic_lint.REMOVE_IMPORT_COMMAND
77+
assert arguments['startLine'] == 1
78+
assert arguments['endLine'] == 2
79+
assert arguments['newText'] == ''
80+
81+
finally:
82+
os.remove(name)

0 commit comments

Comments
 (0)