diff --git a/jupyter_ydoc/ynotebook.py b/jupyter_ydoc/ynotebook.py index 8099497..c117b44 100644 --- a/jupyter_ydoc/ynotebook.py +++ b/jupyter_ydoc/ynotebook.py @@ -304,7 +304,7 @@ def set(self, value: Dict) -> None: self._ymeta["nbformat_minor"] = nbformat_minor old_y_metadata = self._ymeta.get("metadata") - old_metadata = old_y_metadata.to_py() if old_y_metadata else {} + old_metadata = old_y_metadata.to_py() if old_y_metadata else None metadata = nb.get("metadata", {}) if metadata != old_metadata: diff --git a/tests/test_ynotebook.py b/tests/test_ynotebook.py index 282133e..5ff293c 100644 --- a/tests/test_ynotebook.py +++ b/tests/test_ynotebook.py @@ -44,6 +44,15 @@ def record_changes(topic, event): assert changes == [] +def test_set_populates_metadata(): + nb = YNotebook() + nb.set({"cells": []}) + assert nb.get()["metadata"] == { + "kernelspec": {"display_name": "", "name": ""}, + "language_info": {"name": ""}, + } + + def test_set_preserves_cells_with_insert_and_remove(): nb = YNotebook() nb.set(