@@ -10,11 +10,13 @@ import * as windowApis from '../../../../client/common/vscodeApis/windowApis';
10
10
import * as workspaceApis from '../../../../client/common/vscodeApis/workspaceApis' ;
11
11
import {
12
12
ExistingVenvAction ,
13
+ OPEN_REQUIREMENTS_BUTTON ,
13
14
pickExistingVenvAction ,
14
15
pickPackagesToInstall ,
15
16
} from '../../../../client/pythonEnvironments/creation/provider/venvUtils' ;
16
17
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../../constants' ;
17
18
import { CreateEnv } from '../../../../client/common/utils/localize' ;
19
+ import { createDeferred } from '../../../../client/common/utils/async' ;
18
20
19
21
chaiUse ( chaiAsPromised ) ;
20
22
@@ -23,6 +25,7 @@ suite('Venv Utils test', () => {
23
25
let showQuickPickWithBackStub : sinon . SinonStub ;
24
26
let pathExistsStub : sinon . SinonStub ;
25
27
let readFileStub : sinon . SinonStub ;
28
+ let showTextDocumentStub : sinon . SinonStub ;
26
29
27
30
const workspace1 = {
28
31
uri : Uri . file ( path . join ( EXTENSION_ROOT_DIR_FOR_TESTS , 'src' , 'testMultiRootWkspc' , 'workspace1' ) ) ,
@@ -35,6 +38,7 @@ suite('Venv Utils test', () => {
35
38
showQuickPickWithBackStub = sinon . stub ( windowApis , 'showQuickPickWithBack' ) ;
36
39
pathExistsStub = sinon . stub ( fs , 'pathExists' ) ;
37
40
readFileStub = sinon . stub ( fs , 'readFile' ) ;
41
+ showTextDocumentStub = sinon . stub ( windowApis , 'showTextDocument' ) ;
38
42
} ) ;
39
43
40
44
teardown ( ( ) => {
@@ -224,13 +228,18 @@ suite('Venv Utils test', () => {
224
228
await assert . isRejected ( pickPackagesToInstall ( workspace1 ) ) ;
225
229
assert . isTrue (
226
230
showQuickPickWithBackStub . calledWithExactly (
227
- [ { label : 'requirements.txt' } , { label : 'dev-requirements.txt' } , { label : 'test-requirements.txt' } ] ,
231
+ [
232
+ { label : 'requirements.txt' , buttons : [ OPEN_REQUIREMENTS_BUTTON ] } ,
233
+ { label : 'dev-requirements.txt' , buttons : [ OPEN_REQUIREMENTS_BUTTON ] } ,
234
+ { label : 'test-requirements.txt' , buttons : [ OPEN_REQUIREMENTS_BUTTON ] } ,
235
+ ] ,
228
236
{
229
237
placeHolder : CreateEnv . Venv . requirementsQuickPickTitle ,
230
238
ignoreFocusOut : true ,
231
239
canPickMany : true ,
232
240
} ,
233
241
undefined ,
242
+ sinon . match . func ,
234
243
) ,
235
244
) ;
236
245
assert . isTrue ( readFileStub . calledOnce ) ;
@@ -257,13 +266,18 @@ suite('Venv Utils test', () => {
257
266
const actual = await pickPackagesToInstall ( workspace1 ) ;
258
267
assert . isTrue (
259
268
showQuickPickWithBackStub . calledWithExactly (
260
- [ { label : 'requirements.txt' } , { label : 'dev-requirements.txt' } , { label : 'test-requirements.txt' } ] ,
269
+ [
270
+ { label : 'requirements.txt' , buttons : [ OPEN_REQUIREMENTS_BUTTON ] } ,
271
+ { label : 'dev-requirements.txt' , buttons : [ OPEN_REQUIREMENTS_BUTTON ] } ,
272
+ { label : 'test-requirements.txt' , buttons : [ OPEN_REQUIREMENTS_BUTTON ] } ,
273
+ ] ,
261
274
{
262
275
placeHolder : CreateEnv . Venv . requirementsQuickPickTitle ,
263
276
ignoreFocusOut : true ,
264
277
canPickMany : true ,
265
278
} ,
266
279
undefined ,
280
+ sinon . match . func ,
267
281
) ,
268
282
) ;
269
283
assert . deepStrictEqual ( actual , [ ] ) ;
@@ -290,13 +304,18 @@ suite('Venv Utils test', () => {
290
304
const actual = await pickPackagesToInstall ( workspace1 ) ;
291
305
assert . isTrue (
292
306
showQuickPickWithBackStub . calledWithExactly (
293
- [ { label : 'requirements.txt' } , { label : 'dev-requirements.txt' } , { label : 'test-requirements.txt' } ] ,
307
+ [
308
+ { label : 'requirements.txt' , buttons : [ OPEN_REQUIREMENTS_BUTTON ] } ,
309
+ { label : 'dev-requirements.txt' , buttons : [ OPEN_REQUIREMENTS_BUTTON ] } ,
310
+ { label : 'test-requirements.txt' , buttons : [ OPEN_REQUIREMENTS_BUTTON ] } ,
311
+ ] ,
294
312
{
295
313
placeHolder : CreateEnv . Venv . requirementsQuickPickTitle ,
296
314
ignoreFocusOut : true ,
297
315
canPickMany : true ,
298
316
} ,
299
317
undefined ,
318
+ sinon . match . func ,
300
319
) ,
301
320
) ;
302
321
assert . deepStrictEqual ( actual , [
@@ -328,13 +347,18 @@ suite('Venv Utils test', () => {
328
347
const actual = await pickPackagesToInstall ( workspace1 ) ;
329
348
assert . isTrue (
330
349
showQuickPickWithBackStub . calledWithExactly (
331
- [ { label : 'requirements.txt' } , { label : 'dev-requirements.txt' } , { label : 'test-requirements.txt' } ] ,
350
+ [
351
+ { label : 'requirements.txt' , buttons : [ OPEN_REQUIREMENTS_BUTTON ] } ,
352
+ { label : 'dev-requirements.txt' , buttons : [ OPEN_REQUIREMENTS_BUTTON ] } ,
353
+ { label : 'test-requirements.txt' , buttons : [ OPEN_REQUIREMENTS_BUTTON ] } ,
354
+ ] ,
332
355
{
333
356
placeHolder : CreateEnv . Venv . requirementsQuickPickTitle ,
334
357
ignoreFocusOut : true ,
335
358
canPickMany : true ,
336
359
} ,
337
360
undefined ,
361
+ sinon . match . func ,
338
362
) ,
339
363
) ;
340
364
assert . deepStrictEqual ( actual , [
@@ -349,6 +373,45 @@ suite('Venv Utils test', () => {
349
373
] ) ;
350
374
assert . isTrue ( readFileStub . notCalled ) ;
351
375
} ) ;
376
+
377
+ test ( 'User clicks button to open requirements.txt' , async ( ) => {
378
+ let allow = true ;
379
+ findFilesStub . callsFake ( ( ) => {
380
+ if ( allow ) {
381
+ allow = false ;
382
+ return Promise . resolve ( [
383
+ Uri . file ( path . join ( workspace1 . uri . fsPath , 'requirements.txt' ) ) ,
384
+ Uri . file ( path . join ( workspace1 . uri . fsPath , 'dev-requirements.txt' ) ) ,
385
+ Uri . file ( path . join ( workspace1 . uri . fsPath , 'test-requirements.txt' ) ) ,
386
+ ] ) ;
387
+ }
388
+ return Promise . resolve ( [ ] ) ;
389
+ } ) ;
390
+ pathExistsStub . resolves ( false ) ;
391
+
392
+ const deferred = createDeferred ( ) ;
393
+ showQuickPickWithBackStub . callsFake ( async ( _items , _options , _token , callback ) => {
394
+ callback ( {
395
+ button : OPEN_REQUIREMENTS_BUTTON ,
396
+ item : { label : 'requirements.txt' } ,
397
+ } ) ;
398
+ await deferred . promise ;
399
+ return [ { label : 'requirements.txt' } ] ;
400
+ } ) ;
401
+
402
+ let uri : Uri | undefined ;
403
+ showTextDocumentStub . callsFake ( ( arg : Uri ) => {
404
+ uri = arg ;
405
+ deferred . resolve ( ) ;
406
+ return Promise . resolve ( ) ;
407
+ } ) ;
408
+
409
+ await pickPackagesToInstall ( workspace1 ) ;
410
+ assert . deepStrictEqual (
411
+ uri ?. toString ( ) ,
412
+ Uri . file ( path . join ( workspace1 . uri . fsPath , 'requirements.txt' ) ) . toString ( ) ,
413
+ ) ;
414
+ } ) ;
352
415
} ) ;
353
416
354
417
suite ( 'Test pick existing venv action' , ( ) => {
0 commit comments