Skip to content

Commit 2d523b3

Browse files
committed
address review, reformat
1 parent c82f4b0 commit 2d523b3

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

test/plugins/test_hover.py

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,22 @@ def get_hover_text(result):
7676
def test_hover(workspace) -> None:
7777
# Over 'main' in def main():
7878
hov_position = {"line": 2, "character": 6}
79-
# Over the blank second line
80-
no_hov_position = {"line": 1, "character": 0}
8179

8280
doc = Document(DOC_URI, workspace, DOC)
8381

8482
result = pylsp_hover(doc._config, doc, hov_position)
8583
assert "contents" in result
86-
assert isinstance(result["contents"], list)
87-
assert len(result["contents"]) == 2
88-
# First item is the signature code block
89-
assert result["contents"][0] == {
90-
"language": "python",
91-
"value": "main(a: float, b: float)",
92-
}
93-
# Second item is the docstring
94-
assert "hello world" in result["contents"][1]
95-
96-
assert {"contents": ""} == pylsp_hover(doc._config, doc, no_hov_position)
84+
contents = result["contents"]
85+
if isinstance(contents, list):
86+
assert len(contents) == 2
87+
assert contents[0] == {
88+
"language": "python",
89+
"value": "main(a: float, b: float)",
90+
}
91+
assert "hello world" in contents[1]
92+
else:
93+
assert isinstance(contents, dict) and "value" in contents
94+
assert "hello world" in contents["value"]
9795

9896

9997
def test_hover_signature_formatting(workspace) -> None:
@@ -106,16 +104,14 @@ def test_hover_signature_formatting(workspace) -> None:
106104

107105
result = pylsp_hover(doc._config, doc, hov_position)
108106
assert "contents" in result
109-
assert isinstance(result["contents"], list)
110-
assert len(result["contents"]) == 2
111-
# Due to changes in our fork, hover no longer applies signature formatting
112-
# It just returns the raw signature from Jedi
113-
assert result["contents"][0] == {
114-
"language": "python",
115-
"value": "main(a: float, b: float)",
116-
}
117-
# Second item is the docstring
118-
assert "hello world" in result["contents"][1]
107+
contents = result["contents"]
108+
if isinstance(contents, list):
109+
assert len(contents) == 2
110+
assert contents[0] == {"language": "python", "value": "main(a: float, b: float)"}
111+
assert "hello world" in contents[1]
112+
else:
113+
assert isinstance(contents, dict) and "value" in contents
114+
assert "hello world" in contents["value"]
119115

120116

121117
def test_hover_signature_formatting_opt_out(workspace) -> None:
@@ -127,15 +123,14 @@ def test_hover_signature_formatting_opt_out(workspace) -> None:
127123

128124
result = pylsp_hover(doc._config, doc, hov_position)
129125
assert "contents" in result
130-
assert isinstance(result["contents"], list)
131-
assert len(result["contents"]) == 2
132-
# First item is the signature code block without multiline formatting
133-
assert result["contents"][0] == {
134-
"language": "python",
135-
"value": "main(a: float, b: float)",
136-
}
137-
# Second item is the docstring
138-
assert "hello world" in result["contents"][1]
126+
contents = result["contents"]
127+
if isinstance(contents, list):
128+
assert len(contents) == 2
129+
assert contents[0] == {"language": "python", "value": "main(a: float, b: float)"}
130+
assert "hello world" in contents[1]
131+
else:
132+
assert isinstance(contents, dict) and "value" in contents
133+
assert "hello world" in contents["value"]
139134

140135

141136
def test_document_path_hover(workspace_other_root_path, tmpdir) -> None:

test/plugins/test_type_definition.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Copyright 2021- Python Language Server Contributors.
22

3+
import pytest
4+
35
from pylsp import uris
46
from pylsp.plugins.type_definition import pylsp_type_definition
57
from pylsp.workspace import Document
6-
import pytest
78

89
DOC_URI = uris.from_fs_path(__file__)
910
DOC = """\

0 commit comments

Comments
 (0)