forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmockJupyterServer.ts
More file actions
65 lines (58 loc) · 2.37 KB
/
mockJupyterServer.ts
File metadata and controls
65 lines (58 loc) · 2.37 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as uuid from 'uuid/v4';
import { Uri } from 'vscode';
import { TemporaryFile } from '../../client/common/platform/types';
import { noop } from '../../client/common/utils/misc';
import { IConnection, INotebook, INotebookServer, INotebookServerLaunchInfo } from '../../client/datascience/types';
import { MockJupyterNotebook } from './mockJupyterNotebook';
export class MockJupyterServer implements INotebookServer {
private launchInfo: INotebookServerLaunchInfo | undefined;
private notebookFile: TemporaryFile | undefined;
private _id = uuid();
public get id(): string {
return this._id;
}
public connect(launchInfo: INotebookServerLaunchInfo): Promise<void> {
if (launchInfo && launchInfo.connectionInfo && launchInfo.kernelSpec) {
this.launchInfo = launchInfo;
// Validate connection info and kernel spec
if (
launchInfo.connectionInfo.baseUrl &&
launchInfo.kernelSpec.name &&
/[a-z,A-Z,0-9,-,.,_]+/.test(launchInfo.kernelSpec.name)
) {
return Promise.resolve();
}
}
return Promise.reject('invalid server startup');
}
public async createNotebook(_resource: Uri): Promise<INotebook> {
return new MockJupyterNotebook(this);
}
public async getNotebook(_resource: Uri): Promise<INotebook | undefined> {
return new MockJupyterNotebook(this);
}
public async setMatplotLibStyle(_useDark: boolean): Promise<void> {
noop();
}
public getConnectionInfo(): IConnection | undefined {
return this.launchInfo ? this.launchInfo.connectionInfo : undefined;
}
public waitForConnect(): Promise<INotebookServerLaunchInfo | undefined> {
throw new Error('Method not implemented');
}
public async shutdown() {
return Promise.resolve();
}
public async dispose(): Promise<void> {
if (this.launchInfo) {
this.launchInfo.connectionInfo.dispose(); // This should kill the process that's running
this.launchInfo = undefined;
}
if (this.notebookFile) {
this.notebookFile.dispose(); // This destroy any unwanted kernel specs if necessary
this.notebookFile = undefined;
}
}
}