##// END OF EJS Templates
TEST: Abstract out directory/file deletion methods.
Scott Sanderson -
Show More
@@ -141,7 +141,7 b' class APITest(NotebookTestBase):'
141 os.makedirs(os_path)
141 os.makedirs(os_path)
142 except OSError:
142 except OSError:
143 print("Directory already exists: %r" % os_path)
143 print("Directory already exists: %r" % os_path)
144
144
145 def make_txt(self, api_path, txt):
145 def make_txt(self, api_path, txt):
146 """Make a text file at a given api_path"""
146 """Make a text file at a given api_path"""
147 os_path = self.to_os_path(api_path)
147 os_path = self.to_os_path(api_path)
@@ -160,6 +160,16 b' class APITest(NotebookTestBase):'
160
160
161 with io.open(os_path, 'w', encoding='utf-8') as f:
161 with io.open(os_path, 'w', encoding='utf-8') as f:
162 write(nb, f, version=4)
162 write(nb, f, version=4)
163
164 def delete_dir(self, api_path):
165 """Delete a directory at api_path, removing any contents."""
166 os_path = self.to_os_path(api_path)
167 shutil.rmtree(os_path, ignore_errors=True)
168
169 def delete_file(self, api_path):
170 """Delete a file at the given path if it exists."""
171 if self.isfile(api_path):
172 os.unlink(self.to_os_path(api_path))
163
173
164 def isfile(self, api_path):
174 def isfile(self, api_path):
165 return os.path.isfile(self.to_os_path(api_path))
175 return os.path.isfile(self.to_os_path(api_path))
@@ -190,13 +200,9 b' class APITest(NotebookTestBase):'
190 self.api = API(self.base_url())
200 self.api = API(self.base_url())
191
201
192 def tearDown(self):
202 def tearDown(self):
193 nbdir = self.notebook_dir.name
194
195 for dname in (list(self.top_level_dirs) + self.hidden_dirs):
203 for dname in (list(self.top_level_dirs) + self.hidden_dirs):
196 shutil.rmtree(pjoin(nbdir, dname), ignore_errors=True)
204 self.delete_dir(dname)
197
205 self.delete_file('inroot.ipynb')
198 if os.path.isfile(pjoin(nbdir, 'inroot.ipynb')):
199 os.unlink(pjoin(nbdir, 'inroot.ipynb'))
200
206
201 def test_list_notebooks(self):
207 def test_list_notebooks(self):
202 nbs = notebooks_only(self.api.list().json())
208 nbs = notebooks_only(self.api.list().json())
General Comments 0
You need to be logged in to leave comments. Login now