forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonPathUpdater.test.ts
More file actions
94 lines (83 loc) · 5.91 KB
/
pythonPathUpdater.test.ts
File metadata and controls
94 lines (83 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import * as assert from 'assert';
import * as path from 'path';
import { ConfigurationTarget, Uri, workspace } from 'vscode';
import { PythonSettings } from '../../client/common/configSettings';
import { PythonPathUpdaterService } from '../../client/interpreter/configuration/pythonPathUpdaterService';
import { PythonPathUpdaterServiceFactory } from '../../client/interpreter/configuration/pythonPathUpdaterServiceFactory';
import { GlobalPythonPathUpdaterService } from '../../client/interpreter/configuration/services/globalUpdaterService';
import { WorkspacePythonPathUpdaterService } from '../../client/interpreter/configuration/services/workspaceUpdaterService';
import { InterpreterVersionService } from '../../client/interpreter/interpreterVersion';
import { closeActiveWindows, initialize, initializeTest } from '../initialize';
const workspaceRoot = path.join(__dirname, '..', '..', '..', 'src', 'test');
// tslint:disable-next-line:max-func-body-length
suite('Python Path Settings Updater', () => {
suiteSetup(initialize);
setup(initializeTest);
suiteTeardown(async () => {
await closeActiveWindows();
await initializeTest();
});
teardown(async () => {
await closeActiveWindows();
await initializeTest();
});
// Create Github issue VS Code bug (global changes not reflected immediately)
// test('Updating Global Python Path should work', async () => {
// const globalUpdater = new GlobalPythonPathUpdaterService();
// const pythonPath = `xGlobalPythonPath${new Date().getMilliseconds()}`;
// await globalUpdater.updatePythonPath(pythonPath);
// const globalPythonValue = workspace.getConfiguration('python').inspect('pythonPath').globalValue;
// assert.equal(globalPythonValue, pythonPath, 'Global Python Path not updated');
// });
// test('Updating Global Python Path using the factory service should work', async () => {
// const globalUpdater = new PythonPathUpdaterServiceFactory().getGlobalPythonPathConfigurationService();
// const pythonPath = `xGlobalPythonPathFromFactory${new Date().getMilliseconds()}`;
// await globalUpdater.updatePythonPath(pythonPath);
// const globalPythonValue = workspace.getConfiguration('python').inspect('pythonPath').globalValue;
// assert.equal(globalPythonValue, pythonPath, 'Global Python Path not updated');
// });
// test('Updating Global Python Path using the PythonPathUpdaterService should work', async () => {
// const updaterService = new PythonPathUpdaterService(new PythonPathUpdaterServiceFactory());
// const pythonPath = `xGlobalPythonPathFromUpdater${new Date().getMilliseconds()}`;
// await updaterService.updatePythonPath(pythonPath, ConfigurationTarget.Global);
// const globalPythonValue = workspace.getConfiguration('python').inspect('pythonPath').globalValue;
// assert.equal(globalPythonValue, pythonPath, 'Global Python Path not updated');
// });
test('Updating Workspace Python Path should work', async () => {
const workspaceUri = Uri.file(workspaceRoot);
const workspaceUpdater = new WorkspacePythonPathUpdaterService(workspace.getWorkspaceFolder(workspaceUri).uri);
const pythonPath = `xWorkspacePythonPath${new Date().getMilliseconds()}`;
await workspaceUpdater.updatePythonPath(pythonPath);
const workspaceValue = workspace.getConfiguration('python').inspect('pythonPath').workspaceValue;
assert.equal(workspaceValue, pythonPath, 'Workspace Python Path not updated');
});
test('Updating Workspace Python Path using the factor service should work', async () => {
const workspaceUri = Uri.file(workspaceRoot);
const factory = new PythonPathUpdaterServiceFactory();
const workspaceUpdater = factory.getWorkspacePythonPathConfigurationService(workspace.getWorkspaceFolder(workspaceUri).uri);
const pythonPath = `xWorkspacePythonPathFromFactory${new Date().getMilliseconds()}`;
await workspaceUpdater.updatePythonPath(pythonPath);
const workspaceValue = workspace.getConfiguration('python').inspect('pythonPath').workspaceValue;
assert.equal(workspaceValue, pythonPath, 'Workspace Python Path not updated');
});
test('Updating Workspace Python Path using the PythonPathUpdaterService should work', async () => {
const workspaceUri = Uri.file(workspaceRoot);
const updaterService = new PythonPathUpdaterService(new PythonPathUpdaterServiceFactory(), new InterpreterVersionService());
const pythonPath = `xWorkspacePythonPathFromUpdater${new Date().getMilliseconds()}`;
await updaterService.updatePythonPath(pythonPath, ConfigurationTarget.Workspace, 'ui', workspace.getWorkspaceFolder(workspaceUri).uri);
const workspaceValue = workspace.getConfiguration('python').inspect('pythonPath').workspaceValue;
assert.equal(workspaceValue, pythonPath, 'Workspace Python Path not updated');
});
test('Python Path should be relative to workspaceFolder', async () => {
const workspaceUri = workspace.getWorkspaceFolder(Uri.file(workspaceRoot)).uri;
const pythonInterpreter = `xWorkspacePythonPath${new Date().getMilliseconds()}`;
const pythonPath = path.join(workspaceUri.fsPath, 'x', 'y', 'z', pythonInterpreter);
const workspaceUpdater = new WorkspacePythonPathUpdaterService(workspaceUri);
await workspaceUpdater.updatePythonPath(pythonPath);
const workspaceValue = workspace.getConfiguration('python').inspect('pythonPath').workspaceValue;
// tslint:disable-next-line:no-invalid-template-strings
assert.equal(workspaceValue, path.join('${workspaceFolder}', 'x', 'y', 'z', pythonInterpreter), 'Workspace Python Path not updated');
const resolvedPath = PythonSettings.getInstance(Uri.file(workspaceRoot)).pythonPath;
assert.equal(resolvedPath, pythonPath, 'Resolved Workspace Python Path not updated');
});
});