@@ -15,7 +15,7 @@ import * as rawProcessApis from '../../../../client/common/process/rawProcessApi
15
15
import * as commonUtils from '../../../../client/pythonEnvironments/creation/common/commonUtils' ;
16
16
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../../constants' ;
17
17
import { createDeferred } from '../../../../client/common/utils/async' ;
18
- import { Output } from '../../../../client/common/process/types' ;
18
+ import { Output , SpawnOptions } from '../../../../client/common/process/types' ;
19
19
import { VENV_CREATED_MARKER } from '../../../../client/pythonEnvironments/creation/provider/venvProgressAndTelemetry' ;
20
20
import { CreateEnv } from '../../../../client/common/utils/localize' ;
21
21
import * as venvUtils from '../../../../client/pythonEnvironments/creation/provider/venvUtils' ;
@@ -394,4 +394,157 @@ suite('venv Creation provider tests', () => {
394
394
assert . isTrue ( showErrorMessageWithLogsStub . notCalled ) ;
395
395
assert . isTrue ( deleteEnvironmentStub . notCalled ) ;
396
396
} ) ;
397
+
398
+ test ( 'Create venv with 1000 requirement files' , async ( ) => {
399
+ pickWorkspaceFolderStub . resolves ( workspace1 ) ;
400
+
401
+ interpreterQuickPick
402
+ . setup ( ( i ) => i . getInterpreterViaQuickPick ( typemoq . It . isAny ( ) , typemoq . It . isAny ( ) , typemoq . It . isAny ( ) ) )
403
+ . returns ( ( ) => Promise . resolve ( '/usr/bin/python' ) )
404
+ . verifiable ( typemoq . Times . once ( ) ) ;
405
+
406
+ const requirements = Array . from ( { length : 1000 } , ( _ , i ) => ( {
407
+ installType : 'requirements' ,
408
+ installItem : `requirements${ i } .txt` ,
409
+ } ) ) ;
410
+ pickPackagesToInstallStub . resolves ( requirements ) ;
411
+ const expected = JSON . stringify ( { requirements : requirements . map ( ( r ) => r . installItem ) } ) ;
412
+
413
+ const deferred = createDeferred ( ) ;
414
+ let _next : undefined | ( ( value : Output < string > ) => void ) ;
415
+ let _complete : undefined | ( ( ) => void ) ;
416
+ let stdin : undefined | string ;
417
+ let hasStdinArg = false ;
418
+ execObservableStub . callsFake ( ( _c , argv : string [ ] , options ) => {
419
+ stdin = options ?. stdinStr ;
420
+ hasStdinArg = argv . includes ( '--stdin' ) ;
421
+ deferred . resolve ( ) ;
422
+ return {
423
+ proc : {
424
+ exitCode : 0 ,
425
+ } ,
426
+ out : {
427
+ subscribe : (
428
+ next ?: ( value : Output < string > ) => void ,
429
+ _error ?: ( error : unknown ) => void ,
430
+ complete ?: ( ) => void ,
431
+ ) => {
432
+ _next = next ;
433
+ _complete = complete ;
434
+ } ,
435
+ } ,
436
+ dispose : ( ) => undefined ,
437
+ } ;
438
+ } ) ;
439
+
440
+ progressMock . setup ( ( p ) => p . report ( { message : CreateEnv . statusStarting } ) ) . verifiable ( typemoq . Times . once ( ) ) ;
441
+
442
+ withProgressStub . callsFake (
443
+ (
444
+ _options : ProgressOptions ,
445
+ task : (
446
+ progress : CreateEnvironmentProgress ,
447
+ token ?: CancellationToken ,
448
+ ) => Thenable < CreateEnvironmentResult > ,
449
+ ) => task ( progressMock . object ) ,
450
+ ) ;
451
+
452
+ const promise = venvProvider . createEnvironment ( ) ;
453
+ await deferred . promise ;
454
+ assert . isDefined ( _next ) ;
455
+ assert . isDefined ( _complete ) ;
456
+
457
+ _next ! ( { out : `${ VENV_CREATED_MARKER } new_environment` , source : 'stdout' } ) ;
458
+ _complete ! ( ) ;
459
+
460
+ const actual = await promise ;
461
+ assert . deepStrictEqual ( actual , {
462
+ path : 'new_environment' ,
463
+ workspaceFolder : workspace1 ,
464
+ } ) ;
465
+ interpreterQuickPick . verifyAll ( ) ;
466
+ progressMock . verifyAll ( ) ;
467
+ assert . isTrue ( showErrorMessageWithLogsStub . notCalled ) ;
468
+ assert . isTrue ( deleteEnvironmentStub . notCalled ) ;
469
+ assert . strictEqual ( stdin , expected ) ;
470
+ assert . isTrue ( hasStdinArg ) ;
471
+ } ) ;
472
+
473
+ test ( 'Create venv with 5 requirement files' , async ( ) => {
474
+ pickWorkspaceFolderStub . resolves ( workspace1 ) ;
475
+
476
+ interpreterQuickPick
477
+ . setup ( ( i ) => i . getInterpreterViaQuickPick ( typemoq . It . isAny ( ) , typemoq . It . isAny ( ) , typemoq . It . isAny ( ) ) )
478
+ . returns ( ( ) => Promise . resolve ( '/usr/bin/python' ) )
479
+ . verifiable ( typemoq . Times . once ( ) ) ;
480
+
481
+ const requirements = Array . from ( { length : 5 } , ( _ , i ) => ( {
482
+ installType : 'requirements' ,
483
+ installItem : `requirements${ i } .txt` ,
484
+ } ) ) ;
485
+ pickPackagesToInstallStub . resolves ( requirements ) ;
486
+ const expectedRequirements = requirements . map ( ( r ) => r . installItem ) . sort ( ) ;
487
+
488
+ const deferred = createDeferred ( ) ;
489
+ let _next : undefined | ( ( value : Output < string > ) => void ) ;
490
+ let _complete : undefined | ( ( ) => void ) ;
491
+ let stdin : undefined | string ;
492
+ let hasStdinArg = false ;
493
+ let actualRequirements : string [ ] = [ ] ;
494
+ execObservableStub . callsFake ( ( _c , argv : string [ ] , options : SpawnOptions ) => {
495
+ stdin = options ?. stdinStr ;
496
+ actualRequirements = argv . filter ( ( arg ) => arg . startsWith ( 'requirements' ) ) . sort ( ) ;
497
+ hasStdinArg = argv . includes ( '--stdin' ) ;
498
+ deferred . resolve ( ) ;
499
+ return {
500
+ proc : {
501
+ exitCode : 0 ,
502
+ } ,
503
+ out : {
504
+ subscribe : (
505
+ next ?: ( value : Output < string > ) => void ,
506
+ _error ?: ( error : unknown ) => void ,
507
+ complete ?: ( ) => void ,
508
+ ) => {
509
+ _next = next ;
510
+ _complete = complete ;
511
+ } ,
512
+ } ,
513
+ dispose : ( ) => undefined ,
514
+ } ;
515
+ } ) ;
516
+
517
+ progressMock . setup ( ( p ) => p . report ( { message : CreateEnv . statusStarting } ) ) . verifiable ( typemoq . Times . once ( ) ) ;
518
+
519
+ withProgressStub . callsFake (
520
+ (
521
+ _options : ProgressOptions ,
522
+ task : (
523
+ progress : CreateEnvironmentProgress ,
524
+ token ?: CancellationToken ,
525
+ ) => Thenable < CreateEnvironmentResult > ,
526
+ ) => task ( progressMock . object ) ,
527
+ ) ;
528
+
529
+ const promise = venvProvider . createEnvironment ( ) ;
530
+ await deferred . promise ;
531
+ assert . isDefined ( _next ) ;
532
+ assert . isDefined ( _complete ) ;
533
+
534
+ _next ! ( { out : `${ VENV_CREATED_MARKER } new_environment` , source : 'stdout' } ) ;
535
+ _complete ! ( ) ;
536
+
537
+ const actual = await promise ;
538
+ assert . deepStrictEqual ( actual , {
539
+ path : 'new_environment' ,
540
+ workspaceFolder : workspace1 ,
541
+ } ) ;
542
+ interpreterQuickPick . verifyAll ( ) ;
543
+ progressMock . verifyAll ( ) ;
544
+ assert . isTrue ( showErrorMessageWithLogsStub . notCalled ) ;
545
+ assert . isTrue ( deleteEnvironmentStub . notCalled ) ;
546
+ assert . isUndefined ( stdin ) ;
547
+ assert . deepStrictEqual ( actualRequirements , expectedRequirements ) ;
548
+ assert . isFalse ( hasStdinArg ) ;
549
+ } ) ;
397
550
} ) ;
0 commit comments