mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-13 17:22:15 -05:00
* Fixed #4113 * Resolve PR comments
This commit is contained in:
@@ -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, sqlNotebookMultipleCellsContent } from './notebook.util';
|
||||
import { sqlNotebookContent, writeNotebookToFile, sqlKernelMetadata, getFileName, pySparkNotebookContent, pySpark3KernelMetadata, pythonKernelMetadata, sqlNotebookMultipleCellsContent, notebookContentForCellLanguageTest } from './notebook.util';
|
||||
import { getBdcServer, getConfigValue, EnvironmentVariable_PYTHON_PATH } from './testConfig';
|
||||
import { connectToServer } from './utils';
|
||||
import * as fs from 'fs';
|
||||
@@ -40,6 +40,10 @@ if (context.RunTest) {
|
||||
await (new NotebookTester()).sqlNbClearAllOutputs(this.test.title);
|
||||
});
|
||||
|
||||
test('sql language test', async function () {
|
||||
await (new NotebookTester()).sqlLanguageTest(this.test.title);
|
||||
});
|
||||
|
||||
if (process.env['RUN_PYTHON3_TEST'] === '1') {
|
||||
test('Python3 notebook test', async function () {
|
||||
await (new NotebookTester()).python3NbTest(this.test.title);
|
||||
@@ -48,6 +52,10 @@ if (context.RunTest) {
|
||||
test('Clear all outputs - Python3 notebook ', async function () {
|
||||
await (new NotebookTester()).python3ClearAllOutputs(this.test.title);
|
||||
});
|
||||
|
||||
test('python language test', async function () {
|
||||
await (new NotebookTester()).pythonLanguageTest(this.test.title);
|
||||
});
|
||||
}
|
||||
|
||||
if (process.env['RUN_PYSPARK_TEST'] === '1') {
|
||||
@@ -55,6 +63,20 @@ if (context.RunTest) {
|
||||
await (new NotebookTester()).pySpark3NbTest(this.test.title);
|
||||
});
|
||||
}
|
||||
|
||||
/* After https://github.com/microsoft/azuredatastudio/issues/5598 is fixed, enable these tests.
|
||||
test('scala language test', async function () {
|
||||
await (new NotebookTester()).scalaLanguageTest(this.test.title);
|
||||
});
|
||||
|
||||
test('empty language test', async function () {
|
||||
await (new NotebookTester()).emptyLanguageTest(this.test.title);
|
||||
});
|
||||
|
||||
test('cplusplus language test', async function () {
|
||||
await (new NotebookTester()).cplusplusLanguageTest(this.test.title);
|
||||
});
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
@@ -132,6 +154,81 @@ class NotebookTester {
|
||||
assert(actualOutput2[0] === '1', `Expected result: 1, Actual: '${actualOutput2[0]}'`);
|
||||
}
|
||||
|
||||
async scalaLanguageTest(title: string): Promise<void> {
|
||||
let language = 'scala';
|
||||
await this.cellLanguageTest(notebookContentForCellLanguageTest, title + this.invocationCount++, language, {
|
||||
'kernelspec': {
|
||||
'name': '',
|
||||
'display_name': ''
|
||||
},
|
||||
'language_info': {
|
||||
name: language,
|
||||
version: '',
|
||||
mimetype: ''
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async cplusplusLanguageTest(title: string): Promise<void> {
|
||||
let language = 'cplusplus';
|
||||
await this.cellLanguageTest(notebookContentForCellLanguageTest, title + this.invocationCount++, language, {
|
||||
'kernelspec': {
|
||||
'name': '',
|
||||
'display_name': ''
|
||||
},
|
||||
'language_info': {
|
||||
name: language,
|
||||
version: '',
|
||||
mimetype: ''
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async emptyLanguageTest(title: string): Promise<void> {
|
||||
let language = '';
|
||||
await this.cellLanguageTest(notebookContentForCellLanguageTest, title + this.invocationCount++, language, {
|
||||
'kernelspec': {
|
||||
'name': language,
|
||||
'display_name': ''
|
||||
},
|
||||
'language_info': {
|
||||
name: language,
|
||||
version: '',
|
||||
mimetype: 'x-scala'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async sqlLanguageTest(title: string): Promise<void> {
|
||||
let language = 'sql';
|
||||
await this.cellLanguageTest(notebookContentForCellLanguageTest, title + this.invocationCount++, language, {
|
||||
'kernelspec': {
|
||||
'name': language,
|
||||
'display_name': language.toUpperCase()
|
||||
},
|
||||
'language_info': {
|
||||
'name': language,
|
||||
'version': '',
|
||||
'mimetype': ''
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async pythonLanguageTest(title: string): Promise<void> {
|
||||
let language = 'python';
|
||||
await this.cellLanguageTest(notebookContentForCellLanguageTest, title + this.invocationCount++, language, {
|
||||
'kernelspec': {
|
||||
'name': 'python3',
|
||||
'display_name': 'Python 3'
|
||||
},
|
||||
'language_info': {
|
||||
'name': language,
|
||||
'version': '',
|
||||
'mimetype': ''
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async cleanup(testName: string): Promise<void> {
|
||||
try {
|
||||
let fileName = getFileName(testName + this.invocationCount++);
|
||||
@@ -159,7 +256,7 @@ class NotebookTester {
|
||||
}
|
||||
let notebookJson = Object.assign({}, content, { metadata: kernelMetadata });
|
||||
let uri = writeNotebookToFile(notebookJson, testName);
|
||||
console.log(uri);
|
||||
console.log('Notebook uri ' + uri);
|
||||
let notebook = await azdata.nb.showNotebookDocument(uri);
|
||||
console.log('Notebook is opened');
|
||||
|
||||
@@ -190,5 +287,16 @@ class NotebookTester {
|
||||
assert(clearedOutputs, 'Outputs of all the code cells from Python notebook should be cleared');
|
||||
console.log('After clearing cell outputs');
|
||||
}
|
||||
async cellLanguageTest(content: azdata.nb.INotebookContents, testName: string, languageConfigured: string, metadataInfo: any) {
|
||||
let notebookJson = Object.assign({}, content, { metadata: metadataInfo });
|
||||
let uri = writeNotebookToFile(notebookJson, testName);
|
||||
console.log('Notebook uri ' + uri);
|
||||
let notebook = await azdata.nb.showNotebookDocument(uri);
|
||||
console.log('Notebook is opened');
|
||||
await notebook.document.save();
|
||||
let languageInNotebook = notebook.document.cells[0].contents.metadata.language;
|
||||
console.log('Language set in cell: ' + languageInNotebook);
|
||||
assert(languageInNotebook === languageConfigured, `Expected cell language is: ${languageConfigured}, Actual: ${languageInNotebook}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,22 @@ export const pySparkNotebookContent: azdata.nb.INotebookContents = {
|
||||
nbformat_minor: 2
|
||||
};
|
||||
|
||||
export const notebookContentForCellLanguageTest: azdata.nb.INotebookContents = {
|
||||
cells: [{
|
||||
cell_type: CellTypes.Code,
|
||||
source: '1+1',
|
||||
metadata: {},
|
||||
execution_count: 1
|
||||
}],
|
||||
metadata: {
|
||||
'kernelspec': {
|
||||
'name': ''
|
||||
},
|
||||
},
|
||||
nbformat: 4,
|
||||
nbformat_minor: 2
|
||||
};
|
||||
|
||||
export const pythonNotebookMultipleCellsContent: azdata.nb.INotebookContents = {
|
||||
cells: [{
|
||||
cell_type: CellTypes.Code,
|
||||
|
||||
@@ -88,25 +88,6 @@ suite('Cell Model', function (): void {
|
||||
should(cell.language).equal('python');
|
||||
});
|
||||
|
||||
// Failing test disabled - see https://github.com/Microsoft/azuredatastudio/issues/4113
|
||||
/*
|
||||
test('Should set cell language to scala if defined as scala in languageInfo', async function (): Promise<void> {
|
||||
let cellData: nb.ICellContents = {
|
||||
cell_type: CellTypes.Code,
|
||||
source: 'print(\'1\')',
|
||||
metadata: {},
|
||||
execution_count: 1
|
||||
};
|
||||
|
||||
let notebookModel = new NotebookModelStub({
|
||||
name: 'scala',
|
||||
version: '',
|
||||
mimetype: ''
|
||||
});
|
||||
let cell = factory.createCell(cellData, { notebook: notebookModel, isTrusted: false });
|
||||
should(cell.language).equal('scala');
|
||||
});
|
||||
*/
|
||||
test('Should keep cell language as python if cell has language override', async function (): Promise<void> {
|
||||
let cellData: nb.ICellContents = {
|
||||
cell_type: CellTypes.Code,
|
||||
@@ -141,46 +122,6 @@ suite('Cell Model', function (): void {
|
||||
should(cell.language).equal('python');
|
||||
});
|
||||
|
||||
// Failing test disabled - see https://github.com/Microsoft/azuredatastudio/issues/4113
|
||||
/*
|
||||
test('Should match cell language to language specified if unknown language defined in languageInfo', async function (): Promise<void> {
|
||||
let cellData: nb.ICellContents = {
|
||||
cell_type: CellTypes.Code,
|
||||
source: 'std::cout << "hello world";',
|
||||
metadata: {},
|
||||
execution_count: 1
|
||||
};
|
||||
|
||||
let notebookModel = new NotebookModelStub({
|
||||
name: 'cplusplus',
|
||||
version: '',
|
||||
mimetype: ''
|
||||
});
|
||||
let cell = factory.createCell(cellData, { notebook: notebookModel, isTrusted: false });
|
||||
should(cell.language).equal('cplusplus');
|
||||
});
|
||||
*/
|
||||
|
||||
// Failing test disabled - see https://github.com/Microsoft/azuredatastudio/issues/4113
|
||||
/*
|
||||
test('Should match cell language to mimetype name is not supplied in languageInfo', async function (): Promise<void> {
|
||||
let cellData: nb.ICellContents = {
|
||||
cell_type: CellTypes.Code,
|
||||
source: 'print(\'1\')',
|
||||
metadata: {},
|
||||
execution_count: 1
|
||||
};
|
||||
|
||||
let notebookModel = new NotebookModelStub({
|
||||
name: '',
|
||||
version: '',
|
||||
mimetype: 'x-scala'
|
||||
});
|
||||
let cell = factory.createCell(cellData, { notebook: notebookModel, isTrusted: false });
|
||||
should(cell.language).equal('scala');
|
||||
});
|
||||
*/
|
||||
|
||||
suite('Model Future handling', function (): void {
|
||||
let future: TypeMoq.Mock<EmptyFuture>;
|
||||
let cell: ICellModel;
|
||||
|
||||
Reference in New Issue
Block a user