Fix #3680 Notebooks: outputs with string arrays rendered incorrectly (#3681)

* Refactor JSON and format files to model and fix tabs -> spaces issues

This is in prep for some work to reuse these code files inside the model,
so pushing as its own PR to keep the next piece of work clean.

* Fix #3680 Notebooks: outputs with string arrays rendered incorrectly
- Add support for processing v4 format files loaded from disk
- Prep support for v3 notebooks by adding placeholder code for that

* Fix failing tests and add specific one for this bug

* Remove references to v5
This commit is contained in:
Kevin Cunnane
2019-01-08 15:24:16 -08:00
committed by GitHub
parent 954d0d954f
commit 2235ebaf20
4 changed files with 251 additions and 31 deletions

View File

@@ -29,8 +29,8 @@ let expectedNotebookContent: nb.INotebookContents = {
language: 'sql'
}
},
nbformat: 5,
nbformat_minor: 0
nbformat: 4,
nbformat_minor: 2
};
let notebookContentString = JSON.stringify(expectedNotebookContent);
@@ -74,4 +74,41 @@ describe('Local Content Manager', function(): void {
// then I expect notebook format to still be valid
verifyMatchesExpectedNotebook(notebook);
});
it('Should inline mime data into a single string', async function(): Promise<void> {
let mimeNotebook: nb.INotebookContents = {
cells: [{
cell_type: CellTypes.Code,
source: 'insert into t1 values (c1, c2)',
metadata: { language: 'python' },
execution_count: 1,
outputs: [
<nb.IDisplayData> {
output_type: 'display_data',
data: {
'text/html': [
'<div>',
'</div>'
]
}
}
]
}],
metadata: {
kernelspec: {
name: 'mssql',
language: 'sql'
}
},
nbformat: 4,
nbformat_minor: 2
};
let mimeContentString = JSON.stringify(mimeNotebook);
// Given a file containing a valid notebook with multiline mime type
let localFile = tempWrite.sync(mimeContentString, 'notebook.ipynb');
// when I read the content
let notebook = await contentManager.getNotebookContents(URI.file(localFile));
// then I expect output to have been normalized into a single string
let displayOutput = <nb.IDisplayData> notebook.cells[0].outputs[0];
should(displayOutput.data['text/html']).equal('<div></div>');
});
});

View File

@@ -44,8 +44,8 @@ let expectedNotebookContent: nb.INotebookContents = {
language: 'sql'
}
},
nbformat: 5,
nbformat_minor: 0
nbformat: 4,
nbformat_minor: 5
};
let expectedNotebookContentOneCell: nb.INotebookContents = {
@@ -61,8 +61,8 @@ let expectedNotebookContentOneCell: nb.INotebookContents = {
language: 'sql'
}
},
nbformat: 5,
nbformat_minor: 0
nbformat: 4,
nbformat_minor: 5
};
let defaultUri = URI.file('/some/path.ipynb');
@@ -112,8 +112,8 @@ describe('notebook model', function(): void {
language: 'sql'
}
},
nbformat: 5,
nbformat_minor: 0
nbformat: 4,
nbformat_minor: 5
};
let mockContentManager = TypeMoq.Mock.ofType(LocalContentManager);