7
7
from pyls .workspace import Document
8
8
9
9
DOC_URI = uris .from_fs_path (__file__ )
10
- DOC = """
10
+ DOC_ADD = """
11
11
time.sleep(10)
12
12
print("test")
13
13
"""
14
+ DOC_REMOVE = """
15
+ import time
16
+ print("useless import")
17
+ """
14
18
15
19
16
20
def temp_document (doc_text ):
@@ -38,10 +42,10 @@ def test_importmagic_lint():
38
42
os .remove (name )
39
43
40
44
41
- def test_importmagic_actions (config ):
45
+ def test_importmagic_add_import_action (config ):
42
46
try :
43
47
importmagic_lint .pyls_initialize ()
44
- name , doc = temp_document (DOC )
48
+ name , doc = temp_document (DOC_ADD )
45
49
while importmagic_lint ._index_cache .get ('default' ) is None :
46
50
# wait for the index to be ready
47
51
sleep (1 )
@@ -57,4 +61,22 @@ def test_importmagic_actions(config):
57
61
finally :
58
62
os .remove (name )
59
63
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