Skip to content

Commit

Permalink
Fix bad method calls in notebook execution test, via #164297 (#166078)
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens authored Nov 11, 2022
1 parent 9f2be31 commit e31078d
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { mock } from 'vs/base/test/common/mock';
import { assertThrowsAsync } from 'vs/base/test/common/utils';
import { PLAINTEXT_LANGUAGE_ID } from 'vs/editor/common/languages/modesRegistry';
import { IMenu, IMenuService } from 'vs/platform/actions/common/actions';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
import { insertCellAtIndex } from 'vs/workbench/contrib/notebook/browser/controller/cellOperations';
import { NotebookExecutionService } from 'vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl';
import { NotebookKernelService } from 'vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl';
Expand All @@ -29,6 +29,7 @@ import { setupInstantiationService, withTestNotebook as _withTestNotebook } from
suite('NotebookExecutionService', () => {

let instantiationService: TestInstantiationService;
let contextKeyService: IContextKeyService;
let kernelService: INotebookKernelService;
let disposables: DisposableStore;

Expand Down Expand Up @@ -56,6 +57,7 @@ suite('NotebookExecutionService', () => {

kernelService = instantiationService.createInstance(NotebookKernelService);
instantiationService.set(INotebookKernelService, kernelService);
contextKeyService = instantiationService.get(IContextKeyService);

});

Expand All @@ -77,48 +79,48 @@ suite('NotebookExecutionService', () => {
test('cell is not runnable when no kernel is selected', async () => {
await withTestNotebook(
[],
async (viewModel) => {
async (viewModel, textModel) => {
const executionService = instantiationService.createInstance(NotebookExecutionService);

const cell = insertCellAtIndex(viewModel, 1, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true);
await assertThrowsAsync(async () => await executionService.executeNotebookCell(cell));
await assertThrowsAsync(async () => await executionService.executeNotebookCells(textModel, [cell.model], contextKeyService));
});
});

test('cell is not runnable when kernel does not support the language', async () => {
await withTestNotebook(
[],
async (viewModel) => {
async (viewModel, textModel) => {

kernelService.registerKernel(new TestNotebookKernel({ languages: ['testlang'] }));
const executionService = instantiationService.createInstance(NotebookExecutionService);
const cell = insertCellAtIndex(viewModel, 1, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true);
await assertThrowsAsync(async () => await executionService.executeNotebookCell(cell));
await assertThrowsAsync(async () => await executionService.executeNotebookCells(textModel, [cell.model], contextKeyService));

});
});

test('cell is runnable when kernel does support the language', async () => {
await withTestNotebook(
[],
async (viewModel) => {
async (viewModel, textModel) => {
const kernel = new TestNotebookKernel({ languages: ['javascript'] });
kernelService.registerKernel(kernel);
const executionService = instantiationService.createInstance(NotebookExecutionService);
const executeSpy = sinon.spy();
kernel.executeNotebookCellsRequest = executeSpy;

const cell = insertCellAtIndex(viewModel, 0, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true);
await executionService.executeNotebookCells(viewModel.notebookDocument, [cell], new MockContextKeyService());
await executionService.executeNotebookCells(viewModel.notebookDocument, [cell.model], contextKeyService);
assert.strictEqual(executeSpy.calledOnce, true);
});
});

test('select kernel when running cell', async function () {
// https://github.com/microsoft/vscode/issues/121904

return withTestNotebook([], async viewModel => {
assert.strictEqual(kernelService.getMatchingKernel(viewModel.notebookDocument).all.length, 0);
return withTestNotebook([], async (viewModel, textModel) => {
assert.strictEqual(kernelService.getMatchingKernel(textModel).all.length, 0);

let didExecute = false;
const kernel = new class extends TestNotebookKernel {
Expand All @@ -140,7 +142,7 @@ suite('NotebookExecutionService', () => {
kernelService.onDidChangeSelectedNotebooks(e => event = e);

const cell = insertCellAtIndex(viewModel, 0, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true);
await executionService.executeNotebookCells(viewModel.notebookDocument, [cell], new MockContextKeyService());
await executionService.executeNotebookCells(textModel, [cell.model], contextKeyService);

assert.strictEqual(didExecute, true);
assert.ok(event !== undefined);
Expand All @@ -151,7 +153,7 @@ suite('NotebookExecutionService', () => {

test('Completes unconfirmed executions', async function () {

return withTestNotebook([], async viewModel => {
return withTestNotebook([], async (viewModel, textModel) => {
let didExecute = false;
const kernel = new class extends TestNotebookKernel {
constructor() {
Expand All @@ -170,7 +172,7 @@ suite('NotebookExecutionService', () => {
const exeStateService = instantiationService.get(INotebookExecutionStateService);

const cell = insertCellAtIndex(viewModel, 0, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true);
await executionService.executeNotebookCells(viewModel.notebookDocument, [cell], new MockContextKeyService());
await executionService.executeNotebookCells(textModel, [cell.model], contextKeyService);

assert.strictEqual(didExecute, true);
assert.strictEqual(exeStateService.getCellExecution(cell.uri), undefined);
Expand Down

0 comments on commit e31078d

Please sign in to comment.