@@ -76,24 +76,22 @@ def get_hover_text(result):
7676def 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
9997def 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
121117def 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
141136def test_document_path_hover (workspace_other_root_path , tmpdir ) -> None :
0 commit comments