forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexecutable.unit.test.ts
More file actions
47 lines (37 loc) · 1.95 KB
/
Copy pathexecutable.unit.test.ts
File metadata and controls
47 lines (37 loc) · 1.95 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { expect } from 'chai';
import { IMock, Mock, MockBehavior, It } from 'typemoq';
import { ExecutionResult, ShellOptions, StdErrError } from '../../../client/common/process/types';
import { buildPythonExecInfo } from '../../../client/pythonEnvironments/exec';
import { getExecutablePath } from '../../../client/pythonEnvironments/info/executable';
interface IDeps {
shellExec(command: string, options: ShellOptions | undefined): Promise<ExecutionResult<string>>;
}
suite('getExecutablePath()', () => {
let deps: IMock<IDeps>;
const python = buildPythonExecInfo('path/to/python');
setup(() => {
deps = Mock.ofType<IDeps>(undefined, MockBehavior.Strict);
});
test('should get the value by running python', async () => {
const expected = 'path/to/dummy/executable';
deps.setup((d) => d.shellExec(`${python.command} -c "import sys;print(sys.executable)"`, It.isAny()))
// Return the expected value.
.returns(() => Promise.resolve({ stdout: expected }));
const exec = async (c: string, a: ShellOptions | undefined) => deps.object.shellExec(c, a);
const result = await getExecutablePath(python, exec);
expect(result).to.equal(expected, 'getExecutablePath() should return get the value by running Python');
deps.verifyAll();
});
test('should throw if exec() fails', async () => {
const stderr = 'oops';
deps.setup((d) => d.shellExec(`${python.command} -c "import sys;print(sys.executable)"`, It.isAny()))
// Throw an error.
.returns(() => Promise.reject(new StdErrError(stderr)));
const exec = async (c: string, a: ShellOptions | undefined) => deps.object.shellExec(c, a);
const promise = getExecutablePath(python, exec);
expect(promise).to.eventually.be.rejectedWith(stderr);
deps.verifyAll();
});
});