forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorHandler.unit.test.ts
More file actions
114 lines (100 loc) · 4.8 KB
/
errorHandler.unit.test.ts
File metadata and controls
114 lines (100 loc) · 4.8 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { anything, instance, mock, verify, when } from 'ts-mockito';
import * as typemoq from 'typemoq';
import { IApplicationShell } from '../../client/common/application/types';
import { IInstallationChannelManager, IModuleInstaller } from '../../client/common/installer/types';
import * as localize from '../../client/common/utils/localize';
import { DataScienceErrorHandler } from '../../client/datascience/errorHandler/errorHandler';
import { JupyterInstallError } from '../../client/datascience/jupyter/jupyterInstallError';
import { JupyterSelfCertsError } from '../../client/datascience/jupyter/jupyterSelfCertsError';
import { JupyterZMQBinariesNotFoundError } from '../../client/datascience/jupyter/jupyterZMQBinariesNotFoundError';
import { JupyterServerSelector } from '../../client/datascience/jupyter/serverSelector';
import { IJupyterInterpreterDependencyManager } from '../../client/datascience/types';
suite('DataScience Error Handler Unit Tests', () => {
let applicationShell: typemoq.IMock<IApplicationShell>;
let channels: typemoq.IMock<IInstallationChannelManager>;
let dataScienceErrorHandler: DataScienceErrorHandler;
let dependencyManager: IJupyterInterpreterDependencyManager;
const serverSelector = mock(JupyterServerSelector);
setup(() => {
applicationShell = typemoq.Mock.ofType<IApplicationShell>();
channels = typemoq.Mock.ofType<IInstallationChannelManager>();
dependencyManager = mock<IJupyterInterpreterDependencyManager>();
when(dependencyManager.installMissingDependencies(anything())).thenResolve();
dataScienceErrorHandler = new DataScienceErrorHandler(
applicationShell.object,
instance(dependencyManager),
instance(serverSelector)
);
});
const message = 'Test error message.';
test('Default error', async () => {
applicationShell
.setup((app) => app.showErrorMessage(typemoq.It.isAny()))
.returns(() => Promise.resolve(message))
.verifiable(typemoq.Times.once());
const err = new Error(message);
await dataScienceErrorHandler.handleError(err);
applicationShell.verifyAll();
});
test('Jupyter Self Certificates Error', async () => {
applicationShell
.setup((app) => app.showErrorMessage(typemoq.It.isAny()))
.returns(() => Promise.resolve(message))
.verifiable(typemoq.Times.never());
const err = new JupyterSelfCertsError(message);
await dataScienceErrorHandler.handleError(err);
applicationShell.verifyAll();
});
test('Jupyter Install Error', async () => {
applicationShell
.setup((app) =>
app.showInformationMessage(
typemoq.It.isAny(),
typemoq.It.isValue(localize.DataScience.jupyterInstall()),
typemoq.It.isValue(localize.DataScience.notebookCheckForImportNo()),
typemoq.It.isAny()
)
)
.returns(() => Promise.resolve(localize.DataScience.jupyterInstall()))
.verifiable(typemoq.Times.once());
const installers: IModuleInstaller[] = [
{
name: 'Pip',
displayName: 'Pip',
priority: 0,
isSupported: () => Promise.resolve(true),
installModule: () => Promise.resolve()
},
{
name: 'Conda',
displayName: 'Conda',
priority: 0,
isSupported: () => Promise.resolve(true),
installModule: () => Promise.resolve()
}
];
channels
.setup((ch) => ch.getInstallationChannels())
.returns(() => Promise.resolve(installers))
.verifiable(typemoq.Times.once());
const err = new JupyterInstallError(message, 'test.com');
await dataScienceErrorHandler.handleError(err);
verify(dependencyManager.installMissingDependencies(err)).once();
});
test('ZMQ Install Error', async () => {
applicationShell
.setup((app) =>
app.showErrorMessage(typemoq.It.isAny(), typemoq.It.isValue(localize.DataScience.selectNewServer()))
)
.returns(() => Promise.resolve(localize.DataScience.selectNewServer()))
.verifiable(typemoq.Times.once());
when(serverSelector.selectJupyterURI(anything())).thenCall(() => Promise.resolve());
const err = new JupyterZMQBinariesNotFoundError('Not found');
await dataScienceErrorHandler.handleError(err);
verify(serverSelector.selectJupyterURI(anything())).once();
applicationShell.verifyAll();
});
});