forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutable.unit.test.ts
More file actions
52 lines (42 loc) · 1.9 KB
/
Copy pathexecutable.unit.test.ts
File metadata and controls
52 lines (42 loc) · 1.9 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { expect } from 'chai';
import { IMock, Mock, MockBehavior } from 'typemoq';
import { StdErrError } from '../../../client/common/process/types';
import { buildPythonExecInfo } from '../../../client/pythonEnvironments/exec';
import { getExecutablePath } from '../../../client/pythonEnvironments/info/executable';
type ExecResult = {
stdout: string;
};
interface IDeps {
exec(command: string, args: string[]): Promise<ExecResult>;
}
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';
const argv = ['-c', 'import sys;print(sys.executable)'];
deps.setup((d) => d.exec(python.command, argv))
// Return the expected value.
.returns(() => Promise.resolve({ stdout: expected }));
const exec = async (c: string, a: string[]) => deps.object.exec(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';
const argv = ['-c', 'import sys;print(sys.executable)'];
deps.setup((d) => d.exec(python.command, argv))
// Throw an error.
.returns(() => Promise.reject(new StdErrError(stderr)));
const exec = async (c: string, a: string[]) => deps.object.exec(c, a);
const result = getExecutablePath(python, exec);
expect(result).to.eventually.be.rejectedWith(stderr);
deps.verifyAll();
});
});