mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-12 11:45:38 +08:00
Merge pull request #4496 from takluyver/i4495
Pass nbformat object to write call to save .py script Closes #4495
This commit is contained in:
commit
5e4d0fb0e2
@ -251,7 +251,7 @@ class FileNotebookManager(NotebookManager):
|
||||
self.log.debug("Writing script %s", py_path)
|
||||
try:
|
||||
with io.open(py_path, 'w', encoding='utf-8') as f:
|
||||
current.write(model, f, u'py')
|
||||
current.write(nb, f, u'py')
|
||||
except Exception as e:
|
||||
raise web.HTTPError(400, u'Unexpected error while saving notebook as script: %s %s' % (py_path, e))
|
||||
|
||||
|
@ -196,6 +196,25 @@ class TestNotebookManager(TestCase):
|
||||
self.assertEqual(model['name'], 'Untitled0.ipynb')
|
||||
self.assertEqual(model['path'], sub_dir.strip('/'))
|
||||
|
||||
def test_save_notebook_with_script(self):
|
||||
with TemporaryDirectory() as td:
|
||||
# Create a notebook
|
||||
nm = FileNotebookManager(notebook_dir=td)
|
||||
nm.save_script = True
|
||||
model = nm.create_notebook_model()
|
||||
name = model['name']
|
||||
path = model['path']
|
||||
|
||||
# Get the model with 'content'
|
||||
full_model = nm.get_notebook_model(name, path)
|
||||
|
||||
# Save the notebook
|
||||
model = nm.save_notebook_model(full_model, name, path)
|
||||
|
||||
# Check that the script was created
|
||||
py_path = os.path.join(td, os.path.splitext(name)[0]+'.py')
|
||||
assert os.path.exists(py_path), py_path
|
||||
|
||||
def test_delete_notebook_model(self):
|
||||
with TemporaryDirectory() as td:
|
||||
# Test in the root directory
|
||||
|
Loading…
Reference in New Issue
Block a user