forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivation.unit.test.ts
More file actions
85 lines (66 loc) · 3.9 KB
/
activation.unit.test.ts
File metadata and controls
85 lines (66 loc) · 3.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
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { anything, deepEqual, instance, mock, verify, when } from 'ts-mockito';
import { EventEmitter } from 'vscode';
import { IExtensionSingleActivationService } from '../../client/activation/types';
import { PythonExecutionFactory } from '../../client/common/process/pythonExecutionFactory';
import { IPythonExecutionFactory } from '../../client/common/process/types';
import { Activation } from '../../client/datascience/activation';
import { PythonDaemonModule } from '../../client/datascience/constants';
import { NativeEditor } from '../../client/datascience/interactive-ipynb/nativeEditor';
import { NativeEditorProvider } from '../../client/datascience/interactive-ipynb/nativeEditorProvider';
import { INotebookEditor, INotebookEditorProvider } from '../../client/datascience/types';
import { IInterpreterService, PythonInterpreter } from '../../client/interpreter/contracts';
import { InterpreterService } from '../../client/interpreter/interpreterService';
import { sleep } from '../core';
// tslint:disable: no-any
suite('Data Science - Activation', () => {
let activator: IExtensionSingleActivationService;
let notebookProvider: INotebookEditorProvider;
let interpreterService: IInterpreterService;
let executionFactory: IPythonExecutionFactory;
let openedEventEmitter: EventEmitter<INotebookEditor>;
let interpreterEventEmitter: EventEmitter<void>;
setup(async () => {
openedEventEmitter = new EventEmitter<INotebookEditor>();
interpreterEventEmitter = new EventEmitter<void>();
notebookProvider = mock(NativeEditorProvider);
interpreterService = mock(InterpreterService);
executionFactory = mock(PythonExecutionFactory);
when(notebookProvider.onDidOpenNotebookEditor).thenReturn(openedEventEmitter.event);
when(interpreterService.onDidChangeInterpreter).thenReturn(interpreterEventEmitter.event);
when(executionFactory.createDaemon(anything())).thenResolve();
activator = new Activation(instance(notebookProvider), instance(interpreterService), instance(executionFactory), []);
await activator.activate();
});
async function testCreatingDaemonWhenOpeningANotebook(){
const notebook = mock(NativeEditor);
const interpreter = ({ path: 'MY_PY' } as any) as PythonInterpreter;
when(interpreterService.getActiveInterpreter(undefined)).thenResolve(interpreter);
// Open a notebook, (fire the event).
openedEventEmitter.fire(notebook);
// Wait for deounce to complete.
await sleep(1000);
verify(interpreterService.getActiveInterpreter(undefined)).once();
verify(executionFactory.createDaemon(deepEqual({ daemonModule: PythonDaemonModule, pythonPath: interpreter.path }))).once();
}
test('Create a daemon when a notebook is opened', async () => testCreatingDaemonWhenOpeningANotebook);
test('Create a daemon when changing interpreter after a notebook has beeen opened', async () => {
await testCreatingDaemonWhenOpeningANotebook();
// Trigger changes to interpreter.
interpreterEventEmitter.fire();
// Wait for deounce to complete.
await sleep(1000);
verify(interpreterService.getActiveInterpreter(undefined)).twice();
verify(executionFactory.createDaemon(deepEqual({ daemonModule: PythonDaemonModule, pythonPath: 'MY_PY' }))).twice();
}).timeout(3_000);
test('Changing interpreter without opening a notebook does not result in a daemon being created', async () => {
// Trigger changes to interpreter.
interpreterEventEmitter.fire();
// Wait for deounce to complete.
await sleep(1000);
verify(interpreterService.getActiveInterpreter(anything())).never();
verify(executionFactory.createDaemon(anything())).never();
}).timeout(3_000);
});