|
1 | 1 | import * as assert from 'assert';
|
2 | 2 | import * as path from 'path';
|
3 | 3 | import { ConfigurationTarget, Uri, workspace } from 'vscode';
|
| 4 | +import { PythonSettings } from '../../client/common/configSettings'; |
4 | 5 | import { PythonPathUpdaterService } from '../../client/interpreter/configuration/pythonPathUpdaterService';
|
5 | 6 | import { PythonPathUpdaterServiceFactory } from '../../client/interpreter/configuration/pythonPathUpdaterServiceFactory';
|
6 | 7 | import { WorkspaceFolderPythonPathUpdaterService } from '../../client/interpreter/configuration/services/workspaceFolderUpdaterService';
|
@@ -32,40 +33,82 @@ suite('Multiroot Python Path Settings Updater', () => {
|
32 | 33 |
|
33 | 34 | test('Updating Workspace Folder Python Path should work', async () => {
|
34 | 35 | const workspaceUri = workspace3Uri;
|
35 |
| - const workspaceUpdater = new WorkspaceFolderPythonPathUpdaterService(workspace.getWorkspaceFolder(workspaceUri).uri); |
| 36 | + const workspaceUpdater = new WorkspaceFolderPythonPathUpdaterService(workspace.getWorkspaceFolder(workspaceUri)!.uri); |
36 | 37 | const pythonPath = `xWorkspacePythonPath${new Date().getMilliseconds()}`;
|
37 | 38 | await workspaceUpdater.updatePythonPath(pythonPath);
|
38 |
| - const folderValue = workspace.getConfiguration('python', workspace3Uri).inspect('pythonPath').workspaceFolderValue; |
| 39 | + const folderValue = workspace.getConfiguration('python', workspace3Uri).inspect('pythonPath')!.workspaceFolderValue!; |
39 | 40 | assert.equal(folderValue, pythonPath, 'Workspace Python Path not updated');
|
40 | 41 | });
|
41 | 42 |
|
| 43 | + test('Updating Workspace Folder Python Path when Python Path is in a sub directory of Workspace Folder', async () => { |
| 44 | + const workspaceUri = workspace3Uri; |
| 45 | + const workspaceFolder = workspace.getWorkspaceFolder(workspaceUri)!.uri; |
| 46 | + const workspaceUpdater = new WorkspaceFolderPythonPathUpdaterService(workspaceFolder); |
| 47 | + |
| 48 | + // Python path within a sub directory of the workspace folder. |
| 49 | + const pythonExec = path.join('virtual Envs', 'env1', `xWorkspacePythonPath${new Date().getMilliseconds()}`); |
| 50 | + |
| 51 | + // Expected path to python executable where ${workspaceFolder} token represents the fully qualified path to executable. |
| 52 | + // tslint:disable-next-line:no-invalid-template-strings |
| 53 | + const rawPythonPath = path.join('${workspaceFolder}', pythonExec); |
| 54 | + |
| 55 | + // Fully qualified path to the python executable. |
| 56 | + const pythonPath = path.join(workspaceFolder.fsPath, pythonExec); |
| 57 | + await workspaceUpdater.updatePythonPath(pythonPath); |
| 58 | + PythonSettings.dispose(); |
| 59 | + |
| 60 | + const folderValue = workspace.getConfiguration('python', workspace3Uri).inspect('pythonPath')!.workspaceFolderValue!; |
| 61 | + assert.equal(folderValue, rawPythonPath, 'Raw Workspace Python Path not updated with a path relative to workspace folder'); |
| 62 | + const resolvedPythonPath = PythonSettings.getInstance(workspaceUri).pythonPath; |
| 63 | + assert.equal(resolvedPythonPath, pythonPath, 'Resolved Workspace Python Path is incorrect'); |
| 64 | + }); |
| 65 | + |
42 | 66 | test('Updating Workspace Folder Python Path using the factor service should work', async () => {
|
43 | 67 | const workspaceUri = workspace3Uri;
|
44 | 68 | const factory = new PythonPathUpdaterServiceFactory();
|
45 |
| - const workspaceUpdater = factory.getWorkspaceFolderPythonPathConfigurationService(workspace.getWorkspaceFolder(workspaceUri).uri); |
| 69 | + const workspaceUpdater = factory.getWorkspaceFolderPythonPathConfigurationService(workspace.getWorkspaceFolder(workspaceUri)!.uri); |
46 | 70 | const pythonPath = `xWorkspacePythonPathFromFactory${new Date().getMilliseconds()}`;
|
47 | 71 | await workspaceUpdater.updatePythonPath(pythonPath);
|
48 |
| - const folderValue = workspace.getConfiguration('python', workspace3Uri).inspect('pythonPath').workspaceFolderValue; |
| 72 | + const folderValue = workspace.getConfiguration('python', workspace3Uri).inspect('pythonPath')!.workspaceFolderValue!; |
49 | 73 | assert.equal(folderValue, pythonPath, 'Workspace Python Path not updated');
|
50 | 74 | });
|
51 | 75 |
|
52 | 76 | test('Updating Workspace Python Path using the PythonPathUpdaterService should work', async () => {
|
53 | 77 | const workspaceUri = workspace3Uri;
|
54 | 78 | const updaterService = new PythonPathUpdaterService(new PythonPathUpdaterServiceFactory(), new InterpreterVersionService());
|
55 | 79 | const pythonPath = `xWorkspacePythonPathFromUpdater${new Date().getMilliseconds()}`;
|
56 |
| - await updaterService.updatePythonPath(pythonPath, ConfigurationTarget.WorkspaceFolder, 'ui', workspace.getWorkspaceFolder(workspaceUri).uri); |
57 |
| - const folderValue = workspace.getConfiguration('python', workspace3Uri).inspect('pythonPath').workspaceFolderValue; |
| 80 | + await updaterService.updatePythonPath(pythonPath, ConfigurationTarget.WorkspaceFolder, 'ui', workspace.getWorkspaceFolder(workspaceUri)!.uri); |
| 81 | + const folderValue = workspace.getConfiguration('python', workspace3Uri).inspect('pythonPath')!.workspaceFolderValue!; |
58 | 82 | assert.equal(folderValue, pythonPath, 'Workspace Python Path not updated');
|
59 | 83 | });
|
60 | 84 |
|
61 |
| - test('Python Path should be relative to workspace', async () => { |
62 |
| - const workspaceUri = workspace.getWorkspaceFolder(workspace3Uri).uri; |
| 85 | + // tslint:disable-next-line:no-invalid-template-strings |
| 86 | + test('Python Paths containing ${workspaceRoot} should be resolved as ${workspaceFolder}', async () => { |
| 87 | + const workspaceUri = workspace.getWorkspaceFolder(workspace3Uri)!.uri; |
| 88 | + const pythonInterpreter = `xWorkspacePythonPath${new Date().getMilliseconds()}`; |
| 89 | + // tslint:disable-next-line:no-invalid-template-strings |
| 90 | + const pythonPath = path.join('${workspaceRoot}', 'x', 'y', 'z', pythonInterpreter); |
| 91 | + const workspaceUpdater = new WorkspacePythonPathUpdaterService(workspaceUri); |
| 92 | + await workspaceUpdater.updatePythonPath(pythonPath); |
| 93 | + const workspaceValue = workspace.getConfiguration('python').inspect('pythonPath')!.workspaceValue!; |
| 94 | + const resolvedPythonPath = path.join(workspaceUri.fsPath, 'x', 'y', 'z', pythonInterpreter); |
| 95 | + // tslint:disable-next-line:no-invalid-template-strings |
| 96 | + assert.equal(workspaceValue, pythonPath, 'Workspace Python Path not updated'); |
| 97 | + PythonSettings.dispose(); |
| 98 | + assert.equal(PythonSettings.getInstance(workspace3Uri).pythonPath, resolvedPythonPath, 'Resolved Workspace Python Path is incorrect'); |
| 99 | + }); |
| 100 | + |
| 101 | + // tslint:disable-next-line:no-invalid-template-strings |
| 102 | + test('Python Path should be relative to workspace when using ${workspaceFolder}', async () => { |
| 103 | + const workspaceUri = workspace.getWorkspaceFolder(workspace3Uri)!.uri; |
63 | 104 | const pythonInterpreter = `xWorkspacePythonPath${new Date().getMilliseconds()}`;
|
64 | 105 | const pythonPath = path.join(workspaceUri.fsPath, 'x', 'y', 'z', pythonInterpreter);
|
65 | 106 | const workspaceUpdater = new WorkspacePythonPathUpdaterService(workspaceUri);
|
66 | 107 | await workspaceUpdater.updatePythonPath(pythonPath);
|
67 |
| - const workspaceValue = workspace.getConfiguration('python').inspect('pythonPath').workspaceValue; |
| 108 | + const workspaceValue = workspace.getConfiguration('python').inspect('pythonPath')!.workspaceValue!; |
68 | 109 | // tslint:disable-next-line:no-invalid-template-strings
|
69 |
| - assert.equal(workspaceValue, path.join('${workspaceRoot}', 'x', 'y', 'z', pythonInterpreter), 'Workspace Python Path not updated'); |
| 110 | + assert.equal(workspaceValue, path.join('${workspaceFolder}', 'x', 'y', 'z', pythonInterpreter), 'Workspace Python Path not updated'); |
| 111 | + PythonSettings.dispose(); |
| 112 | + assert.equal(PythonSettings.getInstance(workspace3Uri).pythonPath, pythonPath, 'Resolved Workspace Python Path is incorrect'); |
70 | 113 | });
|
71 | 114 | });
|
0 commit comments