Run All Cells Notebook Implementation (#4713)

* runAllCells API

* add comment

* more run cells fixes

* Add integration test

* Add multiple cell SQL notebook test

* Comment out python tests as they fail in the lab

* remove unused imports

* PR comments

* Remove localize

* Return true instead of promise.resolve(true)
This commit is contained in:
Chris LaFreniere
2019-04-02 16:47:00 -07:00
committed by GitHub
parent 219dfe66d0
commit 07166fb3cd
13 changed files with 165 additions and 11 deletions

View File

@@ -10,7 +10,7 @@ import * as assert from 'assert';
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import { context } from './testContext';
import { sqlNotebookContent, writeNotebookToFile, sqlKernelMetadata, getFileName, pySparkNotebookContent, pySpark3KernelMetadata, pythonKernelMetadata } from './notebook.util';
import { sqlNotebookContent, writeNotebookToFile, sqlKernelMetadata, getFileName, pySparkNotebookContent, pySpark3KernelMetadata, pythonKernelMetadata, sqlNotebookMultipleCellsContent } from './notebook.util';
import { getBdcServer } from './testConfig';
import { connectToServer } from './utils';
import * as fs from 'fs';
@@ -50,6 +50,22 @@ if (context.RunTest) {
assert(actualOutput2[0] === '1', `Expected result: 1, Actual: '${actualOutput2[0]}'`);
});
test('Sql NB multiple cells test', async function () {
let notebook = await openNotebook(sqlNotebookMultipleCellsContent, sqlKernelMetadata, this.test.title);
const expectedOutput0 = '(1 row affected)';
for (let i = 0; i < 3; i++) {
let cellOutputs = notebook.document.cells[i].contents.outputs;
console.log('Got cell outputs');
assert(cellOutputs.length === 3, `Expected length: 3, Actual: '${cellOutputs.length}'`);
let actualOutput0 = (<azdata.nb.IDisplayData>cellOutputs[0]).data['text/html'];
console.log('Got first output');
assert(actualOutput0 === expectedOutput0, `Expected row count: '${expectedOutput0}', Actual: '${actualOutput0}'`);
let actualOutput2 = (<azdata.nb.IExecuteResult>cellOutputs[2]).data['application/vnd.dataresource+json'].data[0];
assert(actualOutput2[0] === i.toString(), `Expected result: ${i.toString()}, Actual: '${actualOutput2[0]}'`);
console.log('Sql multiple cells NB done');
}
});
test('Clear all outputs - SQL notebook ', async function () {
let notebook = await openNotebook(sqlNotebookContent, sqlKernelMetadata, this.test.title);
await verifyClearAllOutputs(notebook);
@@ -81,7 +97,7 @@ if (context.RunTest) {
});
}
async function openNotebook(content: azdata.nb.INotebookContents, kernelMetadata: any, testName: string): Promise<azdata.nb.NotebookEditor> {
async function openNotebook(content: azdata.nb.INotebookContents, kernelMetadata: any, testName: string, runAllCells?: boolean): Promise<azdata.nb.NotebookEditor> {
let notebookConfig = vscode.workspace.getConfiguration('notebook');
notebookConfig.update('pythonPath', process.env.PYTHON_TEST_PATH, 1);
let server = await getBdcServer();
@@ -91,12 +107,20 @@ async function openNotebook(content: azdata.nb.INotebookContents, kernelMetadata
console.log(uri);
let notebook = await azdata.nb.showNotebookDocument(uri);
console.log('Notebook is opened');
assert(notebook.document.cells.length === 1, 'Notebook should have 1 cell');
console.log('Before run notebook cell');
let ran = await notebook.runCell(notebook.document.cells[0]);
console.log('After run notebook cell');
assert(ran, 'Notebook runCell should succeed');
assert(notebook !== undefined && notebook !== null, 'Expected notebook object is defined');
if (!runAllCells) {
assert(notebook.document.cells.length === 1, 'Notebook should have 1 cell');
console.log('Before run notebook cell');
let ran = await notebook.runCell(notebook.document.cells[0]);
console.log('After run notebook cell');
assert(ran, 'Notebook runCell should succeed');
} else {
console.log('Before run all notebook cells');
let ran = await notebook.runAllCells();
assert(ran, 'Notebook runCell should succeed');
assert(notebook !== undefined && notebook !== null, 'Expected notebook object is defined');
}
return notebook;
}
async function verifyClearAllOutputs(notebook: azdata.nb.NotebookEditor) {