##// END OF EJS Templates
Add some more kernel tests
Jessica B. Hamrick -
Show More
@@ -3,24 +3,127
3 // Kernel tests
3 // Kernel tests
4 //
4 //
5 casper.notebook_test(function () {
5 casper.notebook_test(function () {
6 // test that the kernel is running
6 this.then(function () {
7 this.then(function () {
7 this.test.assert(this.kernel_running(), 'kernel: kernel is running');
8 this.test.assert(this.kernel_running(), 'kernel is running');
8 });
9 });
9
10
11 // test list
12 this.thenEvaluate(function () {
13 IPython._kernels = null;
14 IPython.notebook.kernel.list(function (data) {
15 IPython._kernels = data;
16 });
17 });
18 this.waitFor(function () {
19 return this.evaluate(function () {
20 return IPython._kernels !== null;
21 });
22 });
23 this.then(function () {
24 var num_kernels = this.evaluate(function () {
25 return IPython._kernels.length;
26 });
27 this.test.assertEquals(num_kernels, 1, 'one kernel running');
28 });
29
30 // test get_info
31 var kernel_info = this.evaluate(function () {
32 return {
33 name: IPython.notebook.kernel.name,
34 id: IPython.notebook.kernel.id
35 };
36 });
37 this.thenEvaluate(function () {
38 IPython._kernel_info = null;
39 IPython.notebook.kernel.get_info(function (data) {
40 IPython._kernel_info = data;
41 });
42 });
43 this.waitFor(function () {
44 return this.evaluate(function () {
45 return IPython._kernel_info !== null;
46 });
47 });
48 this.then(function () {
49 var new_kernel_info = this.evaluate(function () {
50 return IPython._kernel_info;
51 });
52 this.test.assertEquals(kernel_info.name, new_kernel_info.name, 'kernel: name correct');
53 this.test.assertEquals(kernel_info.id, new_kernel_info.id, 'kernel: id correct');
54 });
55
56 // test interrupt
57 this.thenEvaluate(function () {
58 IPython._interrupted = false;
59 IPython.notebook.kernel.interrupt(function () {
60 IPython._interrupted = true;
61 });
62 });
63 this.waitFor(function () {
64 return this.evaluate(function () {
65 return IPython._interrupted;
66 });
67 });
68 this.then(function () {
69 var interrupted = this.evaluate(function () {
70 return IPython._interrupted;
71 });
72 this.test.assert(interrupted, 'kernel was interrupted');
73 });
74
75 // test restart
76 this.thenEvaluate(function () {
77 IPython.notebook.kernel.restart();
78 });
79 this.waitFor(function () {
80 return this.evaluate(function () {
81 return IPython.notebook.kernel.is_fully_disconnected();
82 });
83 });
84 this.waitFor(function () {
85 return this.evaluate(function () {
86 return IPython.notebook.kernel.is_connected();
87 });
88 });
89 this.then(function () {
90 this.test.assert(this.kernel_running(), 'kernel restarted');
91 });
92
93 // test reconnect
94 this.thenEvaluate(function () {
95 IPython.notebook.kernel.stop_channels();
96 });
97 this.waitFor(function () {
98 return this.evaluate(function () {
99 return IPython.notebook.kernel.is_fully_disconnected();
100 });
101 });
102 this.thenEvaluate(function () {
103 IPython.notebook.kernel.reconnect();
104 });
105 this.waitFor(function () {
106 return this.evaluate(function () {
107 return IPython.notebook.kernel.is_connected();
108 });
109 });
110 this.then(function () {
111 this.test.assert(this.kernel_running(), 'kernel reconnected');
112 });
113
114 // test kernel_info_request
10 this.evaluate(function () {
115 this.evaluate(function () {
11 IPython.notebook.kernel.kernel_info(
116 IPython.notebook.kernel.kernel_info(
12 function(msg){
117 function(msg){
13 IPython._kernel_info_response = msg;
118 IPython._kernel_info_response = msg;
14 });
119 });
15 });
120 });
16
17 this.waitFor(
121 this.waitFor(
18 function () {
122 function () {
19 return this.evaluate(function(){
123 return this.evaluate(function(){
20 return IPython._kernel_info_response;
124 return IPython._kernel_info_response;
21 });
125 });
22 });
126 });
23
24 this.then(function () {
127 this.then(function () {
25 var kernel_info_response = this.evaluate(function(){
128 var kernel_info_response = this.evaluate(function(){
26 return IPython._kernel_info_response;
129 return IPython._kernel_info_response;
@@ -28,18 +131,62 casper.notebook_test(function () {
28 this.test.assertTrue( kernel_info_response.msg_type === 'kernel_info_reply', 'Kernel info request return kernel_info_reply');
131 this.test.assertTrue( kernel_info_response.msg_type === 'kernel_info_reply', 'Kernel info request return kernel_info_reply');
29 this.test.assertTrue( kernel_info_response.content !== undefined, 'Kernel_info_reply is not undefined');
132 this.test.assertTrue( kernel_info_response.content !== undefined, 'Kernel_info_reply is not undefined');
30 });
133 });
31
134
135 // test kill
32 this.thenEvaluate(function () {
136 this.thenEvaluate(function () {
33 IPython.notebook.kernel.kill();
137 IPython.notebook.kernel.kill();
34 });
138 });
35
36 this.waitFor(function () {
139 this.waitFor(function () {
37 return this.evaluate(function () {
140 return this.evaluate(function () {
38 return IPython.notebook.kernel.is_fully_disconnected();
141 return IPython.notebook.kernel.is_fully_disconnected();
39 });
142 });
40 });
143 });
41
42 this.then(function () {
144 this.then(function () {
43 this.test.assert(!this.kernel_running(), 'kernel is not running');
145 this.test.assert(!this.kernel_running(), 'kernel is not running');
44 });
146 });
147
148 // test start
149 var url;
150 this.then(function () {
151 url = this.evaluate(function () {
152 return IPython.notebook.kernel.start();
153 });
154 });
155 this.then(function () {
156 this.test.assertEquals(url, "/api/kernels", "start url is correct");
157 });
158 this.waitFor(function () {
159 return this.evaluate(function () {
160 return IPython.notebook.kernel.is_connected();
161 });
162 });
163 this.then(function () {
164 this.test.assert(this.kernel_running(), 'kernel is running');
165 });
166
167 // test start with parameters
168 this.thenEvaluate(function () {
169 IPython.notebook.kernel.kill();
170 });
171 this.waitFor(function () {
172 return this.evaluate(function () {
173 return IPython.notebook.kernel.is_fully_disconnected();
174 });
175 });
176 this.then(function () {
177 url = this.evaluate(function () {
178 return IPython.notebook.kernel.start({foo: "bar"});
179 });
180 });
181 this.then(function () {
182 this.test.assertEquals(url, "/api/kernels?foo=bar", "start url with params is correct");
183 });
184 this.waitFor(function () {
185 return this.evaluate(function () {
186 return IPython.notebook.kernel.is_connected();
187 });
188 });
189 this.then(function () {
190 this.test.assert(this.kernel_running(), 'kernel is running');
191 });
45 });
192 });
General Comments 0
You need to be logged in to leave comments. Login now