Skip to content

Commit

Permalink
test remove action
Browse files Browse the repository at this point in the history
  • Loading branch information
youben11 committed Nov 14, 2019
1 parent 6812993 commit d178670
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions pyls/plugins/importmagic_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def _get_imports_list(source, index=None):

@hookimpl
def pyls_initialize():
_index_cache['default'] = None
pool = ThreadPoolExecutor()
builder = pool.submit(_build_index, (sys.path))
builder.add_done_callback(_cache_index_callback)
Expand Down
30 changes: 26 additions & 4 deletions test/plugins/test_importmagic_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
from pyls.workspace import Document

DOC_URI = uris.from_fs_path(__file__)
DOC = """
DOC_ADD = """
time.sleep(10)
print("test")
"""
DOC_REMOVE = """
import time
print("useless import")
"""


def temp_document(doc_text):
Expand Down Expand Up @@ -38,10 +42,10 @@ def test_importmagic_lint():
os.remove(name)


def test_importmagic_actions(config):
def test_importmagic_add_import_action(config):
try:
importmagic_lint.pyls_initialize()
name, doc = temp_document(DOC)
name, doc = temp_document(DOC_ADD)
while importmagic_lint._index_cache.get('default') is None:
# wait for the index to be ready
sleep(1)
Expand All @@ -57,4 +61,22 @@ def test_importmagic_actions(config):
finally:
os.remove(name)

# TODO(youben) write test for remove action

def test_importmagic_remove_import_action(config):
try:
importmagic_lint.pyls_initialize()
name, doc = temp_document(DOC_REMOVE)
while importmagic_lint._index_cache.get('default') is None:
# wait for the index to be ready
sleep(1)
actions = importmagic_lint.pyls_code_actions(config, doc)
action = [a for a in actions if a['title'] == 'Remove unused import "time"'][0]
arguments = action['arguments'][0]

assert action['command'] == importmagic_lint.REMOVE_IMPORT_COMMAND
assert arguments['startLine'] == 1
assert arguments['endLine'] == 2
assert arguments['newText'] == ''

finally:
os.remove(name)

0 comments on commit d178670

Please sign in to comment.