|
23 | 23 | # Local imports
|
24 | 24 | from spyder.config.base import running_in_ci, running_in_ci_with_conda
|
25 | 25 | from spyder.config.utils import is_anaconda
|
| 26 | +from spyder.plugins.completion.api import ( |
| 27 | + CompletionRequestTypes, CompletionItemKind) |
| 28 | +from spyder.plugins.completion.providers.languageserver.providers.utils import ( |
| 29 | + path_as_uri) |
26 | 30 | from spyder.plugins.completion.providers.kite.utils.status import (
|
27 | 31 | check_if_kite_installed, check_if_kite_running)
|
28 | 32 | from spyder.py3compat import PY2
|
@@ -1178,5 +1182,75 @@ def test_completions_environment(completions_codeeditor, qtbot, tmpdir):
|
1178 | 1182 | completion_plugin.after_configuration_update([])
|
1179 | 1183 |
|
1180 | 1184 |
|
| 1185 | +@pytest.mark.slow |
| 1186 | +@pytest.mark.order(1) |
| 1187 | +@flaky(max_runs=5) |
| 1188 | +def test_dot_completions(completions_codeeditor, qtbot): |
| 1189 | + """ |
| 1190 | + Test that completions after a dot are working as expected. |
| 1191 | +
|
| 1192 | + This is a regression test for issue spyder-ide/spyder#20285 |
| 1193 | + """ |
| 1194 | + code_editor, _ = completions_codeeditor |
| 1195 | + completion = code_editor.completion_widget |
| 1196 | + |
| 1197 | + # Import module and check completions are shown for it after writing a dot |
| 1198 | + # after it |
| 1199 | + qtbot.keyClicks(code_editor, "import math") |
| 1200 | + qtbot.keyPress(code_editor, Qt.Key_Enter) |
| 1201 | + |
| 1202 | + qtbot.wait(500) |
| 1203 | + assert not completion.isVisible() |
| 1204 | + |
| 1205 | + with qtbot.waitSignal(completion.sig_show_completions, timeout=10000): |
| 1206 | + qtbot.keyClicks(code_editor, "math.") |
| 1207 | + |
| 1208 | + qtbot.wait(500) |
| 1209 | + assert completion.isVisible() |
| 1210 | + |
| 1211 | + |
| 1212 | +@pytest.mark.slow |
| 1213 | +@pytest.mark.order(1) |
| 1214 | +def test_completions_for_files_that_start_with_numbers( |
| 1215 | + mock_completions_codeeditor, qtbot): |
| 1216 | + """ |
| 1217 | + Test that completions for files that start with numbers are handled as |
| 1218 | + expected. |
| 1219 | +
|
| 1220 | + This is a regression test for issue spyder-ide/spyder#20156 |
| 1221 | + """ |
| 1222 | + code_editor, mock_response = mock_completions_codeeditor |
| 1223 | + completion = code_editor.completion_widget |
| 1224 | + file_name = '000_testing.txt' |
| 1225 | + |
| 1226 | + # Set text to complete and move cursor to the position we want to ask for |
| 1227 | + # completions. |
| 1228 | + qtbot.keyClicks(code_editor, "'0'") |
| 1229 | + code_editor.moveCursor(QTextCursor.PreviousCharacter) |
| 1230 | + qtbot.wait(500) |
| 1231 | + |
| 1232 | + # Complete '0' -> '000_testing.txt' |
| 1233 | + mock_response.side_effect = lambda lang, method, params: {'params': [{ |
| 1234 | + 'label': f'{file_name}', |
| 1235 | + 'kind': CompletionItemKind.FILE, |
| 1236 | + 'sortText': (0, f'a{file_name}'), |
| 1237 | + 'insertText': f'{file_name}', |
| 1238 | + 'data': {'doc_uri': path_as_uri(__file__)}, |
| 1239 | + 'detail': '', |
| 1240 | + 'documentation': '', |
| 1241 | + 'filterText': f'{file_name}', |
| 1242 | + 'insertTextFormat': 1, |
| 1243 | + 'provider': 'LSP', |
| 1244 | + 'resolve': True |
| 1245 | + }]} if method == CompletionRequestTypes.DOCUMENT_COMPLETION else None |
| 1246 | + |
| 1247 | + with qtbot.waitSignal(completion.sig_show_completions, |
| 1248 | + timeout=10000): |
| 1249 | + qtbot.keyPress(code_editor, Qt.Key_Tab, delay=300) |
| 1250 | + |
| 1251 | + qtbot.wait(500) |
| 1252 | + assert code_editor.get_text_with_eol() == f"'{file_name}'" |
| 1253 | + |
| 1254 | + |
1181 | 1255 | if __name__ == '__main__':
|
1182 | 1256 | pytest.main(['test_introspection.py', '--run-slow'])
|
0 commit comments