55
66import { assert , expect } from 'chai' ;
77import * as sinon from 'sinon' ;
8- import { anything , instance , mock , when } from 'ts-mockito' ;
8+ import { anything , instance , mock , reset , when } from 'ts-mockito' ;
99import * as TypeMoq from 'typemoq' ;
1010import { Uri } from 'vscode' ;
1111import { IDisposable } from '../../client/common/types' ;
@@ -14,6 +14,7 @@ import { InterpreterPathCommand } from '../../client/interpreter/interpreterPath
1414import { IInterpreterService } from '../../client/interpreter/contracts' ;
1515import { PythonEnvironment } from '../../client/pythonEnvironments/info' ;
1616import * as workspaceApis from '../../client/common/vscodeApis/workspaceApis' ;
17+ import { mockedVSCodeNamespaces } from '../vscode-mock' ;
1718
1819suite ( 'Interpreter Path Command' , ( ) => {
1920 let interpreterService : IInterpreterService ;
@@ -30,6 +31,7 @@ suite('Interpreter Path Command', () => {
3031
3132 teardown ( ( ) => {
3233 sinon . restore ( ) ;
34+ reset ( mockedVSCodeNamespaces . workspace ) ;
3335 } ) ;
3436
3537 test ( 'Ensure command is registered with the correct callback handler' , async ( ) => {
@@ -68,6 +70,35 @@ suite('Interpreter Path Command', () => {
6870 expect ( setting ) . to . equal ( 'settingValue' ) ;
6971 } ) ;
7072
73+ test ( 'If `args[1]` is missing but there is exactly one workspace folder, fall back to it (tasks.json case)' , async ( ) => {
74+ when ( mockedVSCodeNamespaces . workspace ! . workspaceFolders ) . thenReturn ( [
75+ { uri : Uri . file ( 'onlyFolderPath' ) , name : 'onlyFolder' , index : 0 } ,
76+ ] ) ;
77+
78+ const args = [ 'command' ] ;
79+ when ( interpreterService . getActiveInterpreter ( anything ( ) ) ) . thenCall ( ( arg ) => {
80+ assert . deepEqual ( arg , Uri . file ( 'onlyFolderPath' ) ) ;
81+
82+ return Promise . resolve ( { path : 'settingValue' } ) as unknown ;
83+ } ) ;
84+ const setting = await interpreterPathCommand . _getSelectedInterpreterPath ( args ) ;
85+ expect ( setting ) . to . equal ( 'settingValue' ) ;
86+ } ) ;
87+
88+ test ( 'If `args[1]` is missing and there are multiple (or zero) workspace folders, value of workspace folder is `undefined`' , async ( ) => {
89+ when ( mockedVSCodeNamespaces . workspace ! . workspaceFolders ) . thenReturn ( [
90+ { uri : Uri . file ( 'folderOne' ) , name : 'folderOne' , index : 0 } ,
91+ { uri : Uri . file ( 'folderTwo' ) , name : 'folderTwo' , index : 1 } ,
92+ ] ) ;
93+
94+ const args = [ 'command' ] ;
95+ when ( interpreterService . getActiveInterpreter ( undefined ) ) . thenReturn (
96+ Promise . resolve ( { path : 'settingValue' } ) as Promise < PythonEnvironment | undefined > ,
97+ ) ;
98+ const setting = await interpreterPathCommand . _getSelectedInterpreterPath ( args ) ;
99+ expect ( setting ) . to . equal ( 'settingValue' ) ;
100+ } ) ;
101+
71102 test ( 'If interpreter path contains spaces, double quote it before returning' , async ( ) => {
72103 const args = [ 'command' , 'folderPath' ] ;
73104 when ( interpreterService . getActiveInterpreter ( anything ( ) ) ) . thenCall ( ( arg ) => {
0 commit comments