Show More
@@ -131,28 +131,29 class FileNotebookManager(NotebookManager): | |||
|
131 | 131 | path = self.get_os_path(name, path) |
|
132 | 132 | return os.path.isfile(path) |
|
133 | 133 | |
|
134 |
def get_os_path(self, fname, path= |
|
|
135 | """Return a full path to a notebook with the os.sep as the separator. | |
|
134 | def get_os_path(self, fname, path='/'): | |
|
135 | """Given a notebook name and a server URL path, return its file system | |
|
136 | path. | |
|
136 | 137 | |
|
137 | 138 | Parameters |
|
138 | 139 | ---------- |
|
139 | 140 | fname : string |
|
140 | 141 | The name of a notebook file with the .ipynb extension |
|
141 | 142 | path : string |
|
142 |
The relative path (with '/' as separator) to the named |
|
|
143 | The relative URL path (with '/' as separator) to the named | |
|
144 | notebook. | |
|
143 | 145 | |
|
144 | 146 | Returns |
|
145 | 147 | ------- |
|
146 | path : | |
|
147 |
A path that combines notebook_dir (location where |
|
|
148 |
the relative path, and the filename with the |
|
|
149 | system's url. | |
|
148 | path : string | |
|
149 | A file system path that combines notebook_dir (location where | |
|
150 | server started), the relative path, and the filename with the | |
|
151 | current operating system's url. | |
|
150 | 152 | """ |
|
151 | if path is None: | |
|
152 | path = '/' | |
|
153 | 153 | parts = path.split('/') |
|
154 | 154 | parts = [p for p in parts if p != ''] # remove duplicate splits |
|
155 | path = os.sep.join([self.notebook_dir] + parts + [fname]) | |
|
155 | parts += [fname] | |
|
156 | path = os.path.join(self.notebook_dir, *parts) | |
|
156 | 157 | return path |
|
157 | 158 | |
|
158 | 159 | def read_notebook_object_from_path(self, path): |
@@ -14,14 +14,14 class TestFileNotebookManager(TestCase): | |||
|
14 | 14 | |
|
15 | 15 | def test_nb_dir(self): |
|
16 | 16 | with TemporaryDirectory() as td: |
|
17 |
|
|
|
18 |
self.assertEqual( |
|
|
17 | fm = FileNotebookManager(notebook_dir=td) | |
|
18 | self.assertEqual(fm.notebook_dir, td) | |
|
19 | 19 | |
|
20 | 20 | def test_create_nb_dir(self): |
|
21 | 21 | with TemporaryDirectory() as td: |
|
22 | 22 | nbdir = os.path.join(td, 'notebooks') |
|
23 |
|
|
|
24 |
self.assertEqual( |
|
|
23 | fm = FileNotebookManager(notebook_dir=nbdir) | |
|
24 | self.assertEqual(fm.notebook_dir, nbdir) | |
|
25 | 25 | |
|
26 | 26 | def test_missing_nb_dir(self): |
|
27 | 27 | with TemporaryDirectory() as td: |
@@ -37,22 +37,21 class TestFileNotebookManager(TestCase): | |||
|
37 | 37 | # separators. |
|
38 | 38 | with TemporaryDirectory() as td: |
|
39 | 39 | nbdir = os.path.join(td, 'notebooks') |
|
40 |
|
|
|
41 |
path = |
|
|
42 | self.assertEqual(path, km.notebook_dir+os.sep+'path'+os.sep+'to'+os.sep+ | |
|
43 | 'notebook'+os.sep+'test.ipynb') | |
|
44 | ||
|
45 | with TemporaryDirectory() as td: | |
|
46 | nbdir = os.path.join(td, 'notebooks') | |
|
47 | km = FileNotebookManager(notebook_dir=nbdir) | |
|
48 |
path = |
|
|
49 |
self.assertEqual(path, |
|
|
50 | ||
|
51 | with TemporaryDirectory() as td: | |
|
52 | nbdir = os.path.join(td, 'notebooks') | |
|
53 | km = FileNotebookManager(notebook_dir=nbdir) | |
|
54 | path = km.get_os_path('test.ipynb', '////') | |
|
55 | self.assertEqual(path, km.notebook_dir+os.sep+'test.ipynb') | |
|
40 | fm = FileNotebookManager(notebook_dir=nbdir) | |
|
41 | path = fm.get_os_path('test.ipynb', '/path/to/notebook/') | |
|
42 | rel_path_list = '/path/to/notebook/test.ipynb'.split('/') | |
|
43 | fs_path = os.path.join(fm.notebook_dir, *rel_path_list) | |
|
44 | self.assertEqual(path, fs_path) | |
|
45 | ||
|
46 | fm = FileNotebookManager(notebook_dir=nbdir) | |
|
47 | path = fm.get_os_path('test.ipynb') | |
|
48 | fs_path = os.path.join(fm.notebook_dir, 'test.ipynb') | |
|
49 | self.assertEqual(path, fs_path) | |
|
50 | ||
|
51 | fm = FileNotebookManager(notebook_dir=nbdir) | |
|
52 | path = fm.get_os_path('test.ipynb', '////') | |
|
53 | fs_path = os.path.join(fm.notebook_dir, 'test.ipynb') | |
|
54 | self.assertEqual(path, fs_path) | |
|
56 | 55 | |
|
57 | 56 | class TestNotebookManager(TestCase): |
|
58 | 57 | def test_named_notebook_path(self): |
General Comments 0
You need to be logged in to leave comments.
Login now