Show More
@@ -0,0 +1,98 b'' | |||
|
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 b' casper.notebook_test(function () {' | |||
|
151 | 151 | 'display(textbox)\n' + |
|
152 | 152 | 'textbox.add_class("my-throttle-textbox")\n' + |
|
153 | 153 | 'def handle_change(name, old, new):\n' + |
|
154 |
' |
|
|
154 | ' display(len(new))\n' + | |
|
155 | 155 | ' time.sleep(0.5)\n' + |
|
156 | 156 | 'textbox.on_trait_change(handle_change, "value")\n' + |
|
157 | 157 | 'print(textbox.model_id)'); |
@@ -182,7 +182,7 b' casper.notebook_test(function () {' | |||
|
182 | 182 | this.test.assert(outputs.length <= 5, 'Messages throttled.'); |
|
183 | 183 | |
|
184 | 184 | // We also need to verify that the last state sent was correct. |
|
185 |
var last_state = outputs[outputs.length-1] |
|
|
186 |
this.test.assertEquals(last_state, "20 |
|
|
185 | var last_state = outputs[outputs.length-1]['text/plain']; | |
|
186 | this.test.assertEquals(last_state, "20", "Last state sent when throttling."); | |
|
187 | 187 | }); |
|
188 | 188 | }); |
@@ -8,14 +8,14 b' casper.notebook_test(function () {' | |||
|
8 | 8 | |
|
9 | 9 | var button_index = this.append_cell( |
|
10 | 10 | 'button = widgets.ButtonWidget(description="Title")\n' + |
|
11 | 'display(button)\n'+ | |
|
11 | 'display(button)\n' + | |
|
12 | 12 | 'print("Success")\n' + |
|
13 | 13 | 'def handle_click(sender):\n' + |
|
14 |
' |
|
|
14 | ' display("Clicked")\n' + | |
|
15 | 15 | 'button.on_click(handle_click)'); |
|
16 | 16 | this.execute_cell_then(button_index, function(index){ |
|
17 | 17 | |
|
18 |
this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', |
|
|
18 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', | |
|
19 | 19 | 'Create button cell executed with correct output.'); |
|
20 | 20 | |
|
21 | 21 | this.test.assert(this.cell_element_exists(index, |
@@ -37,7 +37,7 b' casper.notebook_test(function () {' | |||
|
37 | 37 | this.wait_for_output(button_index, 1); |
|
38 | 38 | |
|
39 | 39 | this.then(function () { |
|
40 |
this.test.assertEquals(this.get_output_cell(button_index, 1) |
|
|
40 | this.test.assertEquals(this.get_output_cell(button_index, 1)['text/plain'], "'Clicked'", | |
|
41 | 41 | 'Button click event fires.'); |
|
42 | 42 | }); |
|
43 | 43 | }); No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now