forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathpytestInstallationHelper.unit.test.ts
More file actions
131 lines (106 loc) · 4.49 KB
/
pytestInstallationHelper.unit.test.ts
File metadata and controls
131 lines (106 loc) · 4.49 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { expect } from 'chai';
import * as sinon from 'sinon';
import { Uri } from 'vscode';
import * as TypeMoq from 'typemoq';
import { IApplicationShell } from '../../../client/common/application/types';
import { PytestInstallationHelper } from '../../../client/testing/configuration/pytestInstallationHelper';
import * as envExtApi from '../../../client/envExt/api.internal';
suite('PytestInstallationHelper', () => {
let appShell: TypeMoq.IMock<IApplicationShell>;
let helper: PytestInstallationHelper;
let useEnvExtensionStub: sinon.SinonStub;
let getEnvExtApiStub: sinon.SinonStub;
let getEnvironmentStub: sinon.SinonStub;
const workspaceUri = Uri.file('/test/workspace');
setup(() => {
appShell = TypeMoq.Mock.ofType<IApplicationShell>();
helper = new PytestInstallationHelper(appShell.object);
useEnvExtensionStub = sinon.stub(envExtApi, 'useEnvExtension');
getEnvExtApiStub = sinon.stub(envExtApi, 'getEnvExtApi');
getEnvironmentStub = sinon.stub(envExtApi, 'getEnvironment');
});
teardown(() => {
sinon.restore();
});
test('promptToInstallPytest should return false if user selects ignore', async () => {
appShell
.setup((a) =>
a.showInformationMessage(
TypeMoq.It.isAny(),
TypeMoq.It.isAny(),
TypeMoq.It.isAny(),
TypeMoq.It.isAny(),
),
)
.returns(() => Promise.resolve('Ignore'))
.verifiable(TypeMoq.Times.once());
const result = await helper.promptToInstallPytest(workspaceUri);
expect(result).to.be.false;
appShell.verifyAll();
});
test('promptToInstallPytest should return false if user cancels', async () => {
appShell
.setup((a) =>
a.showInformationMessage(
TypeMoq.It.isAny(),
TypeMoq.It.isAny(),
TypeMoq.It.isAny(),
TypeMoq.It.isAny(),
),
)
.returns(() => Promise.resolve(undefined))
.verifiable(TypeMoq.Times.once());
const result = await helper.promptToInstallPytest(workspaceUri);
expect(result).to.be.false;
appShell.verifyAll();
});
test('isEnvExtensionAvailable should return result from useEnvExtension', () => {
useEnvExtensionStub.returns(true);
const result = helper.isEnvExtensionAvailable();
expect(result).to.be.true;
expect(useEnvExtensionStub.calledOnce).to.be.true;
});
test('promptToInstallPytest should return false if env extension not available', async () => {
useEnvExtensionStub.returns(false);
appShell
.setup((a) =>
a.showInformationMessage(
TypeMoq.It.isAny(),
TypeMoq.It.isAny(),
TypeMoq.It.isAny(),
TypeMoq.It.isAny(),
),
)
.returns(() => Promise.resolve('Install pytest'))
.verifiable(TypeMoq.Times.once());
const result = await helper.promptToInstallPytest(workspaceUri);
expect(result).to.be.false;
appShell.verifyAll();
});
test('promptToInstallPytest should attempt installation when env extension is available', async () => {
useEnvExtensionStub.returns(true);
const mockEnvironment = { envId: { id: 'test-env', managerId: 'test-manager' } };
const mockEnvExtApi = {
managePackages: sinon.stub().resolves(),
};
getEnvExtApiStub.resolves(mockEnvExtApi);
getEnvironmentStub.resolves(mockEnvironment);
appShell
.setup((a) =>
a.showInformationMessage(
TypeMoq.It.is((msg: string) => msg.includes('pytest selected but not installed')),
TypeMoq.It.isAny(),
TypeMoq.It.isAny(),
TypeMoq.It.isAny(),
),
)
.returns(() => Promise.resolve('Install pytest'))
.verifiable(TypeMoq.Times.once());
const result = await helper.promptToInstallPytest(workspaceUri);
expect(result).to.be.true;
expect(mockEnvExtApi.managePackages.calledOnceWithExactly(mockEnvironment, { install: ['pytest'] })).to.be.true;
appShell.verifyAll();
});
});