forked from palantir/python-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_yapf_format.py
More file actions
58 lines (39 loc) · 1.5 KB
/
Copy pathtest_yapf_format.py
File metadata and controls
58 lines (39 loc) · 1.5 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
# Copyright 2017 Palantir Technologies, Inc.
from pyls import uris
from pyls.plugins.yapf_format import pyls_format_document, pyls_format_range
from pyls.workspace import Document
DOC_URI = uris.from_fs_path(__file__)
DOC = """A = [
'h', 'w',
'a'
]
B = ['h',
'w']
"""
GOOD_DOC = """A = ['hello', 'world']\n"""
def test_format(workspace):
doc = Document(DOC_URI, workspace, DOC)
res = pyls_format_document(doc)
assert len(res) == 1
assert res[0]['newText'] == "A = ['h', 'w', 'a']\n\nB = ['h', 'w']\n"
def test_range_format(workspace):
doc = Document(DOC_URI, workspace, DOC)
def_range = {
'start': {'line': 0, 'character': 0},
'end': {'line': 4, 'character': 10}
}
res = pyls_format_range(doc, def_range)
assert len(res) == 1
# Make sure B is still badly formatted
assert res[0]['newText'] == "A = ['h', 'w', 'a']\n\nB = ['h',\n\n\n'w']\n"
def test_no_change(workspace):
doc = Document(DOC_URI, workspace, GOOD_DOC)
assert not pyls_format_document(doc)
def test_config_file(tmpdir, workspace):
# a config file in the same directory as the source file will be used
conf = tmpdir.join('.style.yapf')
conf.write('[style]\ncolumn_limit = 14')
src = tmpdir.join('test.py')
doc = Document(uris.from_fs_path(src.strpath), workspace, DOC)
# A was split on multiple lines because of column_limit from config file
assert pyls_format_document(doc)[0]['newText'] == "A = [\n 'h', 'w',\n 'a'\n]\n\nB = ['h', 'w']\n"