##// END OF EJS Templates
Use existing IPython method to kill kernels.
David Wyde -
Show More
@@ -1,57 +1,52
1 //
1 //
2 // Utility functions for the HTML notebook's CasperJS tests.
2 // Utility functions for the HTML notebook's CasperJS tests.
3 //
3 //
4
4
5 // Get the URL of a notebook server on which to run tests.
5 // Get the URL of a notebook server on which to run tests.
6 casper.getNotebookServer = function () {
6 casper.getNotebookServer = function () {
7 return 'http://127.0.0.1:8888';
7 return 'http://127.0.0.1:8888';
8 };
8 };
9
9
10 // Create and open a new notebook.
10 // Create and open a new notebook.
11 casper.openNewNotebook = function () {
11 casper.openNewNotebook = function () {
12 var baseUrl = this.getNotebookServer();
12 var baseUrl = this.getNotebookServer();
13 this.start(baseUrl + '/new');
13 this.start(baseUrl + '/new');
14 };
14 };
15
15
16 // Shut down the current notebook's kernel.
16 // Shut down the current notebook's kernel.
17 casper.shutdownCurrentKernel = function () {
17 casper.shutdownCurrentKernel = function () {
18 this.thenEvaluate(function() {
18 this.thenEvaluate(function() {
19 var baseUrl = $('body').data('baseProjectUrl');
19 IPython.notebook.kernel.kill();
20 var kernelId = IPython.notebook.kernel.kernel_id;
21 var url = baseUrl + 'kernels/' + kernelId;
22 $.ajax(url, {
23 type: 'DELETE',
24 });
25 });
20 });
26 };
21 };
27
22
28 // Delete created notebook.
23 // Delete created notebook.
29 casper.deleteCurrentNotebook = function () {
24 casper.deleteCurrentNotebook = function () {
30 this.thenEvaluate(function() {
25 this.thenEvaluate(function() {
31 var nbData = $('body').data();
26 var nbData = $('body').data();
32 var url = nbData.baseProjectUrl + 'notebooks/' + nbData.notebookId;
27 var url = nbData.baseProjectUrl + 'notebooks/' + nbData.notebookId;
33 $.ajax(url, {
28 $.ajax(url, {
34 type: 'DELETE',
29 type: 'DELETE',
35 });
30 });
36 });
31 });
37 };
32 };
38
33
39 // Wrap a notebook test to reduce boilerplate.
34 // Wrap a notebook test to reduce boilerplate.
40 casper.notebookTest = function(test) {
35 casper.notebookTest = function(test) {
41 this.openNewNotebook();
36 this.openNewNotebook();
42 this.then(test);
37 this.then(test);
43 this.shutdownCurrentKernel();
38 this.shutdownCurrentKernel();
44 this.deleteCurrentNotebook();
39 this.deleteCurrentNotebook();
45
40
46 // Run the browser automation.
41 // Run the browser automation.
47 this.run(function() {
42 this.run(function() {
48 this.test.done();
43 this.test.done();
49 });
44 });
50 };
45 };
51
46
52 // Pass `console.log` calls from page JS to casper.
47 // Pass `console.log` calls from page JS to casper.
53 casper.printLog = function () {
48 casper.printLog = function () {
54 this.on('remote.message', function(msg) {
49 this.on('remote.message', function(msg) {
55 this.echo('Remote message caught: ' + msg);
50 this.echo('Remote message caught: ' + msg);
56 });
51 });
57 };
52 };
General Comments 0
You need to be logged in to leave comments. Login now