-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add run above and run below to native notebooks (#4240)
* add run above and run below to native notebooks * address some comments * fix tests * add tests * register commands on the nativeEditorCommandListener * skipt tests
- Loading branch information
David Kutugata
authored
Dec 18, 2020
1 parent
ddbd89e
commit 6c215b1
Showing
13 changed files
with
267 additions
and
2 deletions.
There are no files selected for viewing
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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
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
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
102 changes: 102 additions & 0 deletions
102
src/test/datascience/notebook/notebookEditor.vscode.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,102 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
'use strict'; | ||
|
||
import { assert } from 'chai'; | ||
import { ICommandManager, IVSCodeNotebook } from '../../../client/common/application/types'; | ||
import { IDisposable } from '../../../client/common/types'; | ||
import { Commands } from '../../../client/datascience/constants'; | ||
import { INotebookEditorProvider } from '../../../client/datascience/types'; | ||
import { IExtensionTestApi } from '../../common'; | ||
import { initialize } from '../../initialize'; | ||
import { | ||
canRunNotebookTests, | ||
closeNotebooks, | ||
closeNotebooksAndCleanUpAfterTests, | ||
deleteAllCellsAndWait, | ||
insertCodeCell, | ||
waitForExecutionCompletedSuccessfully, | ||
waitForKernelToGetAutoSelected | ||
} from './helper'; | ||
const vscodeNotebookEnums = require('vscode') as typeof import('vscode-proposed'); | ||
|
||
suite('Notebook Editor tests', () => { | ||
let api: IExtensionTestApi; | ||
let vscodeNotebook: IVSCodeNotebook; | ||
let editorProvider: INotebookEditorProvider; | ||
let commandManager: ICommandManager; | ||
const disposables: IDisposable[] = []; | ||
|
||
suiteSetup(async function () { | ||
api = await initialize(); | ||
if (!(await canRunNotebookTests())) { | ||
return this.skip(); | ||
} | ||
vscodeNotebook = api.serviceContainer.get<IVSCodeNotebook>(IVSCodeNotebook); | ||
editorProvider = api.serviceContainer.get<INotebookEditorProvider>(INotebookEditorProvider); | ||
commandManager = api.serviceContainer.get<ICommandManager>(ICommandManager); | ||
}); | ||
|
||
setup(async function () { | ||
// Open a notebook and use this for all tests in this test suite. | ||
await editorProvider.createNew(); | ||
await waitForKernelToGetAutoSelected(); | ||
await deleteAllCellsAndWait(); | ||
assert.isOk(vscodeNotebook.activeNotebookEditor, 'No active notebook'); | ||
}); | ||
|
||
teardown(async function () { | ||
await closeNotebooks(disposables); | ||
await closeNotebooksAndCleanUpAfterTests(disposables); | ||
}); | ||
suiteTeardown(() => closeNotebooksAndCleanUpAfterTests(disposables)); | ||
|
||
test('Run cells below', async function () { | ||
// add some cells | ||
// https://github.com/microsoft/vscode-jupyter/issues/4250 | ||
this.skip(); | ||
await insertCodeCell('print("0")', { index: 0 }); | ||
await insertCodeCell('print("1")', { index: 1 }); | ||
await insertCodeCell('print("2")', { index: 2 }); | ||
|
||
// run command | ||
await commandManager.executeCommand( | ||
Commands.NativeNotebookRunCellAndAllBelow, | ||
vscodeNotebook.activeNotebookEditor?.document.uri! | ||
); | ||
const thirdCell = vscodeNotebook.activeNotebookEditor?.document.cells![2]!; | ||
await waitForExecutionCompletedSuccessfully(thirdCell); | ||
|
||
// The third cell should have a runState of Success | ||
assert.strictEqual(thirdCell?.metadata.runState, vscodeNotebookEnums.NotebookCellRunState.Success); | ||
}); | ||
|
||
test('Run cells above', async function () { | ||
// This test is skipped because there is no way of selecting a cell in this context | ||
// since by default the first cell is selected nothing happens when running all cells above | ||
// https://github.com/microsoft/vscode-jupyter/issues/4250 | ||
this.skip(); | ||
// add some cells | ||
await insertCodeCell('print("0")', { index: 0 }); | ||
await insertCodeCell('print("1")', { index: 1 }); | ||
await insertCodeCell('print("2")', { index: 2 }); | ||
|
||
// select second cell | ||
// this tries to get the second cell selected by running it, but it doesn't work | ||
// const secondCell = vscodeNotebook.activeNotebookEditor?.document.cells![1]!; | ||
// await executeCell(secondCell); | ||
// await waitForExecutionCompletedSuccessfully(secondCell); | ||
|
||
// run command | ||
await commandManager.executeCommand( | ||
Commands.NativeNotebookRunAllCellsAbove, | ||
vscodeNotebook.activeNotebookEditor?.document.uri! | ||
); | ||
const firstCell = vscodeNotebook.activeNotebookEditor?.document.cells![0]!; | ||
await waitForExecutionCompletedSuccessfully(firstCell); | ||
|
||
// The first cell should have a runState of Success | ||
assert.strictEqual(firstCell?.metadata.runState, vscodeNotebookEnums.NotebookCellRunState.Success); | ||
}); | ||
}); |