##// END OF EJS Templates
test coalesced output in js
MinRK -
Show More
@@ -0,0 +1,98
1 //
2 // Various output tests
3 //
4
5 casper.notebook_test(function () {
6
7 this.test_coalesced_output = function (msg, code, expected) {
8 this.then(function () {
9 this.echo("Test coalesced output: " + msg);
10 });
11
12 this.thenEvaluate(function (code) {
13 IPython.notebook.insert_cell_at_index(0, "code");
14 var cell = IPython.notebook.get_cell(0);
15 cell.set_text(code);
16 cell.execute();
17 }, {code: code});
18
19 this.wait_for_output(0);
20
21 this.then(function () {
22 var results = this.evaluate(function () {
23 var cell = IPython.notebook.get_cell(0);
24 return cell.output_area.outputs;
25 });
26 this.test.assertEquals(results.length, expected.length, "correct number of outputs");
27 for (var i = 0; i < results.length; i++) {
28 var r = results[i];
29 var ex = expected[i];
30 this.test.assertEquals(r.output_type, ex.output_type, "output " + i);
31 if (r.output_type === 'stream') {
32 this.test.assertEquals(r.stream, ex.stream, "stream " + i);
33 this.test.assertEquals(r.text, ex.text, "content " + i);
34 }
35 }
36 });
37
38 };
39
40 this.thenEvaluate(function () {
41 IPython.notebook.insert_cell_at_index(0, "code");
42 var cell = IPython.notebook.get_cell(0);
43 cell.set_text([
44 "from __future__ import print_function",
45 "import sys",
46 "from IPython.display import display"
47 ].join("\n")
48 );
49 cell.execute();
50 });
51
52 this.test_coalesced_output("stdout", [
53 "print(1)",
54 "sys.stdout.flush()",
55 "print(2)",
56 "sys.stdout.flush()",
57 "print(3)"
58 ].join("\n"), [{
59 output_type: "stream",
60 stream: "stdout",
61 text: "1\n2\n3\n"
62 }]
63 );
64
65 this.test_coalesced_output("stdout+sdterr", [
66 "print(1)",
67 "sys.stdout.flush()",
68 "print(2)",
69 "print(3, file=sys.stderr)"
70 ].join("\n"), [{
71 output_type: "stream",
72 stream: "stdout",
73 text: "1\n2\n"
74 },{
75 output_type: "stream",
76 stream: "stderr",
77 text: "3\n"
78 }]
79 );
80
81 this.test_coalesced_output("display splits streams", [
82 "print(1)",
83 "sys.stdout.flush()",
84 "display(2)",
85 "print(3)"
86 ].join("\n"), [{
87 output_type: "stream",
88 stream: "stdout",
89 text: "1\n"
90 },{
91 output_type: "display_data",
92 },{
93 output_type: "stream",
94 stream: "stdout",
95 text: "3\n"
96 }]
97 );
98 });
@@ -151,7 +151,7 casper.notebook_test(function () {
151 'display(textbox)\n' +
151 'display(textbox)\n' +
152 'textbox.add_class("my-throttle-textbox")\n' +
152 'textbox.add_class("my-throttle-textbox")\n' +
153 'def handle_change(name, old, new):\n' +
153 'def handle_change(name, old, new):\n' +
154 ' print(len(new))\n' +
154 ' display(len(new))\n' +
155 ' time.sleep(0.5)\n' +
155 ' time.sleep(0.5)\n' +
156 'textbox.on_trait_change(handle_change, "value")\n' +
156 'textbox.on_trait_change(handle_change, "value")\n' +
157 'print(textbox.model_id)');
157 'print(textbox.model_id)');
@@ -182,7 +182,7 casper.notebook_test(function () {
182 this.test.assert(outputs.length <= 5, 'Messages throttled.');
182 this.test.assert(outputs.length <= 5, 'Messages throttled.');
183
183
184 // We also need to verify that the last state sent was correct.
184 // We also need to verify that the last state sent was correct.
185 var last_state = outputs[outputs.length-1].text;
185 var last_state = outputs[outputs.length-1]['text/plain'];
186 this.test.assertEquals(last_state, "20\n", "Last state sent when throttling.");
186 this.test.assertEquals(last_state, "20", "Last state sent when throttling.");
187 });
187 });
188 });
188 });
@@ -11,7 +11,7 casper.notebook_test(function () {
11 'display(button)\n'+
11 'display(button)\n' +
12 'print("Success")\n' +
12 'print("Success")\n' +
13 'def handle_click(sender):\n' +
13 'def handle_click(sender):\n' +
14 ' print("Clicked")\n' +
14 ' display("Clicked")\n' +
15 'button.on_click(handle_click)');
15 'button.on_click(handle_click)');
16 this.execute_cell_then(button_index, function(index){
16 this.execute_cell_then(button_index, function(index){
17
17
@@ -37,7 +37,7 casper.notebook_test(function () {
37 this.wait_for_output(button_index, 1);
37 this.wait_for_output(button_index, 1);
38
38
39 this.then(function () {
39 this.then(function () {
40 this.test.assertEquals(this.get_output_cell(button_index, 1).text, 'Clicked\n',
40 this.test.assertEquals(this.get_output_cell(button_index, 1)['text/plain'], "'Clicked'",
41 'Button click event fires.');
41 'Button click event fires.');
42 });
42 });
43 }); No newline at end of file
43 });
General Comments 0
You need to be logged in to leave comments. Login now