Skip to content

Commit 021ff27

Browse files
rchiodoDonJayamanne
authored andcommitted
Jupyter server/importer tests (#3126)
* Implement more notebook tests * Add a bunch more tests to validate JupyterServer and JupyterImporter * Remove grep from launch.json * Put back timeouts on unittests * Review feedback
1 parent 0586dba commit 021ff27

16 files changed

Lines changed: 858 additions & 301 deletions

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ script:
9090
bash <(curl -s https://codecov.io/bash);
9191
fi
9292
- if [ $FUNCTIONAL_TEST == "true" ]; then
93+
python -m pip install --upgrade -r functionalTestRequirements.txt
9394
npm run cover:enable;
9495
npm run test:functional;
9596
fi

.vscode/launch.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,23 @@
140140
"sourceMaps": true,
141141
"args": [
142142
"timeout=300000",
143-
"grep=History"
143+
"grep="
144+
],
145+
"outFiles": [
146+
"${workspaceFolder}/out/**/*.js"
147+
],
148+
"preLaunchTask": "Compile"
149+
},
150+
{
151+
"name": "Functional Tests (without VS Code, *.functional.test.ts)",
152+
"type": "node",
153+
"request": "launch",
154+
"program": "${workspaceFolder}/out/test/functionalTests.js",
155+
"stopOnEntry": false,
156+
"sourceMaps": true,
157+
"args": [
158+
"timeout=300000",
159+
"grep="
144160
],
145161
"outFiles": [
146162
"${workspaceFolder}/out/**/*.js"

functionalTestRequirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# List of requirements for functional tests
2+
jupyter

src/client/datascience/history.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export class History implements IWebPanelMessageListener, IHistory {
200200
@captureTelemetry(Telemetry.RestartKernel)
201201
private restartKernel() {
202202
if (this.jupyterServer) {
203-
this.jupyterServer.restartKernel();
203+
this.jupyterServer.restartKernel().ignoreErrors();
204204
}
205205
}
206206

src/client/datascience/jupyterServer.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export class JupyterServer implements INotebookServer {
181181
});
182182
}
183183

184-
return Promise.reject(localize.DataScience.sessionDisposed);
184+
return Promise.reject(new Error(localize.DataScience.sessionDisposed()));
185185
}
186186

187187
public get onStatusChanged() : vscode.Event<boolean> {
@@ -196,10 +196,12 @@ export class JupyterServer implements INotebookServer {
196196
}
197197
}
198198

199-
public restartKernel = () => {
199+
public restartKernel = () : Promise<void> => {
200200
if (this.session && this.session.kernel) {
201-
this.session.kernel.restart().ignoreErrors();
201+
return this.session.kernel.restart();
202202
}
203+
204+
return Promise.reject(new Error(localize.DataScience.sessionDisposed()));
203205
}
204206

205207
public translateToNotebook = async (cells: ICell[]) : Promise<nbformat.INotebookContent | undefined> => {

src/client/datascience/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface INotebookServer extends IDisposable {
3131
getCurrentState() : Promise<ICell[]>;
3232
executeObservable(code: string, file: string, line: number) : Observable<ICell[]>;
3333
execute(code: string, file: string, line: number) : Promise<ICell[]>;
34-
restartKernel();
34+
restartKernel() : Promise<void>;
3535
translateToNotebook(cells: ICell[]) : Promise<JSONObject | undefined>;
3636
launchNotebook(file: string) : Promise<boolean>;
3737
}

src/client/ioc/serviceManager.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3-
43
import { Container, injectable, interfaces } from 'inversify';
5-
import { Abstract, IServiceManager, Newable } from './types';
4+
5+
import { Abstract, ClassType, IServiceManager, Newable } from './types';
66

77
type identifier<T> = string | symbol | Newable<T> | Abstract<T>;
88

@@ -43,4 +43,13 @@ export class ServiceManager implements IServiceManager {
4343
public getAll<T>(serviceIdentifier: identifier<T>, name?: string | number | symbol | undefined): T[] {
4444
return name ? this.container.getAllNamed<T>(serviceIdentifier, name) : this.container.getAll<T>(serviceIdentifier);
4545
}
46+
47+
public rebind<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, constructor: ClassType<T>, name?: string | number | symbol): void {
48+
if (name) {
49+
this.container.rebind<T>(serviceIdentifier).to(constructor).whenTargetNamed(name);
50+
} else {
51+
this.container.rebind<T>(serviceIdentifier).to(constructor);
52+
}
53+
}
54+
4655
}

src/client/ioc/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface IServiceManager {
2626
addFactory<T>(factoryIdentifier: interfaces.ServiceIdentifier<interfaces.Factory<T>>, factoryMethod: interfaces.FactoryCreator<T>): void;
2727
get<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, name?: string | number | symbol): T;
2828
getAll<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, name?: string | number | symbol): T[];
29+
rebind<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, constructor: ClassType<T>, name?: string | number | symbol): void;
2930
}
3031

3132
export const IServiceContainer = Symbol('IServiceContainer');

0 commit comments

Comments
 (0)