1
+ # Standard library imports
1
2
import types
2
3
from pathlib import Path
3
4
from unittest .mock import Mock
4
5
6
+ # Third-party imports
5
7
import black
6
8
import pkg_resources
7
9
import pytest
8
- from pyls import uris
9
- from pyls .workspace import Document , Workspace
10
10
11
- from pyls_black .plugin import load_config , pyls_format_document , pyls_format_range
11
+ # Python LSP imports
12
+ from pylsp import uris
13
+ from pylsp .workspace import Document , Workspace
14
+
15
+ # Local imports
16
+ from pylsp_black .plugin import load_config , pylsp_format_document , pylsp_format_range
12
17
13
18
here = Path (__file__ ).parent
14
19
fixtures_dir = here / "fixtures"
@@ -62,8 +67,8 @@ def config_document(workspace):
62
67
return Document (uri , workspace )
63
68
64
69
65
- def test_pyls_format_document (unformatted_document , formatted_document ):
66
- result = pyls_format_document (unformatted_document )
70
+ def test_pylsp_format_document (unformatted_document , formatted_document ):
71
+ result = pylsp_format_document (unformatted_document )
67
72
68
73
assert result == [
69
74
{
@@ -77,7 +82,7 @@ def test_pyls_format_document(unformatted_document, formatted_document):
77
82
78
83
79
84
def test_pyls_format_pyi_document (unformatted_pyi_document , formatted_pyi_document ):
80
- result = pyls_format_document (unformatted_pyi_document )
85
+ result = pylsp_format_document (unformatted_pyi_document )
81
86
82
87
assert result == [
83
88
{
@@ -90,26 +95,26 @@ def test_pyls_format_pyi_document(unformatted_pyi_document, formatted_pyi_docume
90
95
]
91
96
92
97
93
- def test_pyls_format_document_unchanged (formatted_document ):
94
- result = pyls_format_document (formatted_document )
98
+ def test_pylsp_format_document_unchanged (formatted_document ):
99
+ result = pylsp_format_document (formatted_document )
95
100
96
101
assert result == []
97
102
98
103
99
104
def test_pyls_format_pyi_document_unchanged (formatted_pyi_document ):
100
- result = pyls_format_document (formatted_pyi_document )
105
+ result = pylsp_format_document (formatted_pyi_document )
101
106
102
107
assert result == []
103
108
104
109
105
- def test_pyls_format_document_syntax_error (invalid_document ):
106
- result = pyls_format_document (invalid_document )
110
+ def test_pylsp_format_document_syntax_error (invalid_document ):
111
+ result = pylsp_format_document (invalid_document )
107
112
108
113
assert result == []
109
114
110
115
111
- def test_pyls_format_document_with_config (config_document ):
112
- result = pyls_format_document (config_document )
116
+ def test_pylsp_format_document_with_config (config_document ):
117
+ result = pylsp_format_document (config_document )
113
118
114
119
assert result == [
115
120
{
@@ -134,13 +139,13 @@ def test_pyls_format_document_with_config(config_document):
134
139
("start" , "end" , "expected" ),
135
140
[(0 , 0 , 'a = "hello"\n ' ), (1 , 1 , "b = 42\n " ), (0 , 1 , 'a = "hello"\n b = 42\n ' )],
136
141
)
137
- def test_pyls_format_range (unformatted_document , start , end , expected ):
142
+ def test_pylsp_format_range (unformatted_document , start , end , expected ):
138
143
range = {
139
144
"start" : {"line" : start , "character" : 0 },
140
145
"end" : {"line" : end , "character" : 0 },
141
146
}
142
147
143
- result = pyls_format_range (unformatted_document , range = range )
148
+ result = pylsp_format_range (unformatted_document , range = range )
144
149
145
150
assert result == [
146
151
{
@@ -153,18 +158,18 @@ def test_pyls_format_range(unformatted_document, start, end, expected):
153
158
]
154
159
155
160
156
- def test_pyls_format_range_unchanged (formatted_document ):
161
+ def test_pylsp_format_range_unchanged (formatted_document ):
157
162
range = {"start" : {"line" : 0 , "character" : 0 }, "end" : {"line" : 1 , "character" : 0 }}
158
163
159
- result = pyls_format_range (formatted_document , range = range )
164
+ result = pylsp_format_range (formatted_document , range = range )
160
165
161
166
assert result == []
162
167
163
168
164
- def test_pyls_format_range_syntax_error (invalid_document ):
169
+ def test_pylsp_format_range_syntax_error (invalid_document ):
165
170
range = {"start" : {"line" : 0 , "character" : 0 }, "end" : {"line" : 1 , "character" : 0 }}
166
171
167
- result = pyls_format_range (invalid_document , range = range )
172
+ result = pylsp_format_range (invalid_document , range = range )
168
173
169
174
assert result == []
170
175
@@ -191,7 +196,12 @@ def test_load_config_target_version():
191
196
def test_load_config_py36 ():
192
197
config = load_config (str (fixtures_dir / "py36" / "example.py" ))
193
198
194
- assert config ["target_version" ] == black .PY36_VERSIONS
199
+ assert config ["target_version" ] == {
200
+ black .TargetVersion .PY36 ,
201
+ black .TargetVersion .PY37 ,
202
+ black .TargetVersion .PY38 ,
203
+ black .TargetVersion .PY39 ,
204
+ }
195
205
196
206
197
207
def test_load_config_defaults ():
@@ -207,8 +217,8 @@ def test_load_config_defaults():
207
217
208
218
209
219
def test_entry_point ():
210
- distribution = pkg_resources .get_distribution ("pyls -black" )
211
- entry_point = distribution .get_entry_info ("pyls " , "pyls_black " )
220
+ distribution = pkg_resources .get_distribution ("python-lsp -black" )
221
+ entry_point = distribution .get_entry_info ("pylsp " , "pylsp_black " )
212
222
213
223
assert entry_point is not None
214
224
0 commit comments