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