Show More
@@ -15,6 +15,9 b' mime = {' | |||||
15 | "javascript" : "application/javascript", |
|
15 | "javascript" : "application/javascript", | |
16 | }; |
|
16 | }; | |
17 |
|
17 | |||
|
18 | // helper function to ensure that the short_name is found in the toJSON | |||
|
19 | // represetnation, while the original in-memory cell retains its long mimetype | |||
|
20 | // name, and that fromJSON also gets its long mimetype name | |||
18 | function assert_has(short_name, json, result, result2) { |
|
21 | function assert_has(short_name, json, result, result2) { | |
19 | long_name = mime[short_name]; |
|
22 | long_name = mime[short_name]; | |
20 | this.test.assertTrue(json[0].hasOwnProperty(short_name), |
|
23 | this.test.assertTrue(json[0].hasOwnProperty(short_name), | |
@@ -24,6 +27,27 b' function assert_has(short_name, json, result, result2) {' | |||||
24 | this.test.assertTrue(result2.hasOwnProperty(long_name), |
|
27 | this.test.assertTrue(result2.hasOwnProperty(long_name), | |
25 | 'fromJSON() embeded ' + short_name + ' gets mime key ' + long_name); |
|
28 | 'fromJSON() embeded ' + short_name + ' gets mime key ' + long_name); | |
26 | } |
|
29 | } | |
|
30 | ||||
|
31 | // helper function for checkout that the first two cells have a particular | |||
|
32 | // output_type (either 'pyout' or 'display_data'), and checks the to/fromJSON | |||
|
33 | // for a set of mimetype keys, using their short names ('javascript', 'text', | |||
|
34 | // 'png', etc). | |||
|
35 | function check_output_area(output_type, keys) { | |||
|
36 | json = this.evaluate(function() { | |||
|
37 | var json = IPython.notebook.get_cell(0).output_area.toJSON(); | |||
|
38 | // appended cell will initially be empty, lets add it some output | |||
|
39 | var cell = IPython.notebook.get_cell(1).output_area.fromJSON(json); | |||
|
40 | return json; | |||
|
41 | }); | |||
|
42 | var result = this.get_output_cell(0); | |||
|
43 | var result2 = this.get_output_cell(1); | |||
|
44 | this.test.assertEquals(result.output_type, output_type, | |||
|
45 | 'testing ' + output_type + ' for ' + keys.join(' and ')); | |||
|
46 | ||||
|
47 | for (var idx in keys) { | |||
|
48 | assert_has.apply(this, [keys[idx], json, result, result2]); | |||
|
49 | } | |||
|
50 | } | |||
27 |
|
51 | |||
28 | casper.notebook_test(function () { |
|
52 | casper.notebook_test(function () { | |
29 | this.evaluate(function () { |
|
53 | this.evaluate(function () { | |
@@ -51,16 +75,7 b' casper.notebook_test(function () {' | |||||
51 | //this.thenEvaluate(function() { IPython.notebook.save_notebook(); }); |
|
75 | //this.thenEvaluate(function() { IPython.notebook.save_notebook(); }); | |
52 |
|
76 | |||
53 | this.then(function ( ) { |
|
77 | this.then(function ( ) { | |
54 | json = this.evaluate(function() { |
|
78 | check_output_area.apply(this, ['display_data', ['javascript']]); | |
55 | var json = IPython.notebook.get_cell(0).output_area.toJSON(); |
|
|||
56 | // appended cell will initially be empty, lets add it some output |
|
|||
57 | var cell = IPython.notebook.get_cell(1).output_area.fromJSON(json); |
|
|||
58 | return json; |
|
|||
59 | }); |
|
|||
60 | var result = this.get_output_cell(0); |
|
|||
61 | var result2 = this.get_output_cell(1); |
|
|||
62 |
|
||||
63 | assert_has.apply(this, ['javascript', json, result, result2]); |
|
|||
64 |
|
79 | |||
65 | }); |
|
80 | }); | |
66 |
|
81 | |||
@@ -74,22 +89,10 b' casper.notebook_test(function () {' | |||||
74 | this.execute_cell(0); |
|
89 | this.execute_cell(0); | |
75 | }); |
|
90 | }); | |
76 |
|
91 | |||
77 |
this.then(function ( |
|
92 | this.then(function () { | |
78 | json = this.evaluate(function() { |
|
93 | check_output_area.apply(this, ['pyout', ['text', 'json']]); | |
79 | var json = IPython.notebook.get_cell(0).output_area.toJSON(); |
|
|||
80 | // appended cell will initially be empty, lets add it some output |
|
|||
81 | var cell = IPython.notebook.get_cell(1).output_area.fromJSON(json); |
|
|||
82 | return json; |
|
|||
83 | }); |
|
|||
84 | var result = this.get_output_cell(0); |
|
|||
85 | var result2 = this.get_output_cell(1); |
|
|||
86 | this.test.assertEquals(result.output_type, 'pyout', |
|
|||
87 | 'testing pyout application/json and text/plain'); |
|
|||
88 |
|
||||
89 | assert_has.apply(this, ['json', json, result, result2]); |
|
|||
90 | assert_has.apply(this, ['text', json, result, result2]); |
|
|||
91 |
|
||||
92 | }); |
|
94 | }); | |
|
95 | ||||
93 | this.then(function() { |
|
96 | this.then(function() { | |
94 | // test display of text/plain and application/json keys |
|
97 | // test display of text/plain and application/json keys | |
95 | this.evaluate(function() { |
|
98 | this.evaluate(function() { | |
@@ -102,20 +105,7 b' casper.notebook_test(function () {' | |||||
102 | }); |
|
105 | }); | |
103 |
|
106 | |||
104 | this.then(function ( ) { |
|
107 | this.then(function ( ) { | |
105 | json = this.evaluate(function() { |
|
108 | check_output_area.apply(this, ['display_data', ['text', 'json']]); | |
106 | var json = IPython.notebook.get_cell(0).output_area.toJSON(); |
|
|||
107 | // appended cell will initially be empty, lets add it some output |
|
|||
108 | var cell = IPython.notebook.get_cell(1).output_area.fromJSON(json); |
|
|||
109 | return json; |
|
|||
110 | }); |
|
|||
111 | var result = this.get_output_cell(0); |
|
|||
112 | var result2 = this.get_output_cell(1); |
|
|||
113 | this.test.assertEquals(result.output_type, 'display_data', |
|
|||
114 | 'testing display_data application/json and text/plain'); |
|
|||
115 |
|
||||
116 | assert_has.apply(this, ['json', json, result, result2]); |
|
|||
117 | assert_has.apply(this, ['text', json, result, result2]); |
|
|||
118 |
|
||||
119 | }); |
|
109 | }); | |
120 |
|
110 | |||
121 | }); |
|
111 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now