77from pyls .workspace import Document
88
99DOC_URI = uris .from_fs_path (__file__ )
10- DOC = """
10+ DOC_ADD = """
1111time.sleep(10)
1212print("test")
1313"""
14+ DOC_REMOVE = """
15+ import time
16+ print("useless import")
17+ """
1418
1519
1620def 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