1+ # Standard library imports
12import types
23from pathlib import Path
34from unittest .mock import Mock
45
6+ # Third-party imports
57import black
68import pkg_resources
79import pytest
8- from pyls import uris
9- from pyls .workspace import Document , Workspace
1010
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
1217
1318here = Path (__file__ ).parent
1419fixtures_dir = here / "fixtures"
@@ -62,8 +67,8 @@ def config_document(workspace):
6267 return Document (uri , workspace )
6368
6469
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 )
6772
6873 assert result == [
6974 {
@@ -77,7 +82,7 @@ def test_pyls_format_document(unformatted_document, formatted_document):
7782
7883
7984def 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 )
8186
8287 assert result == [
8388 {
@@ -90,26 +95,26 @@ def test_pyls_format_pyi_document(unformatted_pyi_document, formatted_pyi_docume
9095 ]
9196
9297
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 )
95100
96101 assert result == []
97102
98103
99104def 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 )
101106
102107 assert result == []
103108
104109
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 )
107112
108113 assert result == []
109114
110115
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 )
113118
114119 assert result == [
115120 {
@@ -134,13 +139,13 @@ def test_pyls_format_document_with_config(config_document):
134139 ("start" , "end" , "expected" ),
135140 [(0 , 0 , 'a = "hello"\n ' ), (1 , 1 , "b = 42\n " ), (0 , 1 , 'a = "hello"\n b = 42\n ' )],
136141)
137- def test_pyls_format_range (unformatted_document , start , end , expected ):
142+ def test_pylsp_format_range (unformatted_document , start , end , expected ):
138143 range = {
139144 "start" : {"line" : start , "character" : 0 },
140145 "end" : {"line" : end , "character" : 0 },
141146 }
142147
143- result = pyls_format_range (unformatted_document , range = range )
148+ result = pylsp_format_range (unformatted_document , range = range )
144149
145150 assert result == [
146151 {
@@ -153,18 +158,18 @@ def test_pyls_format_range(unformatted_document, start, end, expected):
153158 ]
154159
155160
156- def test_pyls_format_range_unchanged (formatted_document ):
161+ def test_pylsp_format_range_unchanged (formatted_document ):
157162 range = {"start" : {"line" : 0 , "character" : 0 }, "end" : {"line" : 1 , "character" : 0 }}
158163
159- result = pyls_format_range (formatted_document , range = range )
164+ result = pylsp_format_range (formatted_document , range = range )
160165
161166 assert result == []
162167
163168
164- def test_pyls_format_range_syntax_error (invalid_document ):
169+ def test_pylsp_format_range_syntax_error (invalid_document ):
165170 range = {"start" : {"line" : 0 , "character" : 0 }, "end" : {"line" : 1 , "character" : 0 }}
166171
167- result = pyls_format_range (invalid_document , range = range )
172+ result = pylsp_format_range (invalid_document , range = range )
168173
169174 assert result == []
170175
@@ -191,7 +196,12 @@ def test_load_config_target_version():
191196def test_load_config_py36 ():
192197 config = load_config (str (fixtures_dir / "py36" / "example.py" ))
193198
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+ }
195205
196206
197207def test_load_config_defaults ():
@@ -207,8 +217,8 @@ def test_load_config_defaults():
207217
208218
209219def 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 " )
212222
213223 assert entry_point is not None
214224
0 commit comments