@@ -1209,7 +1209,7 @@ def test_dot_completions(completions_codeeditor, qtbot):
1209
1209
qtbot .wait (500 )
1210
1210
assert completion .isVisible ()
1211
1211
1212
- # Select a raondom entry in the completion widget
1212
+ # Select a random entry in the completion widget
1213
1213
entry_index = random .randint (0 , 30 )
1214
1214
inserted_entry = completion .completion_list [entry_index ]['insertText' ]
1215
1215
for _ in range (entry_index ):
@@ -1225,7 +1225,7 @@ def test_dot_completions(completions_codeeditor, qtbot):
1225
1225
@pytest .mark .order (1 )
1226
1226
@pytest .mark .parametrize (
1227
1227
"filename" , ['000_test.txt' , '.hidden' , 'any_file.txt' , 'abc.py' ,
1228
- 'part.0.parquet' , '/home' , '/usr/bin' , r'C:\\Users' ])
1228
+ 'part.0.parquet' ])
1229
1229
def test_file_completions (filename , mock_completions_codeeditor , qtbot ):
1230
1230
"""
1231
1231
Test that completions for files are handled as expected.
@@ -1249,40 +1249,20 @@ def test_file_completions(filename, mock_completions_codeeditor, qtbot):
1249
1249
# This checks that we can insert file completions next to a dot when a
1250
1250
# filename has several dots.
1251
1251
qtbot .keyClicks (code_editor , "'part.0.'" )
1252
- elif filename == '/home' :
1253
- # This checks that we can insert file completions next to a /
1254
- qtbot .keyClicks (code_editor , "'/'" )
1255
- elif filename == '/usr/bin' :
1256
- # This checks that we can insert file completions next to a / placed at
1257
- # second-level
1258
- qtbot .keyClicks (code_editor , "'/usr/'" )
1259
- elif filename == r'C:\\Users' :
1260
- # This checks that we can insert file completions next to a \
1261
- qtbot .keyClicks (code_editor , r"'C:\\'" )
1262
1252
else :
1263
1253
qtbot .keyClicks (code_editor , f"'{ filename [0 ]} '" )
1264
1254
code_editor .moveCursor (QTextCursor .PreviousCharacter )
1265
1255
qtbot .wait (500 )
1266
1256
1267
- # Set text that will be completed
1268
- if filename == '/home' :
1269
- completion_text = 'home'
1270
- elif filename == '/usr/bin' :
1271
- completion_text = 'bin'
1272
- elif filename == r'C:\\Users' :
1273
- completion_text = 'Users'
1274
- else :
1275
- completion_text = filename
1276
-
1277
1257
mock_response .side_effect = lambda lang , method , params : {'params' : [{
1278
- 'label' : f'{ completion_text } ' ,
1258
+ 'label' : f'{ filename } ' ,
1279
1259
'kind' : CompletionItemKind .FILE ,
1280
- 'sortText' : (0 , f'a{ completion_text } ' ),
1281
- 'insertText' : f'{ completion_text } ' ,
1260
+ 'sortText' : (0 , f'a{ filename } ' ),
1261
+ 'insertText' : f'{ filename } ' ,
1282
1262
'data' : {'doc_uri' : path_as_uri (__file__ )},
1283
1263
'detail' : '' ,
1284
1264
'documentation' : '' ,
1285
- 'filterText' : f'{ completion_text } ' ,
1265
+ 'filterText' : f'{ filename } ' ,
1286
1266
'insertTextFormat' : 1 ,
1287
1267
'provider' : 'LSP' ,
1288
1268
'resolve' : True
@@ -1296,5 +1276,83 @@ def test_file_completions(filename, mock_completions_codeeditor, qtbot):
1296
1276
assert code_editor .get_text_with_eol () == f"'{ filename } '"
1297
1277
1298
1278
1279
+ @pytest .mark .slow
1280
+ @pytest .mark .order (1 )
1281
+ @pytest .mark .parametrize (
1282
+ "directory" ,
1283
+ [
1284
+ pytest .param (
1285
+ '/home' ,
1286
+ marks = pytest .mark .skipif (
1287
+ not sys .platform .startswith ('linux' ),
1288
+ reason = 'Only works on Linux'
1289
+ )
1290
+ ),
1291
+ pytest .param (
1292
+ 'C:\\ Users' ,
1293
+ marks = pytest .mark .skipif (
1294
+ not os .name == 'nt' ,
1295
+ reason = 'Only works on Windows'
1296
+ )
1297
+ ),
1298
+ pytest .param (
1299
+ 'C:\\ Windows\\ System32' ,
1300
+ marks = pytest .mark .skipif (
1301
+ not os .name == 'nt' ,
1302
+ reason = 'Only works on Windows'
1303
+ )
1304
+ ),
1305
+ pytest .param (
1306
+ '/Library/Frameworks' ,
1307
+ marks = pytest .mark .skipif (
1308
+ not sys .platform == 'darwin' ,
1309
+ reason = 'Only works on macOS'
1310
+ )
1311
+ )
1312
+ ]
1313
+ )
1314
+ def test_directory_completions (directory , completions_codeeditor , qtbot ):
1315
+ """
1316
+ Test that directory completions work as expected.
1317
+ """
1318
+ code_editor , _ = completions_codeeditor
1319
+ completion = code_editor .completion_widget
1320
+
1321
+ qtbot .wait (500 )
1322
+ assert not completion .isVisible ()
1323
+
1324
+ if directory == '/home' :
1325
+ qtbot .keyClicks (code_editor , "'/'" )
1326
+ elif directory == 'C:\\ Users' :
1327
+ qtbot .keyClicks (code_editor , r"'C:\\'" )
1328
+ elif directory == 'C:\\ Windows\\ System32' :
1329
+ qtbot .keyClicks (code_editor , r"'C:\\Windows\\'" )
1330
+ else :
1331
+ qtbot .keyClicks (code_editor , "'/Library/'" )
1332
+
1333
+ code_editor .moveCursor (QTextCursor .PreviousCharacter )
1334
+ with qtbot .waitSignal (completion .sig_show_completions ,
1335
+ timeout = 10000 ):
1336
+ qtbot .keyPress (code_editor , Qt .Key_Tab , delay = 300 )
1337
+
1338
+ qtbot .wait (500 )
1339
+ assert completion .isVisible ()
1340
+
1341
+ # Select the corresponding entry in the completion widget
1342
+ selected_entry = False
1343
+ while not selected_entry :
1344
+ item = completion .currentItem ()
1345
+ label = item .data (Qt .AccessibleTextRole ).split ()[0 ]
1346
+ if directory .split (os .sep )[- 1 ] in label :
1347
+ selected_entry = True
1348
+ else :
1349
+ qtbot .keyPress (completion , Qt .Key_Down , delay = 50 )
1350
+
1351
+ # Insert completion and check that the inserted text is the expected one
1352
+ qtbot .keyPress (completion , Qt .Key_Enter )
1353
+ qtbot .wait (500 )
1354
+ assert code_editor .toPlainText () == f"'{ directory } { os .sep } '"
1355
+
1356
+
1299
1357
if __name__ == '__main__' :
1300
1358
pytest .main (['test_introspection.py' , '--run-slow' ])
0 commit comments