|
6 | 6 | import { expect } from 'chai';
|
7 | 7 | import * as path from 'path';
|
8 | 8 | import * as sinon from 'sinon';
|
9 |
| -import { anything, instance, mock, when } from 'ts-mockito'; |
| 9 | +import { anything, instance, mock, verify, when } from 'ts-mockito'; |
10 | 10 | import * as typemoq from 'typemoq';
|
11 | 11 | import { Uri, WorkspaceConfiguration } from 'vscode';
|
12 | 12 | import { IWorkspaceService } from '../../../client/common/application/types';
|
@@ -118,7 +118,24 @@ suite('Python Settings - pythonPath', () => {
|
118 | 118 |
|
119 | 119 | expect(configSettings.pythonPath).to.be.equal('python');
|
120 | 120 | });
|
121 |
| - test("If we don't have a custom python path and we do have an auto selected interpreter, then use it", () => { |
| 121 | + test("If a workspace is opened and if we don't have a custom python path but we do have an auto selected interpreter, then use it", () => { |
| 122 | + const pythonPath = path.join(__dirname, 'this is a python path that was auto selected'); |
| 123 | + const interpreter = { path: pythonPath } as PythonEnvironment; |
| 124 | + const workspaceFolderUri = Uri.file(__dirname); |
| 125 | + const selectionService = mock(MockAutoSelectionService); |
| 126 | + when(selectionService.getAutoSelectedInterpreter(workspaceFolderUri)).thenReturn(interpreter); |
| 127 | + when(selectionService.setWorkspaceInterpreter(workspaceFolderUri, anything())).thenResolve(); |
| 128 | + configSettings = new CustomPythonSettings(workspaceFolderUri, instance(selectionService)); |
| 129 | + pythonSettings |
| 130 | + .setup((p) => p.get(typemoq.It.isValue('pythonPath'))) |
| 131 | + .returns(() => 'python') |
| 132 | + .verifiable(typemoq.Times.atLeast(1)); |
| 133 | + configSettings.update(pythonSettings.object); |
| 134 | + |
| 135 | + expect(configSettings.pythonPath).to.be.equal(pythonPath); |
| 136 | + verify(selectionService.setWorkspaceInterpreter(workspaceFolderUri, interpreter)).once(); // Verify we set the autoselected interpreter |
| 137 | + }); |
| 138 | + test("If no workspace is opened and we don't have a custom python path but we do have an auto selected interpreter, then use it", () => { |
122 | 139 | const pythonPath = path.join(__dirname, 'this is a python path that was auto selected');
|
123 | 140 | const interpreter = { path: pythonPath } as PythonEnvironment;
|
124 | 141 | const workspaceFolderUri = Uri.file(__dirname);
|
|
0 commit comments