diff --git a/IPython/nbformat/v3/nbbase.py b/IPython/nbformat/v3/nbbase.py index f0a97fd..8387484 100644 --- a/IPython/nbformat/v3/nbbase.py +++ b/IPython/nbformat/v3/nbbase.py @@ -146,7 +146,7 @@ def new_worksheet(name=None, cells=None): return ws -def new_notebook(metadata=None, worksheets=None): +def new_notebook(name=None, metadata=None, worksheets=None): """Create a notebook by name, id and a list of worksheets.""" nb = NotebookNode() nb.nbformat = nbformat @@ -158,6 +158,8 @@ def new_notebook(metadata=None, worksheets=None): nb.metadata = new_metadata() else: nb.metadata = NotebookNode(metadata) + if name is not None: + nb.metadata.name = unicode(name) return nb diff --git a/IPython/nbformat/v3/tests/test_nbbase.py b/IPython/nbformat/v3/tests/test_nbbase.py index 3e992c0..d3e1190 100644 --- a/IPython/nbformat/v3/tests/test_nbbase.py +++ b/IPython/nbformat/v3/tests/test_nbbase.py @@ -112,6 +112,13 @@ class TestNotebook(TestCase): self.assertEquals(nb.worksheets,worksheets) self.assertEquals(nb.nbformat,nbformat) + def test_notebook_name(self): + worksheets = [new_worksheet(),new_worksheet()] + nb = new_notebook(name='foo',worksheets=worksheets) + self.assertEquals(nb.metadata.name,u'foo') + self.assertEquals(nb.worksheets,worksheets) + self.assertEquals(nb.nbformat,nbformat) + class TestMetadata(TestCase): def test_empty_metadata(self):