##// END OF EJS Templates
saving notebook does not run cell....
Bussonnier Matthias -
Show More
@@ -1,78 +1,78
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.save-notebook']")[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 });
@@ -1,62 +1,62
1 //
1 //
2 // Test that a Markdown cell is rendered to HTML.
2 // Test that a Markdown cell is rendered to HTML.
3 //
3 //
4 casper.notebook_test(function () {
4 casper.notebook_test(function () {
5 // Test JavaScript models.
5 // Test JavaScript models.
6 var output = this.evaluate(function () {
6 var output = this.evaluate(function () {
7 IPython.notebook.to_markdown();
7 IPython.notebook.to_markdown();
8 var cell = IPython.notebook.get_selected_cell();
8 var cell = IPython.notebook.get_selected_cell();
9 cell.set_text('# Foo');
9 cell.set_text('# Foo');
10 cell.render();
10 cell.render();
11 return cell.get_rendered();
11 return cell.get_rendered();
12 });
12 });
13 this.test.assertEquals(output.trim(), '<h1 id=\"Foo\">Foo<a class=\"anchor-link\" href=\"#Foo\">ΒΆ</a></h1>', 'Markdown JS API works.');
13 this.test.assertEquals(output.trim(), '<h1 id=\"Foo\">Foo<a class=\"anchor-link\" href=\"#Foo\">ΒΆ</a></h1>', 'Markdown JS API works.');
14
14
15 // Test menubar entries.
15 // Test menubar entries.
16 output = this.evaluate(function () {
16 output = this.evaluate(function () {
17 $('#to_code').mouseenter().click();
17 $('#to_code').mouseenter().click();
18 $('#to_markdown').mouseenter().click();
18 $('#to_markdown').mouseenter().click();
19 var cell = IPython.notebook.get_selected_cell();
19 var cell = IPython.notebook.get_selected_cell();
20 cell.set_text('**Bar**');
20 cell.set_text('**Bar**');
21 $('#run_cell').mouseenter().click();
21 $('#run_cell').mouseenter().click();
22 return cell.get_rendered();
22 return cell.get_rendered();
23 });
23 });
24 this.test.assertEquals(output.trim(), '<p><strong>Bar</strong></p>', 'Markdown menubar items work.');
24 this.test.assertEquals(output.trim(), '<p><strong>Bar</strong></p>', 'Markdown menubar items work.');
25
25
26 // Test toolbar buttons.
26 // Test toolbar buttons.
27 output = this.evaluate(function () {
27 output = this.evaluate(function () {
28 $('#cell_type').val('code').change();
28 $('#cell_type').val('code').change();
29 $('#cell_type').val('markdown').change();
29 $('#cell_type').val('markdown').change();
30 var cell = IPython.notebook.get_selected_cell();
30 var cell = IPython.notebook.get_selected_cell();
31 cell.set_text('*Baz*');
31 cell.set_text('*Baz*');
32 $("button[data-jupyter-action='ipython.save-notebook']")[0].click();
32 $("button[data-jupyter-action='ipython.run-select-next']")[0].click();
33 return cell.get_rendered();
33 return cell.get_rendered();
34 });
34 });
35 this.test.assertEquals(output.trim(), '<p><em>Baz</em></p>', 'Markdown toolbar items work.');
35 this.test.assertEquals(output.trim(), '<p><em>Baz</em></p>', 'Markdown toolbar items work.');
36
36
37 // Test markdown headings
37 // Test markdown headings
38
38
39 var text = 'multi\nline';
39 var text = 'multi\nline';
40
40
41 this.evaluate(function (text) {
41 this.evaluate(function (text) {
42 var cell = IPython.notebook.insert_cell_at_index('markdown', 0);
42 var cell = IPython.notebook.insert_cell_at_index('markdown', 0);
43 cell.set_text(text);
43 cell.set_text(text);
44 }, {text: text});
44 }, {text: text});
45
45
46 var set_level = function (level) {
46 var set_level = function (level) {
47 return casper.evaluate(function (level) {
47 return casper.evaluate(function (level) {
48 var cell = IPython.notebook.get_cell(0);
48 var cell = IPython.notebook.get_cell(0);
49 cell.set_heading_level(level);
49 cell.set_heading_level(level);
50 return cell.get_text();
50 return cell.get_text();
51 }, {level: level});
51 }, {level: level});
52 };
52 };
53
53
54 var level_text;
54 var level_text;
55 var levels = [ 1, 2, 3, 4, 5, 6, 2, 1 ];
55 var levels = [ 1, 2, 3, 4, 5, 6, 2, 1 ];
56 for (var idx=0; idx < levels.length; idx++) {
56 for (var idx=0; idx < levels.length; idx++) {
57 var level = levels[idx];
57 var level = levels[idx];
58 level_text = set_level(level);
58 level_text = set_level(level);
59 hashes = new Array(level + 1).join('#');
59 hashes = new Array(level + 1).join('#');
60 this.test.assertEquals(level_text, hashes + ' ' + text, 'markdown set_heading_level ' + level);
60 this.test.assertEquals(level_text, hashes + ' ' + text, 'markdown set_heading_level ' + level);
61 }
61 }
62 });
62 });
General Comments 0
You need to be logged in to leave comments. Login now