forked from palantir/python-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_completion.py
More file actions
66 lines (47 loc) · 1.8 KB
/
Copy pathtest_completion.py
File metadata and controls
66 lines (47 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Copyright 2017 Palantir Technologies, Inc.
import os
from pyls import uris
from pyls.workspace import Document
from pyls.plugins.jedi_completion import pyls_completions as pyls_jedi_completions
from pyls.plugins.rope_completion import pyls_completions as pyls_rope_completions
LOCATION = os.path.realpath(
os.path.join(os.getcwd(), os.path.dirname(__file__))
)
DOC_URI = uris.from_fs_path(__file__)
DOC = """import os
print os.path.isabs("/tmp")
def hello():
pass
def _a_hello():
pass
"""
def test_rope_import_completion(config, workspace):
com_position = {'line': 0, 'character': 7}
doc = Document(DOC_URI, DOC)
items = pyls_rope_completions(config, workspace, doc, com_position)
assert items is None
def test_jedi_completion():
# Over 'i' in os.path.isabs(...)
com_position = {'line': 1, 'character': 15}
doc = Document(DOC_URI, DOC)
items = pyls_jedi_completions(doc, com_position)
assert items
assert items[0]['label'] == 'isabs(s)'
# Test we don't throw with big character
pyls_jedi_completions(doc, {'line': 1, 'character': 1000})
def test_rope_completion(config, workspace):
# Over 'i' in os.path.isabs(...)
com_position = {'line': 1, 'character': 15}
workspace.put_document(DOC_URI, source=DOC)
doc = workspace.get_document(DOC_URI)
items = pyls_rope_completions(config, workspace, doc, com_position)
assert items
assert items[0]['label'] == 'isabs'
def test_jedi_completion_ordering():
# Over the blank line
com_position = {'line': 8, 'character': 0}
doc = Document(DOC_URI, DOC)
completions = pyls_jedi_completions(doc, com_position)
items = {c['label']: c['sortText'] for c in completions}
# And that 'hidden' functions come after unhidden ones
assert items['hello()'] < items['_a_hello()']