Skip to content

Commit

Permalink
oops
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed Jul 14, 2022
1 parent 8f31538 commit 0dddb70
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 38 deletions.
6 changes: 2 additions & 4 deletions src/test/datascience/widgets/commUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
import { NotebookCell, NotebookEditor, NotebookRendererMessaging, notebooks } from 'vscode';
import { disposeAllDisposables } from '../../../platform/common/helpers';
import { traceInfo, traceInfoIfCI } from '../../../platform/logging';
import { IDisposable, IDisposableRegistry } from '../../../platform/common/types';
import { IDisposable } from '../../../platform/common/types';
import { createDeferred } from '../../../platform/common/utils/async';
import { IServiceContainer } from '../../../platform/ioc/types';
import { noop } from '../../core';
import { IPyWidgetRendererId } from '../../../platform/common/constants';
import * as colors from 'colors';

export function initializeWidgetComms(serviceContainer: IServiceContainer): Utils {
const disposables = serviceContainer.get<IDisposableRegistry>(IDisposableRegistry);
export function initializeWidgetComms(disposables: IDisposable[]): Utils {
const messageChannel = notebooks.createRendererMessaging(IPyWidgetRendererId);
if (!messageChannel) {
throw new Error('No Widget renderer comms channel');
Expand Down
5 changes: 0 additions & 5 deletions src/test/datascience/widgets/rendererUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ function initializeComms() {
return;
}
rendererContext.onDidReceiveMessage((message) => {
rendererContext.postMessage!({
command: 'log',
message: `Received message in Widget renderer ${JSON.stringify(message)}`
});

if (!message || !message.command) {
return;
}
Expand Down
35 changes: 17 additions & 18 deletions src/test/datascience/widgets/standardWidgets.vscode.common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const templateRootPath: Uri =
? urlPath.joinPath(workspace.workspaceFolders[0].uri, 'widgets', 'notebooks')
: Uri.file('');
export async function initializeNotebookForWidgetTest(
api: IExtensionTestApi,
disposables: IDisposable[],
options: { templateFile: string } | { notebookFile: Uri }
) {
Expand All @@ -55,7 +54,7 @@ export async function initializeNotebookForWidgetTest(
await commands.executeCommand('workbench.action.closePanel');
await commands.executeCommand('workbench.action.maximizeEditor');
await commands.executeCommand('notebook.cell.collapseAllCellInputs');
return initializeWidgetComms(api.serviceContainer);
return initializeWidgetComms(disposables);
}
export async function executeCellAndWaitForOutput(cell: NotebookCell, comms: Utils) {
await Promise.all([
Expand Down Expand Up @@ -136,21 +135,21 @@ suite('Standard IPyWidget Tests', function () {
});
suiteTeardown(async () => closeNotebooksAndCleanUpAfterTests(disposables));
test('Slider Widget', async function () {
const comms = await initializeNotebookForWidgetTest(api, disposables, { templateFile: 'slider_widgets.ipynb' });
const comms = await initializeNotebookForWidgetTest(disposables, { templateFile: 'slider_widgets.ipynb' });
const cell = vscodeNotebook.activeNotebookEditor?.notebook.cellAt(0)!;
await executeCellAndWaitForOutput(cell, comms);
await assertOutputContainsHtml(cell, comms, ['6519'], '.widget-readout');
});
test('Textbox Widget', async () => {
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'standard_widgets.ipynb'
});
const cell = vscodeNotebook.activeNotebookEditor?.notebook.cellAt(1)!;
await executeCellAndWaitForOutput(cell, comms);
await assertOutputContainsHtml(cell, comms, ['<input type="text', 'Enter your name:'], '.widget-text');
});
test('Linking Widgets slider to textbox widget', async function () {
const comms = await initializeNotebookForWidgetTest(api, disposables, { templateFile: 'slider_widgets.ipynb' });
const comms = await initializeNotebookForWidgetTest(disposables, { templateFile: 'slider_widgets.ipynb' });
const [, cell1, cell2, cell3] = vscodeNotebook.activeNotebookEditor!.notebook.getCells()!;
await executeCellAndDontWaitForOutput(cell1);
await executeCellAndWaitForOutput(cell2, comms);
Expand All @@ -165,15 +164,15 @@ suite('Standard IPyWidget Tests', function () {
await assertOutputContainsHtml(cell2, comms, ['60'], '.widget-readout');
});
test('Checkbox Widget', async () => {
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'standard_widgets.ipynb'
});
const cell = vscodeNotebook.activeNotebookEditor?.notebook.cellAt(2)!;
await executeCellAndWaitForOutput(cell, comms);
await assertOutputContainsHtml(cell, comms, ['Check me', '<input type="checkbox'], '.widget-checkbox');
});
test('Button Widget (click button)', async () => {
const comms = await initializeNotebookForWidgetTest(api, disposables, { templateFile: 'button_widgets.ipynb' });
const comms = await initializeNotebookForWidgetTest(disposables, { templateFile: 'button_widgets.ipynb' });
const [cell0, cell1, cell2] = vscodeNotebook.activeNotebookEditor!.notebook.getCells();

await executeCellAndWaitForOutput(cell0, comms);
Expand All @@ -189,7 +188,7 @@ suite('Standard IPyWidget Tests', function () {
await assertOutputContainsHtml(cell2, comms, ['Button clicked']);
});
test('Button Widget (click button in output of another cell)', async () => {
const comms = await initializeNotebookForWidgetTest(api, disposables, { templateFile: 'button_widgets.ipynb' });
const comms = await initializeNotebookForWidgetTest(disposables, { templateFile: 'button_widgets.ipynb' });
const [cell0, cell1, cell2] = vscodeNotebook.activeNotebookEditor!.notebook.getCells();

await executeCellAndWaitForOutput(cell0, comms);
Expand All @@ -205,7 +204,7 @@ suite('Standard IPyWidget Tests', function () {
await assertOutputContainsHtml(cell2, comms, ['Button clicked']);
});
test('Button Widget with custom comm message', async () => {
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'button_widget_comm_msg.ipynb'
});
const [cell0, cell1] = vscodeNotebook.activeNotebookEditor!.notebook.getCells();
Expand All @@ -220,7 +219,7 @@ suite('Standard IPyWidget Tests', function () {
});
test.skip('Widget renders after executing a notebook which was saved after previous execution', async () => {
// https://github.com/microsoft/vscode-jupyter/issues/8748
let comms = await initializeNotebookForWidgetTest(api, disposables, { templateFile: 'standard_widgets.ipynb' });
let comms = await initializeNotebookForWidgetTest(disposables, { templateFile: 'standard_widgets.ipynb' });
const cell = vscodeNotebook.activeNotebookEditor?.notebook.cellAt(0)!;
await executeCellAndWaitForOutput(cell, comms);
await assertOutputContainsHtml(cell, comms, ['66'], '.widget-readout');
Expand All @@ -231,7 +230,7 @@ suite('Standard IPyWidget Tests', function () {
await closeActiveWindows();

// Open this notebook again.
comms = await initializeNotebookForWidgetTest(api, disposables, { notebookFile: uri });
comms = await initializeNotebookForWidgetTest(disposables, { notebookFile: uri });

// Verify we have output in the first cell.
assert.isOk(cell.outputs.length, 'No outputs in the cell after saving nb');
Expand All @@ -240,7 +239,7 @@ suite('Standard IPyWidget Tests', function () {
await assertOutputContainsHtml(cell, comms, ['66'], '.widget-readout');
});
test.skip('Widget renders after restarting kernel', async () => {
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'standard_widgets.ipynb'
});
const cell = vscodeNotebook.activeNotebookEditor?.notebook.cellAt(0)!;
Expand All @@ -263,7 +262,7 @@ suite('Standard IPyWidget Tests', function () {
});
test.skip('Widget renders after interrupting kernel', async () => {
// https://github.com/microsoft/vscode-jupyter/issues/8749
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'standard_widgets.ipynb'
});
const cell = vscodeNotebook.activeNotebookEditor?.notebook.cellAt(0)!;
Expand All @@ -285,7 +284,7 @@ suite('Standard IPyWidget Tests', function () {
await assertOutputContainsHtml(cell, comms, ['66'], '.widget-readout');
});
test('Nested Output Widgets', async () => {
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'nested_output_widget.ipynb'
});
const [cell1, cell2, cell3, cell4] = vscodeNotebook.activeNotebookEditor!.notebook.getCells();
Expand Down Expand Up @@ -313,7 +312,7 @@ suite('Standard IPyWidget Tests', function () {
assert.strictEqual(cell3.outputs.length, 0, 'Cell 3 should not have any output');
});
test('More Nested Output Widgets', async () => {
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'nested_output_widget2.ipynb'
});
const [cell1, cell2, cell3, cell4, cell5, cell6] = vscodeNotebook.activeNotebookEditor!.notebook.getCells();
Expand Down Expand Up @@ -443,7 +442,7 @@ suite('Standard IPyWidget Tests', function () {
);
});
test('Interactive Button', async () => {
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'interactive_button.ipynb'
});
const cell = vscodeNotebook.activeNotebookEditor!.notebook.cellAt(0);
Expand All @@ -463,7 +462,7 @@ suite('Standard IPyWidget Tests', function () {
);
});
test('Interactive Function', async () => {
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'interactive_function.ipynb'
});
const cell = vscodeNotebook.activeNotebookEditor!.notebook.cellAt(0);
Expand All @@ -489,7 +488,7 @@ suite('Standard IPyWidget Tests', function () {
assert.strictEqual(getTextOutputValue(cell.outputs[2]).trim(), `'Hello World'`);
});
test('Interactive Plot', async () => {
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'interactive_plot.ipynb'
});
const cell = vscodeNotebook.activeNotebookEditor!.notebook.cellAt(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import { GlobalStateKeyToTrackIfUserConfiguredCDNAtLeastOnce } from '../../../ke
suiteTeardown(async () => closeNotebooksAndCleanUpAfterTests(disposables));

test('Button Widget with custom comm message rendering a matplotlib widget', async () => {
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'button_widget_comm_msg_matplotlib.ipynb'
});
const [cell0, cell1] = vscodeNotebook.activeNotebookEditor!.notebook.getCells();
Expand All @@ -106,7 +106,7 @@ import { GlobalStateKeyToTrackIfUserConfiguredCDNAtLeastOnce } from '../../../ke
// https://github.com/microsoft/vscode-jupyter/issues/10506
return this.skip();
}
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'ipySheet_widgets.ipynb'
});
const [, cell1] = vscodeNotebook.activeNotebookEditor!.notebook.getCells();
Expand All @@ -119,7 +119,7 @@ import { GlobalStateKeyToTrackIfUserConfiguredCDNAtLeastOnce } from '../../../ke
// https://github.com/microsoft/vscode-jupyter/issues/10506
return this.skip();
}
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'ipySheet_widgets_search.ipynb'
});
const [, cell1, cell2] = vscodeNotebook.activeNotebookEditor!.notebook.getCells();
Expand All @@ -138,7 +138,7 @@ import { GlobalStateKeyToTrackIfUserConfiguredCDNAtLeastOnce } from '../../../ke
// https://github.com/microsoft/vscode-jupyter/issues/10506
return this.skip();
}
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'ipySheet_widgets_slider.ipynb'
});
const [, cell1, cell2, cell3] = vscodeNotebook.activeNotebookEditor!.notebook.getCells();
Expand All @@ -155,7 +155,7 @@ import { GlobalStateKeyToTrackIfUserConfiguredCDNAtLeastOnce } from '../../../ke
await assertOutputContainsHtml(cell3, comms, ['>5255<', '>5378.0']);
});
test('Render ipyvolume (slider, color picker, figure)', async function () {
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'ipyvolume_widgets.ipynb'
});
const cell = vscodeNotebook.activeNotebookEditor!.notebook.cellAt(1);
Expand All @@ -175,7 +175,7 @@ import { GlobalStateKeyToTrackIfUserConfiguredCDNAtLeastOnce } from '../../../ke
await assertOutputContainsHtml(cell, comms, ['<input type="color"', '>Slider1<', '>Slider2<', '<canvas']);
});
test('Render pythreejs', async function () {
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'pythreejs_widgets.ipynb'
});
const cell = vscodeNotebook.activeNotebookEditor!.notebook.cellAt(1);
Expand All @@ -184,7 +184,7 @@ import { GlobalStateKeyToTrackIfUserConfiguredCDNAtLeastOnce } from '../../../ke
await assertOutputContainsHtml(cell, comms, ['<canvas']);
});
test('Render pythreejs, 2', async function () {
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'pythreejs_widgets2.ipynb'
});
const cell = vscodeNotebook.activeNotebookEditor!.notebook.cellAt(1);
Expand All @@ -193,7 +193,7 @@ import { GlobalStateKeyToTrackIfUserConfiguredCDNAtLeastOnce } from '../../../ke
await assertOutputContainsHtml(cell, comms, ['<canvas']);
});
test('Render matplotlib, interactive inline', async function () {
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'matplotlib_widgets_interactive.ipynb'
});
const cell = vscodeNotebook.activeNotebookEditor!.notebook.cellAt(1);
Expand All @@ -202,7 +202,7 @@ import { GlobalStateKeyToTrackIfUserConfiguredCDNAtLeastOnce } from '../../../ke
await assertOutputContainsHtml(cell, comms, ['>m<', '>b<', '<img src="data:image']);
});
test('Render matplotlib, non-interactive inline', async function () {
await initializeNotebookForWidgetTest(api, disposables, {
await initializeNotebookForWidgetTest(disposables, {
templateFile: 'matplotlib_widgets_inline.ipynb'
});
const cell = vscodeNotebook.activeNotebookEditor!.notebook.cellAt(2);
Expand All @@ -217,7 +217,7 @@ import { GlobalStateKeyToTrackIfUserConfiguredCDNAtLeastOnce } from '../../../ke
);
});
test('Render matplotlib, widget', async function () {
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'matplotlib_widgets_widget.ipynb'
});
const cell = vscodeNotebook.activeNotebookEditor!.notebook.cellAt(3);
Expand All @@ -226,7 +226,7 @@ import { GlobalStateKeyToTrackIfUserConfiguredCDNAtLeastOnce } from '../../../ke
await assertOutputContainsHtml(cell, comms, ['>Figure 1<', '<canvas', 'Download plot']);
});
test('Render matplotlib, widget in multiple cells', async function () {
const comms = await initializeNotebookForWidgetTest(api, disposables, {
const comms = await initializeNotebookForWidgetTest(disposables, {
templateFile: 'matplotlib_multiple_cells_widgets.ipynb'
});
const [, cell1, cell2, cell3] = vscodeNotebook.activeNotebookEditor!.notebook.getCells();
Expand Down

0 comments on commit 0dddb70

Please sign in to comment.