##// END OF EJS Templates
refactor tests with more concise assertion checks
Paul Ivanov -
Show More
@@ -1,6 +1,30 b''
1 // Test opening a rich notebook, saving it, and reopening it again.
1 // Test opening a rich notebook, saving it, and reopening it again.
2 //
2 //
3 //toJSON fromJSON toJSON and do a string comparison
3 //toJSON fromJSON toJSON and do a string comparison
4
5
6 // this is just a copy of OutputArea.mime_mape_r in IPython/html/static/notebook/js/outputarea.js
7 mime = {
8 "text" : "text/plain",
9 "html" : "text/html",
10 "svg" : "image/svg+xml",
11 "png" : "image/png",
12 "jpeg" : "image/jpeg",
13 "latex" : "text/latex",
14 "json" : "application/json",
15 "javascript" : "application/javascript",
16 };
17
18 function assert_has(short_name, json, result, result2) {
19 long_name = mime[short_name];
20 this.test.assertTrue(result.hasOwnProperty(long_name),
21 'toJSON() original embeded JSON keeps ' + long_name);
22 this.test.assertTrue(json[0].hasOwnProperty(short_name),
23 'toJSON() representation uses ' + short_name);
24 this.test.assertTrue(result2.hasOwnProperty(long_name),
25 'fromJSON() embeded ' + short_name + ' gets mime key ' + long_name);
26 }
27
4 casper.notebook_test(function () {
28 casper.notebook_test(function () {
5 this.evaluate(function () {
29 this.evaluate(function () {
6 var cell = IPython.notebook.get_cell(0);
30 var cell = IPython.notebook.get_cell(0);
@@ -35,12 +59,8 b' casper.notebook_test(function () {'
35 });
59 });
36 var result = this.get_output_cell(0);
60 var result = this.get_output_cell(0);
37 var result2 = this.get_output_cell(1);
61 var result2 = this.get_output_cell(1);
38 this.test.assertTrue(result.hasOwnProperty('application/javascript'),
62
39 'toJSON() original embeded JS keeps mime key');
63 assert_has.apply(this, ['javascript', json, result, result2]);
40 this.test.assertTrue(json[0].hasOwnProperty('javascript'),
41 'toJSON() representation uses short key');
42 this.test.assertTrue(result2.hasOwnProperty('application/javascript'),
43 'fromJSON() embeded JS gets mime key');
44
64
45 });
65 });
46
66
@@ -53,7 +73,7 b' casper.notebook_test(function () {'
53 this.set_cell_text(0, "%lsmagic");
73 this.set_cell_text(0, "%lsmagic");
54 this.execute_cell(0);
74 this.execute_cell(0);
55 });
75 });
56
76
57 this.then(function ( ) {
77 this.then(function ( ) {
58 json = this.evaluate(function() {
78 json = this.evaluate(function() {
59 var json = IPython.notebook.get_cell(0).output_area.toJSON();
79 var json = IPython.notebook.get_cell(0).output_area.toJSON();
@@ -65,12 +85,9 b' casper.notebook_test(function () {'
65 var result2 = this.get_output_cell(1);
85 var result2 = this.get_output_cell(1);
66 this.test.assertEquals(result.output_type, 'pyout',
86 this.test.assertEquals(result.output_type, 'pyout',
67 'testing pyout application/json and text/plain');
87 'testing pyout application/json and text/plain');
68 this.test.assertTrue(result.hasOwnProperty('application/json'),
88
69 'toJSON() original embeded JSON keeps mime key');
89 assert_has.apply(this, ['json', json, result, result2]);
70 this.test.assertTrue(json[0].hasOwnProperty('json'),
90 assert_has.apply(this, ['text', json, result, result2]);
71 'toJSON() representation uses short key');
72 this.test.assertTrue(result2.hasOwnProperty('application/json'),
73 'fromJSON() embeded JS gets mime key');
74
91
75 });
92 });
76 this.then(function() {
93 this.then(function() {
@@ -95,29 +112,10 b' casper.notebook_test(function () {'
95 var result2 = this.get_output_cell(1);
112 var result2 = this.get_output_cell(1);
96 this.test.assertEquals(result.output_type, 'display_data',
113 this.test.assertEquals(result.output_type, 'display_data',
97 'testing display_data application/json and text/plain');
114 'testing display_data application/json and text/plain');
98 this.test.assertTrue(result.hasOwnProperty('text/plain'),
115
99 'toJSON()\t original embeded text keeps mime key');
116 assert_has.apply(this, ['json', json, result, result2]);
100 this.test.assertTrue(json[0].hasOwnProperty('text'),
117 assert_has.apply(this, ['text', json, result, result2]);
101 'toJSON()\t representation uses short key');
102 this.test.assertTrue(result2.hasOwnProperty('text/plain'),
103 'fromJSON()\t embeded text gets mime key');
104
118
105 });
119 });
106
120
107
108 //this.thenEvaluate(function () {
109 //var cell = IPython.notebook.get_cell(0);
110
111 // // we have to make messes to find out who we are
112 // cell.set_text([
113 // "import IPython.html.tests as t",
114 // "t.write_test_notebook('rich_output.ipynb')"
115 // ].join('\n')
116 // );
117
118 // cell.execute();
119 //});
120 //
121 //this.wait_for_output(0);
122
123 });
121 });
General Comments 0
You need to be logged in to leave comments. Login now