forked from microsoft/azuredatastudio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Jupyter Notebook Manager Tests (microsoft#10955)
* jupyter notebook manager tests * cover config duplicate integrationTest
- Loading branch information
1 parent
8b68d52
commit 77ba5a3
Showing
2 changed files
with
116 additions
and
12 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
extensions/notebook/src/test/model/notebookManager.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the Source EULA. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as should from 'should'; | ||
import * as TypeMoq from 'typemoq'; | ||
import * as vscode from 'vscode'; | ||
import * as azdata from 'azdata'; | ||
import 'mocha'; | ||
|
||
import { LocalJupyterServerManager, ServerInstanceFactory, IServerManagerOptions } from '../../jupyter/jupyterServerManager'; | ||
import { JupyterServerInstallation } from '../../jupyter/jupyterServerInstallation'; | ||
import { Deferred } from '../../common/promise'; | ||
import { ApiWrapper } from '../../common/apiWrapper'; | ||
import { MockExtensionContext } from '../common/stubs'; | ||
import { JupyterSessionManager } from '../../jupyter/jupyterSessionManager'; | ||
import { JupyterNotebookManager } from '../../jupyter/jupyterNotebookManager'; | ||
import { initInstallAndInstance } from './serverManager.test'; | ||
|
||
describe('Jupyter Notebook Manager', function (): void { | ||
const pythonKernelSpec: azdata.nb.IKernelSpec = { | ||
name: 'python3', | ||
display_name: 'Python 3' | ||
}; | ||
let expectedPath = 'my/notebook.ipynb'; | ||
let serverManager: LocalJupyterServerManager; | ||
let sessionManager: JupyterSessionManager; | ||
let notebookManager: JupyterNotebookManager; | ||
let deferredInstall: Deferred<void>; | ||
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>; | ||
let mockExtensionContext: MockExtensionContext; | ||
let mockFactory: TypeMoq.IMock<ServerInstanceFactory>; | ||
let serverManagerOptions: IServerManagerOptions; | ||
beforeEach(() => { | ||
mockExtensionContext = new MockExtensionContext(); | ||
mockApiWrapper = TypeMoq.Mock.ofType(ApiWrapper); | ||
mockApiWrapper.setup(a => a.showErrorMessage(TypeMoq.It.isAny())); | ||
mockApiWrapper.setup(a => a.getWorkspacePathFromUri(TypeMoq.It.isAny())).returns(() => undefined); | ||
mockFactory = TypeMoq.Mock.ofType(ServerInstanceFactory); | ||
|
||
deferredInstall = new Deferred<void>(); | ||
let mockInstall = TypeMoq.Mock.ofType(JupyterServerInstallation, undefined, undefined, '/root'); | ||
mockInstall.setup(j => j.promptForPythonInstall(TypeMoq.It.isAny())).returns(() => deferredInstall.promise); | ||
mockInstall.object.execOptions = { env: Object.assign({}, process.env) }; | ||
|
||
serverManagerOptions = { | ||
documentPath: expectedPath, | ||
jupyterInstallation: mockInstall.object, | ||
extensionContext: mockExtensionContext, | ||
apiWrapper: mockApiWrapper.object, | ||
factory: mockFactory.object | ||
}; | ||
serverManager = new LocalJupyterServerManager(serverManagerOptions); | ||
|
||
sessionManager = new JupyterSessionManager(); | ||
notebookManager = new JupyterNotebookManager(serverManager, sessionManager); | ||
}); | ||
|
||
it('Server settings should be set', async function (): Promise<void> { | ||
should(notebookManager.serverSettings).be.undefined(); | ||
let expectedUri = vscode.Uri.parse('http://localhost:1234?token=abcdefghijk'); | ||
initInstallAndInstance(expectedUri, mockFactory); | ||
deferredInstall.resolve(); | ||
|
||
// When I start the server | ||
await serverManager.startServer(pythonKernelSpec); | ||
should(notebookManager.serverSettings.baseUrl).equal('http://localhost:1234', 'Server settings did not match expected value'); | ||
}); | ||
|
||
it('Session Manager should exist', async function (): Promise<void> { | ||
should(notebookManager.sessionManager).deepEqual(sessionManager); | ||
}); | ||
|
||
it('Server Manager should exist', async function (): Promise<void> { | ||
should(notebookManager.serverManager).deepEqual(serverManager); | ||
}); | ||
|
||
it('Content manager should always be undefined', async function (): Promise<void> { | ||
should(notebookManager.contentManager).be.undefined(); | ||
let expectedUri = vscode.Uri.parse('http://localhost:1234?token=abcdefghijk'); | ||
initInstallAndInstance(expectedUri, mockFactory); | ||
deferredInstall.resolve(); | ||
|
||
// When I start the server | ||
await serverManager.startServer(pythonKernelSpec); | ||
should(notebookManager.contentManager).be.undefined(); | ||
}); | ||
|
||
it('Session and server managers should be shutdown/stopped on dispose', async function(): Promise<void> { | ||
let sessionManager = TypeMoq.Mock.ofType<JupyterSessionManager>(); | ||
let serverManager = TypeMoq.Mock.ofType<LocalJupyterServerManager>(); | ||
notebookManager = new JupyterNotebookManager(serverManager.object, sessionManager.object, mockApiWrapper.object); | ||
sessionManager.setup(s => s.shutdownAll()).returns(() => new Promise((resolve) => resolve())); | ||
serverManager.setup(s => s.stopServer()).returns(() => new Promise((resolve) => resolve())); | ||
|
||
// After I dispose the notebook manager | ||
notebookManager.dispose(); | ||
|
||
// Session and server managers should be shutdown/stopped | ||
sessionManager.verify((s) => s.shutdownAll(), TypeMoq.Times.once()); | ||
serverManager.verify((s) => s.stopServer(), TypeMoq.Times.once()); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters