bump default nb format version (#242741)

* bump default nb format version

* update tests

---------

Co-authored-by: amunger <>
This commit is contained in:
Aaron Munger
2025-03-07 11:58:55 -08:00
committed by GitHub
parent 35ccec1f08
commit e5ac650981
3 changed files with 7 additions and 5 deletions

View File

@@ -5,7 +5,7 @@
import type { DocumentSelector } from 'vscode';
export const defaultNotebookFormat = { major: 4, minor: 2 };
export const defaultNotebookFormat = { major: 4, minor: 5 };
export const ATTACHMENT_CLEANUP_COMMANDID = 'ipynb.cleanInvalidImageAttachment';
export const JUPYTER_NOTEBOOK_MARKDOWN_SELECTOR: DocumentSelector = { notebookType: 'jupyter-notebook', language: 'markdown' };

View File

@@ -8,6 +8,7 @@ import { activate as keepNotebookModelStoreInSync } from './notebookModelStoreSy
import { notebookImagePasteSetup } from './notebookImagePaste';
import { AttachmentCleaner } from './notebookAttachmentCleaner';
import { serializeNotebookToString } from './serializers';
import { defaultNotebookFormat } from './constants';
// From {nbformat.INotebookMetadata} in @jupyterlab/coreutils
type NotebookMetadata = {
@@ -86,8 +87,8 @@ export function activate(context: vscode.ExtensionContext, serializer: vscode.No
data.metadata = {
cells: [],
metadata: {},
nbformat: 4,
nbformat_minor: 2
nbformat: defaultNotebookFormat.major,
nbformat_minor: defaultNotebookFormat.minor,
};
const doc = await vscode.workspace.openNotebookDocument('jupyter-notebook', data);
await vscode.window.showNotebookDocument(doc);

View File

@@ -101,7 +101,8 @@ suite(`Notebook Model Store Sync`, () => {
assert.strictEqual(editsApplied.length, 0);
assert.strictEqual(cellMetadataUpdates.length, 0);
});
test('Adding cell will result in an update to the metadata', async () => {
test('Adding cell to nbformat 4.2 notebook will result in adding empty metadata', async () => {
sinon.stub(notebook, 'metadata').get(() => ({ nbformat: 4, nbformat_minor: 2 }));
const cell: NotebookCell = {
document: {} as any,
executionSummary: {},
@@ -131,7 +132,7 @@ suite(`Notebook Model Store Sync`, () => {
const newMetadata = cellMetadataUpdates[0].newCellMetadata;
assert.deepStrictEqual(newMetadata, { execution_count: null, metadata: {} });
});
test('Add cell id if nbformat is 4.5', async () => {
test('Added cell will have a cell id if nbformat is 4.5', async () => {
sinon.stub(notebook, 'metadata').get(() => ({ nbformat: 4, nbformat_minor: 5 }));
const cell: NotebookCell = {
document: {} as any,