simplified named_notebook_path implementation

Also updated the tests
pull/37/head
Paul Ivanov 13 years ago committed by MinRK
parent 9f08aa5a08
commit fd7a64ff38

@ -54,29 +54,21 @@ class NotebookManager(LoggingConfigurable):
Returns
-------
name : string or None
the filename of the notebook, or None if not a .ipynb extesnsion
path : string or None
the filename of the notebook, or None if not a .ipynb extension
path : string
the path to the directory which contains the notebook
"""
names = notebook_path.split('/')
if len(names) > 1:
name = names[-1]
if name.endswith(".ipynb"):
name = name
path = notebook_path[:-1]+'/'
else:
name = None
path = notebook_path+'/'
name = names[-1]
if name.endswith(".ipynb"):
name = name
path = "/".join(names[:-1]) + '/'
else:
name = names[0]
if name.endswith(".ipynb"):
name = name
path = None
else:
name = None
path = notebook_path+'/'
name = None
path = "/".join(names) + '/'
return name, path
def url_encode(self, path):
parts = path.split('/')
return os.path.join(*[quote(p) for p in parts])

@ -40,10 +40,17 @@ class TestNotebookManager(TestCase):
name, path = nm.named_notebook_path('hello')
self.assertEqual(name, None)
self.assertEqual(path, 'hello/')
name, path = nm.named_notebook_path('/')
self.assertEqual(name, None)
name, path = nm.named_notebook_path('hello.ipynb')
self.assertEqual(name, 'hello.ipynb')
self.assertEqual(path, None)
self.assertEqual(path, '/')
name, path = nm.named_notebook_path('/hello.ipynb')
self.assertEqual(name, 'hello.ipynb')
self.assertEqual(path, '/')
name, path = nm.named_notebook_path('/this/is/a/path/hello.ipynb')
self.assertEqual(name, 'hello.ipynb')

Loading…
Cancel
Save