Show More
@@ -1,34 +1,52 | |||||
1 | """Tests for the notebook manager.""" |
|
1 | """Tests for the notebook manager.""" | |
2 |
|
2 | |||
3 | import os |
|
3 | import os | |
4 | from unittest import TestCase |
|
4 | from unittest import TestCase | |
5 | from tempfile import NamedTemporaryFile |
|
5 | from tempfile import NamedTemporaryFile | |
6 |
|
6 | |||
7 | from IPython.utils.tempdir import TemporaryDirectory |
|
7 | from IPython.utils.tempdir import TemporaryDirectory | |
8 | from IPython.utils.traitlets import TraitError |
|
8 | from IPython.utils.traitlets import TraitError | |
9 |
|
9 | |||
10 | from ..filenbmanager import FileNotebookManager |
|
10 | from ..filenbmanager import FileNotebookManager | |
|
11 | from ..nbmanager import NotebookManager | |||
11 |
|
12 | |||
12 | class TestNotebookManager(TestCase): |
|
13 | class TestFileNotebookManager(TestCase): | |
13 |
|
14 | |||
14 | def test_nb_dir(self): |
|
15 | def test_nb_dir(self): | |
15 | with TemporaryDirectory() as td: |
|
16 | with TemporaryDirectory() as td: | |
16 | km = FileNotebookManager(notebook_dir=td) |
|
17 | km = FileNotebookManager(notebook_dir=td) | |
17 | self.assertEqual(km.notebook_dir, td) |
|
18 | self.assertEqual(km.notebook_dir, td) | |
18 |
|
19 | |||
19 | def test_create_nb_dir(self): |
|
20 | def test_create_nb_dir(self): | |
20 | with TemporaryDirectory() as td: |
|
21 | with TemporaryDirectory() as td: | |
21 | nbdir = os.path.join(td, 'notebooks') |
|
22 | nbdir = os.path.join(td, 'notebooks') | |
22 | km = FileNotebookManager(notebook_dir=nbdir) |
|
23 | km = FileNotebookManager(notebook_dir=nbdir) | |
23 | self.assertEqual(km.notebook_dir, nbdir) |
|
24 | self.assertEqual(km.notebook_dir, nbdir) | |
24 |
|
25 | |||
25 | def test_missing_nb_dir(self): |
|
26 | def test_missing_nb_dir(self): | |
26 | with TemporaryDirectory() as td: |
|
27 | with TemporaryDirectory() as td: | |
27 | nbdir = os.path.join(td, 'notebook', 'dir', 'is', 'missing') |
|
28 | nbdir = os.path.join(td, 'notebook', 'dir', 'is', 'missing') | |
28 | self.assertRaises(TraitError, FileNotebookManager, notebook_dir=nbdir) |
|
29 | self.assertRaises(TraitError, FileNotebookManager, notebook_dir=nbdir) | |
29 |
|
30 | |||
30 | def test_invalid_nb_dir(self): |
|
31 | def test_invalid_nb_dir(self): | |
31 | with NamedTemporaryFile() as tf: |
|
32 | with NamedTemporaryFile() as tf: | |
32 | self.assertRaises(TraitError, FileNotebookManager, notebook_dir=tf.name) |
|
33 | self.assertRaises(TraitError, FileNotebookManager, notebook_dir=tf.name) | |
33 |
|
34 | |||
|
35 | class TestNotebookManager(TestCase): | |||
|
36 | def test_named_notebook_path(self): | |||
|
37 | nm = NotebookManager() | |||
|
38 | ||||
|
39 | # doesn't end with ipynb, should just be path | |||
|
40 | name, path = nm.named_notebook_path('hello') | |||
|
41 | self.assertEqual(name, None) | |||
|
42 | self.assertEqual(path, 'hello/') | |||
|
43 | ||||
|
44 | name, path = nm.named_notebook_path('hello.ipynb') | |||
|
45 | self.assertEqual(name, 'hello.ipynb') | |||
|
46 | self.assertEqual(path, None) | |||
|
47 | ||||
|
48 | name, path = nm.named_notebook_path('/this/is/a/path/hello.ipynb') | |||
|
49 | self.assertEqual(name, 'hello.ipynb') | |||
|
50 | self.assertEqual(path, '/this/is/a/path/') | |||
|
51 | ||||
34 |
|
52 |
General Comments 0
You need to be logged in to leave comments.
Login now