Show More
@@ -1,113 +1,115 b'' | |||||
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 | // refactor this into just a get_output(0) | |
14 | this.then(function () { |
|
14 | this.then(function () { | |
15 | var result = this.get_output_cell(0); |
|
15 | var result = this.get_output_cell(0); | |
16 | this.test.assertEquals(result.text, '10\n', 'cell execute (using js)'); |
|
16 | this.test.assertEquals(result.text, '10\n', 'cell execute (using js)'); | |
17 | }); |
|
17 | }); | |
18 |
|
18 | |||
19 |
|
19 | |||
20 | // do it again with the keyboard shortcut |
|
20 | // do it again with the keyboard shortcut | |
21 | this.thenEvaluate(function () { |
|
21 | this.thenEvaluate(function () { | |
22 | var cell = IPython.notebook.get_cell(0); |
|
22 | var cell = IPython.notebook.get_cell(0); | |
23 | cell.set_text('a=11; print(a)'); |
|
23 | cell.set_text('a=11; print(a)'); | |
24 | cell.clear_output(); |
|
24 | cell.clear_output(); | |
25 | }); |
|
25 | }); | |
26 |
|
26 | |||
27 | this.then(function(){ |
|
27 | this.then(function(){ | |
28 |
|
28 | |||
29 | this.trigger_keydown('shift-enter'); |
|
29 | this.trigger_keydown('shift-enter'); | |
30 | }); |
|
30 | }); | |
31 |
|
31 | |||
32 | this.wait_for_output(0); |
|
32 | this.wait_for_output(0); | |
33 |
|
33 | |||
34 | this.then(function () { |
|
34 | this.then(function () { | |
35 | var result = this.get_output_cell(0); |
|
35 | var result = this.get_output_cell(0); | |
36 | var num_cells = this.get_cells_length(); |
|
36 | var num_cells = this.get_cells_length(); | |
37 | this.test.assertEquals(result.text, '11\n', 'cell execute (using ctrl-enter)'); |
|
37 | this.test.assertEquals(result.text, '11\n', 'cell execute (using ctrl-enter)'); | |
38 | this.test.assertEquals(num_cells, 2, 'shift-enter adds a new cell at the bottom') |
|
38 | this.test.assertEquals(num_cells, 2, 'shift-enter adds a new cell at the bottom') | |
39 | }); |
|
39 | }); | |
40 |
|
40 | |||
41 | // do it again with the keyboard shortcut |
|
41 | // do it again with the keyboard shortcut | |
42 | this.thenEvaluate(function () { |
|
42 | this.thenEvaluate(function () { | |
43 | IPython.notebook.select(1); |
|
43 | IPython.notebook.select(1); | |
44 | IPython.notebook.delete_cell(); |
|
44 | IPython.notebook.delete_cell(); | |
45 | var cell = IPython.notebook.get_cell(0); |
|
45 | var cell = IPython.notebook.get_cell(0); | |
46 | cell.set_text('a=12; print(a)'); |
|
46 | cell.set_text('a=12; print(a)'); | |
47 | cell.clear_output(); |
|
47 | cell.clear_output(); | |
48 | }); |
|
48 | }); | |
49 |
|
49 | |||
50 | this.then(function(){ |
|
50 | this.then(function(){ | |
51 | this.trigger_keydown('ctrl-enter'); |
|
51 | this.trigger_keydown('ctrl-enter'); | |
52 | }); |
|
52 | }); | |
53 |
|
53 | |||
54 | this.wait_for_output(0); |
|
54 | this.wait_for_output(0); | |
55 |
|
55 | |||
56 | this.then(function () { |
|
56 | this.then(function () { | |
57 | var result = this.get_output_cell(0); |
|
57 | var result = this.get_output_cell(0); | |
58 | var num_cells = this.get_cells_length(); |
|
58 | var num_cells = this.get_cells_length(); | |
59 | this.test.assertEquals(result.text, '12\n', 'cell execute (using shift-enter)'); |
|
59 | this.test.assertEquals(result.text, '12\n', 'cell execute (using shift-enter)'); | |
60 | this.test.assertEquals(num_cells, 1, 'ctrl-enter adds no new cell at the bottom') |
|
60 | this.test.assertEquals(num_cells, 1, 'ctrl-enter adds no new cell at the bottom') | |
61 | }); |
|
61 | }); | |
62 |
|
62 | |||
63 | // press the "play" triangle button in the toolbar |
|
63 | // press the "play" triangle button in the toolbar | |
64 | this.thenEvaluate(function () { |
|
64 | this.thenEvaluate(function () { | |
65 | var cell = IPython.notebook.get_cell(0); |
|
65 | var cell = IPython.notebook.get_cell(0); | |
66 | IPython.notebook.select(0); |
|
66 | IPython.notebook.select(0); | |
67 | cell.clear_output(); |
|
67 | cell.clear_output(); | |
68 | cell.set_text('a=13; print(a)'); |
|
68 | cell.set_text('a=13; print(a)'); | |
69 | $("button[data-jupyter-action='ipython.run-select-next']")[0].click() |
|
69 | $("button[data-jupyter-action='ipython.run-select-next']")[0].click() | |
70 | }); |
|
70 | }); | |
71 |
|
71 | |||
72 | this.wait_for_output(0); |
|
72 | this.wait_for_output(0); | |
73 |
|
73 | |||
74 | this.then(function () { |
|
74 | this.then(function () { | |
75 | var result = this.get_output_cell(0); |
|
75 | var result = this.get_output_cell(0); | |
76 | this.test.assertEquals(result.text, '13\n', 'cell execute (using "play" toolbar button)') |
|
76 | this.test.assertEquals(result.text, '13\n', 'cell execute (using "play" toolbar button)') | |
77 | }); |
|
77 | }); | |
78 |
|
78 | |||
79 | // run code with skip_exception |
|
79 | // run code with skip_exception | |
80 | this.thenEvaluate(function () { |
|
80 | this.thenEvaluate(function () { | |
81 | var cell0 = IPython.notebook.get_cell(0); |
|
81 | var cell0 = IPython.notebook.get_cell(0); | |
82 | cell0.set_text('raise IOError'); |
|
82 | cell0.set_text('raise IOError'); | |
83 | IPython.notebook.insert_cell_below('code',0); |
|
83 | IPython.notebook.insert_cell_below('code',0); | |
84 | var cell1 = IPython.notebook.get_cell(1); |
|
84 | var cell1 = IPython.notebook.get_cell(1); | |
85 | cell1.set_text('a=14; print(a)'); |
|
85 | cell1.set_text('a=14; print(a)'); | |
86 | cell0.execute(false); |
|
86 | cell0.execute(false); | |
87 | cell1.execute(); |
|
87 | cell1.execute(); | |
88 | }); |
|
88 | }); | |
89 |
|
89 | |||
90 | this.wait_for_output(1); |
|
90 | this.wait_for_output(1); | |
91 |
|
91 | |||
92 | this.then(function () { |
|
92 | this.then(function () { | |
93 | var result = this.get_output_cell(1); |
|
93 | var result = this.get_output_cell(1); | |
94 | this.test.assertEquals(result.text, '14\n', "cell execute, don't stop on error"); |
|
94 | this.test.assertEquals(result.text, '14\n', "cell execute, don't stop on error"); | |
95 | }); |
|
95 | }); | |
96 |
|
96 | |||
97 | this.thenEvaluate(function () { |
|
97 | this.thenEvaluate(function () { | |
98 | var cell0 = IPython.notebook.get_cell(0); |
|
98 | var cell0 = IPython.notebook.get_cell(0); | |
99 | cell0.set_text('raise IOError'); |
|
99 | cell0.set_text('raise IOError'); | |
100 | IPython.notebook.insert_cell_below('code',0); |
|
100 | IPython.notebook.insert_cell_below('code',0); | |
101 | var cell1 = IPython.notebook.get_cell(1); |
|
101 | var cell1 = IPython.notebook.get_cell(1); | |
102 | cell1.set_text('a=14; print(a)'); |
|
102 | cell1.set_text('a=14; print(a)'); | |
103 | cell0.execute(); |
|
103 | cell0.execute(); | |
104 | cell1.execute(); |
|
104 | cell1.execute(); | |
105 | }); |
|
105 | }); | |
106 |
|
106 | |||
107 |
this.wait_for_output( |
|
107 | this.wait_for_output(0); | |
108 |
|
108 | |||
109 | this.then(function () { |
|
109 | this.then(function () { | |
110 | var result = this.get_output_cell(1); |
|
110 | var outputs = this.evaluate(function() { | |
111 | this.test.assertNotEquals(result.text, '14\n', 'cell execute, stop on error'); |
|
111 | return IPython.notebook.get_cell(1).output_area.outputs; | |
|
112 | }) | |||
|
113 | this.test.assertEquals(outputs.length, 0, 'cell execute, stop on error (default)'); | |||
112 | }); |
|
114 | }); | |
113 | }); |
|
115 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now