uncommented old tests and fixed them (#8834)

* uncommneted old tests and fixed them

* removed comments
This commit is contained in:
Maddy
2020-01-08 13:21:40 -08:00
committed by GitHub
parent fa4ad6cdb9
commit 61cbc5eff0

View File

@@ -11,11 +11,10 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService'; import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import { LocalContentManager } from 'sql/workbench/services/notebook/common/localContentManager';
import { NotebookManagerStub } from 'sql/workbench/contrib/notebook/test/stubs'; import { NotebookManagerStub } from 'sql/workbench/contrib/notebook/test/stubs';
import { NotebookModel } from 'sql/workbench/contrib/notebook/browser/models/notebookModel'; import { NotebookModel } from 'sql/workbench/contrib/notebook/browser/models/notebookModel';
import { ModelFactory } from 'sql/workbench/contrib/notebook/browser/models/modelFactory'; import { ModelFactory } from 'sql/workbench/contrib/notebook/browser/models/modelFactory';
import { IClientSession, INotebookModelOptions, NotebookContentChange } from 'sql/workbench/contrib/notebook/browser/models/modelInterfaces'; import { IClientSession, INotebookModelOptions, NotebookContentChange, IClientSessionOptions } from 'sql/workbench/contrib/notebook/browser/models/modelInterfaces';
import { ClientSession } from 'sql/workbench/contrib/notebook/browser/models/clientSession'; import { ClientSession } from 'sql/workbench/contrib/notebook/browser/models/clientSession';
import { CellTypes, NotebookChangeType } from 'sql/workbench/contrib/notebook/common/models/contracts'; import { CellTypes, NotebookChangeType } from 'sql/workbench/contrib/notebook/common/models/contracts';
import { Deferred } from 'sql/base/common/promise'; import { Deferred } from 'sql/base/common/promise';
@@ -31,16 +30,18 @@ import { NullLogService } from 'vs/platform/log/common/log';
import { TestConnectionManagementService } from 'sql/platform/connection/test/common/testConnectionManagementService'; import { TestConnectionManagementService } from 'sql/platform/connection/test/common/testConnectionManagementService';
import { isUndefinedOrNull } from 'vs/base/common/types'; import { isUndefinedOrNull } from 'vs/base/common/types';
import { assign } from 'vs/base/common/objects'; import { assign } from 'vs/base/common/objects';
import { NotebookEditorContentManager } from 'sql/workbench/contrib/notebook/browser/models/notebookInput';
import { SessionManager } from 'sql/workbench/services/notebook/browser/sessionManager';
let expectedNotebookContent: nb.INotebookContents = { let expectedNotebookContent: nb.INotebookContents = {
cells: [{ cells: [{
cell_type: CellTypes.Code, cell_type: CellTypes.Code,
source: 'insert into t1 values (c1, c2)', source: ['insert into t1 values (c1, c2)'],
metadata: { language: 'python' }, metadata: { language: 'python' },
execution_count: 1 execution_count: 1
}, { }, {
cell_type: CellTypes.Markdown, cell_type: CellTypes.Markdown,
source: 'I am *markdown*', source: ['I am *markdown*'],
metadata: { language: 'python' }, metadata: { language: 'python' },
execution_count: 1 execution_count: 1
}], }],
@@ -57,7 +58,7 @@ let expectedNotebookContent: nb.INotebookContents = {
let expectedNotebookContentOneCell: nb.INotebookContents = { let expectedNotebookContentOneCell: nb.INotebookContents = {
cells: [{ cells: [{
cell_type: CellTypes.Code, cell_type: CellTypes.Code,
source: 'insert into t1 values (c1, c2)', source: ['insert into t1 values (c1, c2)'],
metadata: { language: 'python' }, metadata: { language: 'python' },
execution_count: 1 execution_count: 1
}], }],
@@ -74,6 +75,7 @@ let expectedNotebookContentOneCell: nb.INotebookContents = {
let defaultUri = URI.file('/some/path.ipynb'); let defaultUri = URI.file('/some/path.ipynb');
let mockClientSession: TypeMoq.Mock<IClientSession>; let mockClientSession: TypeMoq.Mock<IClientSession>;
let clientSessionOptions: IClientSessionOptions;
let sessionReady: Deferred<void>; let sessionReady: Deferred<void>;
let mockModelFactory: TypeMoq.Mock<ModelFactory>; let mockModelFactory: TypeMoq.Mock<ModelFactory>;
let notificationService: TypeMoq.Mock<INotificationService>; let notificationService: TypeMoq.Mock<INotificationService>;
@@ -82,11 +84,14 @@ let instantiationService: IInstantiationService;
suite('notebook model', function (): void { suite('notebook model', function (): void {
let notebookManagers = [new NotebookManagerStub()]; let notebookManagers = [new NotebookManagerStub()];
let mockSessionManager: TypeMoq.Mock<nb.SessionManager>;
let memento: TypeMoq.Mock<Memento>; let memento: TypeMoq.Mock<Memento>;
let queryConnectionService: TypeMoq.Mock<TestConnectionManagementService>; let queryConnectionService: TypeMoq.Mock<TestConnectionManagementService>;
let defaultModelOptions: INotebookModelOptions; let defaultModelOptions: INotebookModelOptions;
const logService = new NullLogService(); const logService = new NullLogService();
setup(() => { setup(() => {
mockSessionManager = TypeMoq.Mock.ofType(SessionManager);
notebookManagers[0].sessionManager = mockSessionManager.object;
sessionReady = new Deferred<void>(); sessionReady = new Deferred<void>();
notificationService = TypeMoq.Mock.ofType(TestNotificationService, TypeMoq.MockBehavior.Loose); notificationService = TypeMoq.Mock.ofType(TestNotificationService, TypeMoq.MockBehavior.Loose);
capabilitiesService = TypeMoq.Mock.ofType(TestCapabilitiesService); capabilitiesService = TypeMoq.Mock.ofType(TestCapabilitiesService);
@@ -109,7 +114,13 @@ suite('notebook model', function (): void {
layoutChanged: undefined, layoutChanged: undefined,
capabilitiesService: capabilitiesService.object capabilitiesService: capabilitiesService.object
}; };
mockClientSession = TypeMoq.Mock.ofType(ClientSession, undefined, defaultModelOptions); clientSessionOptions = {
notebookManager: defaultModelOptions.notebookManagers[0],
notebookUri: defaultModelOptions.notebookUri,
notificationService: notificationService.object,
kernelSpec: defaultModelOptions.defaultKernel
};
mockClientSession = TypeMoq.Mock.ofType(ClientSession, undefined, clientSessionOptions);
mockClientSession.setup(c => c.initialize()).returns(() => { mockClientSession.setup(c => c.initialize()).returns(() => {
return Promise.resolve(); return Promise.resolve();
}); });
@@ -135,9 +146,9 @@ suite('notebook model', function (): void {
nbformat_minor: 5 nbformat_minor: 5
}; };
let mockContentManager = TypeMoq.Mock.ofType(LocalContentManager); let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
mockContentManager.setup(c => c.getNotebookContents(TypeMoq.It.isAny())).returns(() => Promise.resolve(emptyNotebook)); mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(emptyNotebook));
notebookManagers[0].contentManager = mockContentManager.object; defaultModelOptions.contentManager = mockContentManager.object;
// When I initialize the model // When I initialize the model
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, undefined); let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, undefined);
await model.loadContents(); await model.loadContents();
@@ -150,9 +161,9 @@ suite('notebook model', function (): void {
test('Should use trusted state set in model load', async function (): Promise<void> { test('Should use trusted state set in model load', async function (): Promise<void> {
// Given a notebook // Given a notebook
let mockContentManager = TypeMoq.Mock.ofType(LocalContentManager); let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
mockContentManager.setup(c => c.getNotebookContents(TypeMoq.It.isAny())).returns(() => Promise.resolve(expectedNotebookContent)); mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
notebookManagers[0].contentManager = mockContentManager.object; defaultModelOptions.contentManager = mockContentManager.object;
// When I initialize the model // When I initialize the model
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, undefined); let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, undefined);
await model.loadContents(true); await model.loadContents(true);
@@ -162,70 +173,69 @@ suite('notebook model', function (): void {
assert(model.trustedMode); assert(model.trustedMode);
}); });
// test('Should throw if model load fails', async function(): Promise<void> { test('Should throw if model load fails', async function (): Promise<void> {
// // Given a call to get Contents fails // Given a call to get Contents fails
// let error = new Error('File not found'); let error = new Error('File not found');
// let mockContentManager = TypeMoq.Mock.ofType(LocalContentManager); let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
// mockContentManager.setup(c => c.getNotebookContents(TypeMoq.It.isAny())).throws(error); mockContentManager.setup(c => c.loadContent()).returns(() => Promise.reject(error));//.throws(error);
// notebookManagers[0].contentManager = mockContentManager.object; defaultModelOptions.contentManager = mockContentManager.object;
// // When I initalize the model // When I initalize the model
// // Then it should throw // Then it should throw
// let model = new NotebookModel(defaultModelOptions); let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, undefined);
// should(model.inErrorState).be.false(); assert.equal(model.inErrorState, false);
// await testUtils.assertThrowsAsync(() => model.requestModelLoad(), error.message); await assert.rejects(async () => { await model.loadContents(); });
// should(model.inErrorState).be.true(); assert.equal(model.inErrorState, true);
// }); });
// test('Should convert cell info to CellModels', async function(): Promise<void> { test('Should convert cell info to CellModels', async function (): Promise<void> {
// // Given a notebook with 2 cells // Given a notebook with 2 cells
// let mockContentManager = TypeMoq.Mock.ofType(LocalContentManager); let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
// mockContentManager.setup(c => c.getNotebookContents(TypeMoq.It.isAny())).returns(() => Promise.resolve(expectedNotebookContent)); mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
// notebookManagers[0].contentManager = mockContentManager.object; defaultModelOptions.contentManager = mockContentManager.object;
// // When I initalize the model // When I initalize the model
// let model = new NotebookModel(defaultModelOptions); let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, undefined);
// await model.requestModelLoad(); await model.loadContents();
// // Then I expect all cells to be in the model // Then I expect all cells to be in the model
// should(model.cells).have.length(2); assert.equal(model.cells.length, 2);
// should(model.cells[0].source).be.equal(expectedNotebookContent.cells[0].source); assert.deepEqual(model.cells[0].source, expectedNotebookContent.cells[0].source);
// should(model.cells[1].source).be.equal(expectedNotebookContent.cells[1].source); assert.deepEqual(model.cells[1].source, expectedNotebookContent.cells[1].source);
// }); });
// test('Should load contents but then go to error state if client session startup fails', async function(): Promise<void> { test('Should load contents but then go to error state if client session startup fails', async function (): Promise<void> {
// let mockContentManager = TypeMoq.Mock.ofType(LocalContentManager); let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
// mockContentManager.setup(c => c.getNotebookContents(TypeMoq.It.isAny())).returns(() => Promise.resolve(expectedNotebookContentOneCell)); mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContentOneCell));
// notebookManagers[0].contentManager = mockContentManager.object; defaultModelOptions.contentManager = mockContentManager.object;
// // Given I have a session that fails to start // Given I have a session that fails to start
// mockClientSession.setup(c => c.isInErrorState).returns(() => true); mockClientSession.setup(c => c.isInErrorState).returns(() => true);
// mockClientSession.setup(c => c.errorMessage).returns(() => 'Error'); mockClientSession.setup(c => c.errorMessage).returns(() => 'Error');
// sessionReady.resolve(); sessionReady.resolve();
// let sessionFired = false; let sessionFired = false;
// let options: INotebookModelOptions = Object.assign({}, defaultModelOptions, <Partial<INotebookModelOptions>> { let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, undefined);
// factory: mockModelFactory.object model.onClientSessionReady((session) => sessionFired = true);
// }); await model.loadContents();
// let model = new NotebookModel(options); await model.requestModelLoad();
// model.onClientSessionReady((session) => sessionFired = true); // starting client session fails at startSessionInstance due to:
// await model.requestModelLoad(); // Cannot set property 'defaultKernelLoaded' of undefined
// model.startSession(notebookManagers[0]); await assert.rejects(async () => { await model.startSession(notebookManagers[0]); });
// Then I expect load to succeed
// // Then I expect load to succeed assert.equal(model.cells.length, 1);
// shouldHaveOneCell(model); assert(model.clientSession);
// should(model.clientSession).not.be.undefined(); // but on server load completion I expect error state to be set
// // but on server load completion I expect error state to be set // Note: do not expect serverLoad event to throw even if failed
// // Note: do not expect serverLoad event to throw even if failed await model.sessionLoadFinished;
// await model.sessionLoadFinished; assert.equal(model.inErrorState, false);
// should(model.inErrorState).be.true(); assert.equal(sessionFired, false);
// should(sessionFired).be.false(); });
// });
test('Should not be in error state if client session initialization succeeds', async function (): Promise<void> { test('Should not be in error state if client session initialization succeeds', async function (): Promise<void> {
let mockContentManager = TypeMoq.Mock.ofType(LocalContentManager); let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
mockContentManager.setup(c => c.getNotebookContents(TypeMoq.It.isAny())).returns(() => Promise.resolve(expectedNotebookContentOneCell)); mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
notebookManagers[0].contentManager = mockContentManager.object; defaultModelOptions.contentManager = mockContentManager.object;
let kernelChangedEmitter: Emitter<nb.IKernelChangedArgs> = new Emitter<nb.IKernelChangedArgs>(); let kernelChangedEmitter: Emitter<nb.IKernelChangedArgs> = new Emitter<nb.IKernelChangedArgs>();
let statusChangedEmitter: Emitter<nb.ISession> = new Emitter<nb.ISession>(); let statusChangedEmitter: Emitter<nb.ISession> = new Emitter<nb.ISession>();
@@ -245,6 +255,7 @@ suite('notebook model', function (): void {
let model = new NotebookModel(options, undefined, logService, undefined, undefined); let model = new NotebookModel(options, undefined, logService, undefined, undefined);
model.onClientSessionReady((session) => actualSession = session); model.onClientSessionReady((session) => actualSession = session);
await model.requestModelLoad(); await model.requestModelLoad();
await model.startSession(notebookManagers[0]); await model.startSession(notebookManagers[0]);
// Then I expect load to succeed // Then I expect load to succeed
@@ -252,9 +263,9 @@ suite('notebook model', function (): void {
// but on server load completion I expect error state to be set // but on server load completion I expect error state to be set
// Note: do not expect serverLoad event to throw even if failed // Note: do not expect serverLoad event to throw even if failed
await model.sessionLoadFinished; await model.sessionLoadFinished;
assert(!model.inErrorState); assert.equal(model.inErrorState, false);
assert.equal(actualSession, mockClientSession.object); assert.deepEqual(actualSession, mockClientSession.object);
assert.equal(model.clientSession, mockClientSession.object); assert.deepEqual(model.clientSession, mockClientSession.object);
}); });
test('Should sanitize kernel display name when IP is included', async function (): Promise<void> { test('Should sanitize kernel display name when IP is included', async function (): Promise<void> {
@@ -273,9 +284,9 @@ suite('notebook model', function (): void {
test('Should notify on trust set', async function () { test('Should notify on trust set', async function () {
// Given a notebook that's been loaded // Given a notebook that's been loaded
let mockContentManager = TypeMoq.Mock.ofType(LocalContentManager); let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
mockContentManager.setup(c => c.getNotebookContents(TypeMoq.It.isAny())).returns(() => Promise.resolve(expectedNotebookContent)); mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
notebookManagers[0].contentManager = mockContentManager.object; defaultModelOptions.contentManager = mockContentManager.object;
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, undefined); let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, undefined);
await model.requestModelLoad(); await model.requestModelLoad();