Skip to content

Commit

Permalink
Merge pull request #175814 from amunger/betterFailureMessage
Browse files Browse the repository at this point in the history
fail with more info
  • Loading branch information
amunger committed Mar 2, 2023
2 parents 825e84e + d989227 commit 5fb19ca
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,25 @@ async function addCell(code: string, notebook: vscode.NotebookDocument) {
const edit = vscode.NotebookEdit.insertCells(notebook.cellCount, [cell]);
const workspaceEdit = new vscode.WorkspaceEdit();
workspaceEdit.set(notebook.uri, [edit]);
const event = asPromise(vscode.workspace.onDidChangeNotebookDocument);
await vscode.workspace.applyEdit(workspaceEdit);
await event;
return notebook.cellAt(notebook.cellCount - 1);
}

async function addCellAndRun(code: string, notebook: vscode.NotebookDocument, i: number) {
async function addCellAndRun(code: string, notebook: vscode.NotebookDocument) {
const initialCellCount = notebook.cellCount;
const cell = await addCell(code, notebook);

const event = asPromise(vscode.workspace.onDidChangeNotebookDocument);
await vscode.commands.executeCommand('notebook.cell.execute', { start: i, end: i + 1 }, notebook.uri);
await event;
assert.strictEqual(cell.outputs.length, 1, 'execute failed');
await vscode.commands.executeCommand('notebook.cell.execute', { start: initialCellCount, end: initialCellCount + 1 }, notebook.uri);
try {
await event;
} catch (e) {
const result = notebook.cellAt(notebook.cellCount - 1);
assert.fail(`Notebook change event was not triggered after executing newly added cell. Initial Cell count: ${initialCellCount}. Current cell count: ${notebook.cellCount}. execution summary: ${JSON.stringify(result.executionSummary)}`);
}
assert.strictEqual(cell.outputs.length, 1, `Executed cell has no output. Initial Cell count: ${initialCellCount}. Current cell count: ${notebook.cellCount}. execution summary: ${JSON.stringify(cell.executionSummary)}`);
return cell;
}

Expand Down Expand Up @@ -86,7 +95,7 @@ async function addCellAndRun(code: string, notebook: vscode.NotebookDocument, i:

// Run and add a bunch of cells
for (let i = 0; i < 10; i++) {
await addCellAndRun(`print ${i}`, notebookEditor.notebook, i);
await addCellAndRun(`print ${i}`, notebookEditor.notebook);
}

// Verify visible range has the last cell
Expand All @@ -105,7 +114,7 @@ async function addCellAndRun(code: string, notebook: vscode.NotebookDocument, i:
assert.ok(notebookEditor);

// Verify the kernel is the secondary one
await addCellAndRun(`print`, notebookEditor.notebook, 0);
await addCellAndRun(`print`, notebookEditor.notebook);

assert.strictEqual(secondKernel.associatedNotebooks.has(notebookEditor.notebook.uri.toString()), true, `Secondary kernel was not set as the kernel for the interactive window`);

Expand Down

0 comments on commit 5fb19ca

Please sign in to comment.