Show More
@@ -6,6 +6,7 b' from tornado import web' | |||||
6 |
|
6 | |||
7 | from ..sessionmanager import SessionManager |
|
7 | from ..sessionmanager import SessionManager | |
8 | from IPython.html.services.kernels.kernelmanager import MappingKernelManager |
|
8 | from IPython.html.services.kernels.kernelmanager import MappingKernelManager | |
|
9 | from IPython.html.services.contents.manager import ContentsManager | |||
9 |
|
10 | |||
10 | class DummyKernel(object): |
|
11 | class DummyKernel(object): | |
11 | def __init__(self, kernel_name='python'): |
|
12 | def __init__(self, kernel_name='python'): | |
@@ -28,10 +29,17 b' class DummyMKM(MappingKernelManager):' | |||||
28 | def shutdown_kernel(self, kernel_id, now=False): |
|
29 | def shutdown_kernel(self, kernel_id, now=False): | |
29 | del self._kernels[kernel_id] |
|
30 | del self._kernels[kernel_id] | |
30 |
|
31 | |||
|
32 | ||||
31 | class TestSessionManager(TestCase): |
|
33 | class TestSessionManager(TestCase): | |
32 |
|
34 | |||
|
35 | def setUp(self): | |||
|
36 | self.sm = SessionManager( | |||
|
37 | kernel_manager=DummyMKM(), | |||
|
38 | contents_manager=ContentsManager(), | |||
|
39 | ) | |||
|
40 | ||||
33 | def test_get_session(self): |
|
41 | def test_get_session(self): | |
34 | sm = SessionManager(kernel_manager=DummyMKM()) |
|
42 | sm = self.sm | |
35 | session_id = sm.create_session(path='/path/to/test.ipynb', |
|
43 | session_id = sm.create_session(path='/path/to/test.ipynb', | |
36 | kernel_name='bar')['id'] |
|
44 | kernel_name='bar')['id'] | |
37 | model = sm.get_session(session_id=session_id) |
|
45 | model = sm.get_session(session_id=session_id) | |
@@ -42,13 +50,13 b' class TestSessionManager(TestCase):' | |||||
42 |
|
50 | |||
43 | def test_bad_get_session(self): |
|
51 | def test_bad_get_session(self): | |
44 | # Should raise error if a bad key is passed to the database. |
|
52 | # Should raise error if a bad key is passed to the database. | |
45 | sm = SessionManager(kernel_manager=DummyMKM()) |
|
53 | sm = self.sm | |
46 | session_id = sm.create_session(path='/path/to/test.ipynb', |
|
54 | session_id = sm.create_session(path='/path/to/test.ipynb', | |
47 | kernel_name='foo')['id'] |
|
55 | kernel_name='foo')['id'] | |
48 | self.assertRaises(TypeError, sm.get_session, bad_id=session_id) # Bad keyword |
|
56 | self.assertRaises(TypeError, sm.get_session, bad_id=session_id) # Bad keyword | |
49 |
|
57 | |||
50 | def test_get_session_dead_kernel(self): |
|
58 | def test_get_session_dead_kernel(self): | |
51 | sm = SessionManager(kernel_manager=DummyMKM()) |
|
59 | sm = self.sm | |
52 | session = sm.create_session(path='/path/to/1/test1.ipynb', kernel_name='python') |
|
60 | session = sm.create_session(path='/path/to/1/test1.ipynb', kernel_name='python') | |
53 | # kill the kernel |
|
61 | # kill the kernel | |
54 | sm.kernel_manager.shutdown_kernel(session['kernel']['id']) |
|
62 | sm.kernel_manager.shutdown_kernel(session['kernel']['id']) | |
@@ -59,7 +67,7 b' class TestSessionManager(TestCase):' | |||||
59 | self.assertEqual(listed, []) |
|
67 | self.assertEqual(listed, []) | |
60 |
|
68 | |||
61 | def test_list_sessions(self): |
|
69 | def test_list_sessions(self): | |
62 | sm = SessionManager(kernel_manager=DummyMKM()) |
|
70 | sm = self.sm | |
63 | sessions = [ |
|
71 | sessions = [ | |
64 | sm.create_session(path='/path/to/1/test1.ipynb', kernel_name='python'), |
|
72 | sm.create_session(path='/path/to/1/test1.ipynb', kernel_name='python'), | |
65 | sm.create_session(path='/path/to/2/test2.ipynb', kernel_name='python'), |
|
73 | sm.create_session(path='/path/to/2/test2.ipynb', kernel_name='python'), | |
@@ -84,7 +92,7 b' class TestSessionManager(TestCase):' | |||||
84 | self.assertEqual(sessions, expected) |
|
92 | self.assertEqual(sessions, expected) | |
85 |
|
93 | |||
86 | def test_list_sessions_dead_kernel(self): |
|
94 | def test_list_sessions_dead_kernel(self): | |
87 | sm = SessionManager(kernel_manager=DummyMKM()) |
|
95 | sm = self.sm | |
88 | sessions = [ |
|
96 | sessions = [ | |
89 | sm.create_session(path='/path/to/1/test1.ipynb', kernel_name='python'), |
|
97 | sm.create_session(path='/path/to/1/test1.ipynb', kernel_name='python'), | |
90 | sm.create_session(path='/path/to/2/test2.ipynb', kernel_name='python'), |
|
98 | sm.create_session(path='/path/to/2/test2.ipynb', kernel_name='python'), | |
@@ -107,7 +115,7 b' class TestSessionManager(TestCase):' | |||||
107 | self.assertEqual(listed, expected) |
|
115 | self.assertEqual(listed, expected) | |
108 |
|
116 | |||
109 | def test_update_session(self): |
|
117 | def test_update_session(self): | |
110 | sm = SessionManager(kernel_manager=DummyMKM()) |
|
118 | sm = self.sm | |
111 | session_id = sm.create_session(path='/path/to/test.ipynb', |
|
119 | session_id = sm.create_session(path='/path/to/test.ipynb', | |
112 | kernel_name='julia')['id'] |
|
120 | kernel_name='julia')['id'] | |
113 | sm.update_session(session_id, path='/path/to/new_name.ipynb') |
|
121 | sm.update_session(session_id, path='/path/to/new_name.ipynb') | |
@@ -119,13 +127,13 b' class TestSessionManager(TestCase):' | |||||
119 |
|
127 | |||
120 | def test_bad_update_session(self): |
|
128 | def test_bad_update_session(self): | |
121 | # try to update a session with a bad keyword ~ raise error |
|
129 | # try to update a session with a bad keyword ~ raise error | |
122 | sm = SessionManager(kernel_manager=DummyMKM()) |
|
130 | sm = self.sm | |
123 | session_id = sm.create_session(path='/path/to/test.ipynb', |
|
131 | session_id = sm.create_session(path='/path/to/test.ipynb', | |
124 | kernel_name='ir')['id'] |
|
132 | kernel_name='ir')['id'] | |
125 | self.assertRaises(TypeError, sm.update_session, session_id=session_id, bad_kw='test.ipynb') # Bad keyword |
|
133 | self.assertRaises(TypeError, sm.update_session, session_id=session_id, bad_kw='test.ipynb') # Bad keyword | |
126 |
|
134 | |||
127 | def test_delete_session(self): |
|
135 | def test_delete_session(self): | |
128 | sm = SessionManager(kernel_manager=DummyMKM()) |
|
136 | sm = self.sm | |
129 | sessions = [ |
|
137 | sessions = [ | |
130 | sm.create_session(path='/path/to/1/test1.ipynb', kernel_name='python'), |
|
138 | sm.create_session(path='/path/to/1/test1.ipynb', kernel_name='python'), | |
131 | sm.create_session(path='/path/to/2/test2.ipynb', kernel_name='python'), |
|
139 | sm.create_session(path='/path/to/2/test2.ipynb', kernel_name='python'), | |
@@ -147,7 +155,7 b' class TestSessionManager(TestCase):' | |||||
147 |
|
155 | |||
148 | def test_bad_delete_session(self): |
|
156 | def test_bad_delete_session(self): | |
149 | # try to delete a session that doesn't exist ~ raise error |
|
157 | # try to delete a session that doesn't exist ~ raise error | |
150 | sm = SessionManager(kernel_manager=DummyMKM()) |
|
158 | sm = self.sm | |
151 | sm.create_session(path='/path/to/test.ipynb', kernel_name='python') |
|
159 | sm.create_session(path='/path/to/test.ipynb', kernel_name='python') | |
152 | self.assertRaises(TypeError, sm.delete_session, bad_kwarg='23424') # Bad keyword |
|
160 | self.assertRaises(TypeError, sm.delete_session, bad_kwarg='23424') # Bad keyword | |
153 | self.assertRaises(web.HTTPError, sm.delete_session, session_id='23424') # nonexistant |
|
161 | self.assertRaises(web.HTTPError, sm.delete_session, session_id='23424') # nonexistant |
General Comments 0
You need to be logged in to leave comments.
Login now