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