##// END OF EJS Templates
yet another JS race condition fix...
Paul Ivanov -
Show More
@@ -1,39 +1,49
1 1 //
2 2 // Test kernel interrupt
3 3 //
4 4 casper.notebook_test(function () {
5 5 this.evaluate(function () {
6 6 var cell = IPython.notebook.get_cell(0);
7 cell.set_text('import time\nfor x in range(3):\n time.sleep(1)');
7 cell.set_text(
8 'import time'+
9 '\nfor x in range(3):'+
10 '\n time.sleep(1)'
11 );
8 12 cell.execute();
9 13 });
10 14
15 this.waitFor(function(){
16 return this.evaluate(function() {
17 return $("#notification_kernel")[0].textContent.indexOf('busy') !== -1;
18 });
19 });
20
11 21
12 22 // interrupt using menu item (Kernel -> Interrupt)
13 23 this.thenClick('li#int_kernel');
14 24
15 25 this.wait_for_output(0);
16 26
17 27 this.then(function () {
18 28 var result = this.get_output_cell(0);
19 29 this.test.assertEquals(result.ename, 'KeyboardInterrupt', 'keyboard interrupt (mouseclick)');
20 30 });
21 31
22 32 // run cell 0 again, now interrupting using keyboard shortcut
23 33 this.thenEvaluate(function () {
24 34 cell.clear_output();
25 35 cell.execute();
26 36 });
27 37
28 38 // interrupt using Ctrl-M I keyboard shortcut
29 39 this.thenEvaluate( function() {
30 40 IPython.utils.press_ghetto(IPython.utils.keycodes.I)
31 41 });
32 42
33 43 this.wait_for_output(0);
34 44
35 45 this.then(function () {
36 46 var result = this.get_output_cell(0);
37 47 this.test.assertEquals(result.ename, 'KeyboardInterrupt', 'keyboard interrupt (shortcut)');
38 48 });
39 49 });
@@ -1,123 +1,127
1 1 //
2 2 // Utility functions for the HTML notebook's CasperJS tests.
3 3 //
4 4
5 5 // Get the URL of a notebook server on which to run tests.
6 6 casper.get_notebook_server = function () {
7 7 port = casper.cli.get("port")
8 8 port = (typeof port === 'undefined') ? '8888' : port;
9 9 return 'http://127.0.0.1:' + port
10 10 };
11 11
12 12 // Create and open a new notebook.
13 13 casper.open_new_notebook = function () {
14 14 var baseUrl = this.get_notebook_server();
15 15 this.start(baseUrl);
16 16 this.thenClick('button#new_notebook');
17 17 this.waitForPopup('');
18 18
19 19 this.withPopup('', function () {this.waitForSelector('.CodeMirror-code');});
20 20 this.then(function () {
21 21 // XXX: Kind of odd, the next line works for one test, but not when
22 22 // running multiple tests back-to-back, so we will just point the main
23 23 // casper browser to the same URL as the popup we just grabbed.
24 24
25 25 //this.page = this.popups[0];
26 26 this.open(this.popups[0].url);
27 27 });
28 28
29 29 // initially, the cells aren't created, so wait for them to appear
30 30 this.waitForSelector('.CodeMirror-code');
31 31 // and make sure the kernel has started
32 32 this.waitFor( this.kernel_running );
33 33 };
34 34
35 35 // return whether or not the kernel is running
36 36 casper.kernel_running = function kernel_running() {
37 37 return this.evaluate(function kernel_running() {
38 38 return IPython.notebook.kernel.running;
39 39 });
40 40 };
41 41
42 42 // Shut down the current notebook's kernel.
43 43 casper.shutdown_current_kernel = function () {
44 44 this.thenEvaluate(function() {
45 45 IPython.notebook.kernel.kill();
46 46 });
47 47 };
48 48
49 49 // Delete created notebook.
50 50 casper.delete_current_notebook = function () {
51 51 this.thenEvaluate(function() {
52 52 var nbData = $('body').data();
53 53 var url = nbData.baseProjectUrl + 'notebooks/' + nbData.notebookId;
54 54 $.ajax(url, {
55 55 type: 'DELETE',
56 56 });
57 57 });
58 58 };
59 59
60 60 // wait for output in a given cell
61 61 casper.wait_for_output = function (cell_num) {
62 62 this.then(function() {
63 63 this.waitFor(function (c) {
64 64 return this.evaluate(function get_output(c) {
65 65 var cell = IPython.notebook.get_cell(c);
66 66 return cell.output_area.outputs.length != 0;
67 67 },
68 68 // pass parameter from the test suite js to the browser code js
69 69 {c : cell_num});
70 },
71 function then() { },
72 function timeout() {
73 this.echo("wait_for_output timedout!");
70 74 });
71 75 });
72 76 };
73 77
74 78 // return the output of a given cell
75 79 casper.get_output_cell = function (cell_num) {
76 80 var result = casper.evaluate(function (c) {
77 81 var cell = IPython.notebook.get_cell(c);
78 82 return cell.output_area.outputs[0];
79 83 },
80 84 {c : cell_num});
81 85 return result;
82 86 };
83 87
84 88 // return the number of cells in the notebook
85 89 casper.get_cells_length = function () {
86 90 var result = casper.evaluate(function () {
87 91 return IPython.notebook.get_cells().length;
88 92 })
89 93 return result;
90 94 };
91 95
92 96 // Wrap a notebook test to reduce boilerplate.
93 97 casper.notebook_test = function(test) {
94 98 this.open_new_notebook();
95 99 this.then(test);
96 100 //XXX: we get sporadic error messages when shutting down some of the tests.
97 101 // Since the entire server will go down at the end of running the test
98 102 // suite, it's ok for now to not try to shut anything down.
99 103 this.shutdown_current_kernel();
100 104
101 105 //XXX: the implementation of delete_current_notebook is currently broken
102 106 // it's not a big deal, since the notebook directory will be deleted on
103 107 // cleanup, but we should add tests for deleting the notebook separately
104 108 //this.delete_current_notebook();
105 109
106 110 // Run the browser automation.
107 111 this.run(function() {
108 112 this.test.done();
109 113 });
110 114 };
111 115
112 116 casper.options.waitTimeout=10000
113 117 casper.on('waitFor.timeout', function onWaitForTimeout(timeout) {
114 118 this.echo("Timeout for " + casper.get_notebook_server());
115 119 this.echo("Is the notebook server running?");
116 120 });
117 121
118 122 // Pass `console.log` calls from page JS to casper.
119 123 casper.printLog = function () {
120 124 this.on('remote.message', function(msg) {
121 125 this.echo('Remote message caught: ' + msg);
122 126 });
123 127 };
General Comments 0
You need to be logged in to leave comments. Login now