-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Treat Native notebook tests as VS Code tests #14282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4898a27
c6151b3
78289f9
fbea55c
3f4117c
2e7aeec
196a884
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import { IApplicationShell } from '../../../../client/common/application/types'; | |
import { ProductNames } from '../../../../client/common/installer/productNames'; | ||
import { BufferDecoder } from '../../../../client/common/process/decoder'; | ||
import { ProcessService } from '../../../../client/common/process/proc'; | ||
import { IInstaller, InstallerResponse, Product } from '../../../../client/common/types'; | ||
import { IDisposable, IInstaller, InstallerResponse, Product } from '../../../../client/common/types'; | ||
import { createDeferred } from '../../../../client/common/utils/async'; | ||
import { Common, DataScience } from '../../../../client/common/utils/localize'; | ||
import { INotebookEditorProvider } from '../../../../client/datascience/types'; | ||
|
@@ -22,6 +22,7 @@ import { closeNotebooksAndCleanUpAfterTests } from '../../notebook/helper'; | |
|
||
// tslint:disable: no-invalid-this max-func-body-length no-function-expression no-any | ||
suite('DataScience Install IPyKernel (slow) (install)', () => { | ||
const disposables: IDisposable[] = []; | ||
const nbFile = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src/test/datascience/jupyter/kernels/nbWithKernel.ipynb'); | ||
const executable = getOSType() === OSType.Windows ? 'Scripts/python.exe' : 'bin/python'; // If running locally on Windows box. | ||
const venvPythonPath = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src/test/datascience/.venvnokernel', executable); | ||
|
@@ -55,7 +56,7 @@ suite('DataScience Install IPyKernel (slow) (install)', () => { | |
}); | ||
|
||
setup(closeActiveWindows); | ||
teardown(closeNotebooksAndCleanUpAfterTests); | ||
teardown(() => closeNotebooksAndCleanUpAfterTests(disposables)); | ||
|
||
test('Test Install IPyKernel prompt message', async () => { | ||
// Confirm the message has not changed. | ||
|
@@ -72,7 +73,7 @@ suite('DataScience Install IPyKernel (slow) (install)', () => { | |
const installed = createDeferred(); | ||
|
||
// Confirm it is installed. | ||
sinon.stub(installer, 'install').callsFake(async function (product: Product) { | ||
const showInformationMessage = sinon.stub(installer, 'install').callsFake(async function (product: Product) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to revert the stubs in each test. |
||
// Call original method | ||
const result: InstallerResponse = await ((installer.install as any).wrappedMethod.apply( | ||
installer, | ||
|
@@ -83,6 +84,7 @@ suite('DataScience Install IPyKernel (slow) (install)', () => { | |
} | ||
return result; | ||
}); | ||
disposables.push({ dispose: () => showInformationMessage.restore() }); | ||
|
||
// Confirm message is displayed & we click 'Install` button. | ||
sinon.stub(appShell, 'showErrorMessage').callsFake(function (message: string) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,9 @@ import { assert } from 'chai'; | |
import * as sinon from 'sinon'; | ||
import { commands, NotebookEditor as VSCNotebookEditor } from 'vscode'; | ||
import { IApplicationShell, IVSCodeNotebook } from '../../../client/common/application/types'; | ||
import { IConfigurationService, IDataScienceSettings, IDisposable } from '../../../client/common/types'; | ||
import { IDisposable } from '../../../client/common/types'; | ||
import { createDeferredFromPromise } from '../../../client/common/utils/async'; | ||
import { DataScience } from '../../../client/common/utils/localize'; | ||
import { noop } from '../../../client/common/utils/misc'; | ||
import { IKernelProvider } from '../../../client/datascience/jupyter/kernels/types'; | ||
import { INotebookEditorProvider } from '../../../client/datascience/types'; | ||
|
@@ -27,9 +28,8 @@ import { | |
trustAllNotebooks, | ||
waitForTextOutputInVSCode | ||
} from './helper'; | ||
// tslint:disable-next-line: no-var-requires no-require-imports | ||
|
||
// tslint:disable: no-any no-invalid-this | ||
// tslint:disable: no-any no-invalid-this no-function-expression | ||
/* | ||
* This test focuses on interrupting, restarting kernels. | ||
* We will not use actual kernels, just ensure the appropriate methods are invoked on the appropriate classes. | ||
|
@@ -45,8 +45,6 @@ suite('DataScience - VSCode Notebook - Restart/Interrupt/Cancel/Errors (slow)', | |
let vscEditor: VSCNotebookEditor; | ||
let vscodeNotebook: IVSCodeNotebook; | ||
const suiteDisposables: IDisposable[] = []; | ||
let oldAskForRestart: boolean | undefined; | ||
let dsSettings: IDataScienceSettings; | ||
suiteSetup(async function () { | ||
this.timeout(60_000); | ||
api = await initialize(); | ||
|
@@ -59,11 +57,6 @@ suite('DataScience - VSCode Notebook - Restart/Interrupt/Cancel/Errors (slow)', | |
editorProvider = api.serviceContainer.get<INotebookEditorProvider>(INotebookEditorProvider); | ||
editorProvider = api.serviceContainer.get<INotebookEditorProvider>(INotebookEditorProvider); | ||
kernelProvider = api.serviceContainer.get<IKernelProvider>(IKernelProvider); | ||
dsSettings = api.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(undefined) | ||
.datascience; | ||
oldAskForRestart = dsSettings.askForKernelRestart; | ||
// Disable the prompt (when attempting to restart kernel). | ||
dsSettings.askForKernelRestart = false; | ||
}); | ||
setup(async () => { | ||
sinon.restore(); | ||
|
@@ -74,12 +67,7 @@ suite('DataScience - VSCode Notebook - Restart/Interrupt/Cancel/Errors (slow)', | |
vscEditor = vscodeNotebook.activeNotebookEditor!; | ||
}); | ||
teardown(() => closeNotebooks(disposables)); | ||
suiteTeardown(async () => { | ||
oldAskForRestart = dsSettings.askForKernelRestart; | ||
// Restore. | ||
dsSettings.askForKernelRestart = oldAskForRestart; | ||
await closeNotebooksAndCleanUpAfterTests(disposables.concat(suiteDisposables)); | ||
}); | ||
suiteTeardown(async () => closeNotebooksAndCleanUpAfterTests(disposables.concat(suiteDisposables))); | ||
|
||
test('Cancelling token will cancel cell execution', async () => { | ||
await insertPythonCell('import time\nfor i in range(10000):\n print(i)\n time.sleep(0.1)', 0); | ||
|
@@ -118,7 +106,20 @@ suite('DataScience - VSCode Notebook - Restart/Interrupt/Cancel/Errors (slow)', | |
test('Restarting kernel will cancel cell execution & we can re-run a cell', async () => { | ||
await insertPythonCell('import time\nfor i in range(10000):\n print(i)\n time.sleep(0.1)', 0); | ||
const cell = vscEditor.document.cells[0]; | ||
// Ensure we click `Yes` when prompted to restart the kernel. | ||
const appShell = api.serviceContainer.get<IApplicationShell>(IApplicationShell); | ||
const showInformationMessage = sinon | ||
.stub(appShell, 'showInformationMessage') | ||
.callsFake(function (message: string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better & easier test, than updating the settings There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also can be used to confirm prompt is displayed. |
||
if (message === DataScience.restartKernelMessage()) { | ||
// User clicked ok to restart it. | ||
return DataScience.restartKernelMessageYes(); | ||
} | ||
return (appShell.showInformationMessage as any).wrappedMethod.apply(appShell, arguments); | ||
}); | ||
disposables.push({ dispose: () => showInformationMessage.restore() }); | ||
|
||
(editorProvider.activeEditor as any).shouldAskForRestart = () => Promise.resolve(false); | ||
await executeActiveDocument(); | ||
|
||
// Wait for cell to get busy. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to changes in API, we need to ensure cell status is updated.