##// END OF EJS Templates
Merge pull request #7379 from juhasch/js-tests...
Min RK -
r19816:4b2be133 merge
parent child Browse files
Show More
@@ -1,63 +1,63 b''
1 //
1 //
2 // Test display of images
2 // Test display of images
3 //
3 //
4 // The effect of shape metadata is validated,
4 // The effect of shape metadata is validated,
5 // using Image(retina=True)
5 // using Image(retina=True)
6 //
6 //
7
7
8
8
9 // 2x2 black square in b64 jpeg and png
9 // 2x2 black square in b64 jpeg and png
10 b64_image_data = {
10 b64_image_data = {
11 "image/png" : "b'iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAC0lEQVR4nGNgQAYAAA4AAamRc7EA\\nAAAASUVORK5CYII='",
11 "image/png" : "b'iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAC0lEQVR4nGNgQAYAAA4AAamRc7EA\\nAAAASUVORK5CYII='",
12 "image/jpeg" : "b'/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a\\nHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy\\nMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAACAAIDASIA\\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\\nAwEBAQEBAQEBAQAAAAAA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YaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD5/ooo\\noA//2Q=='"
13 }
13 }
14
14
15
15
16 casper.notebook_test(function () {
16 casper.notebook_test(function () {
17 this.test_img_shape = function(fmt, retina) {
17 this.test_img_shape = function(fmt, retina) {
18 this.thenEvaluate(function (b64data, retina) {
18 this.thenEvaluate(function (b64data, retina) {
19 IPython.notebook.insert_cell_at_index(0, "code");
19 IPython.notebook.insert_cell_at_index("code", 0);
20 var cell = IPython.notebook.get_cell(0);
20 var cell = IPython.notebook.get_cell(0);
21 cell.set_text([
21 cell.set_text([
22 "import base64",
22 "import base64",
23 "from IPython.display import display, Image",
23 "from IPython.display import display, Image",
24 "data = base64.decodestring(" + b64data + ")",
24 "data = base64.decodestring(" + b64data + ")",
25 "retina = bool(" + retina + ")",
25 "retina = bool(" + retina + ")",
26 "display(Image(data, retina=retina))"
26 "display(Image(data, retina=retina))"
27 ].join("\n"));
27 ].join("\n"));
28 cell.execute();
28 cell.execute();
29 }, {b64data : b64_image_data[fmt], retina : retina ? 1:0 });
29 }, {b64data : b64_image_data[fmt], retina : retina ? 1:0 });
30
30
31 this.wait_for_output(0);
31 this.wait_for_output(0);
32
32
33 this.then(function() {
33 this.then(function() {
34 var img = this.evaluate(function() {
34 var img = this.evaluate(function() {
35 // get a summary of the image that was just displayed
35 // get a summary of the image that was just displayed
36 var cell = IPython.notebook.get_cell(0);
36 var cell = IPython.notebook.get_cell(0);
37 var img = $(cell.output_area.element.find("img")[0]);
37 var img = $(cell.output_area.element.find("img")[0]);
38 return {
38 return {
39 src : img.attr("src"),
39 src : img.attr("src"),
40 width : img.width(),
40 width : img.width(),
41 height : img.height(),
41 height : img.height(),
42 width_attr : img.attr("width"),
42 width_attr : img.attr("width"),
43 height_attr : img.attr("height")
43 height_attr : img.attr("height")
44 };
44 };
45 });
45 });
46 var prefix = "Image('" + fmt + "', retina=" + retina + ") ";
46 var prefix = "Image('" + fmt + "', retina=" + retina + ") ";
47 this.test.assertType(img, "object", prefix + "img was displayed");
47 this.test.assertType(img, "object", prefix + "img was displayed");
48 this.test.assertEquals(img.src.split(',')[0], "data:" + fmt + ";base64",
48 this.test.assertEquals(img.src.split(',')[0], "data:" + fmt + ";base64",
49 prefix + "data-uri prefix"
49 prefix + "data-uri prefix"
50 );
50 );
51 var sz = retina ? 1 : 2;
51 var sz = retina ? 1 : 2;
52 var sz_attr = retina ? "1" : undefined;
52 var sz_attr = retina ? "1" : undefined;
53 this.test.assertEquals(img.height, sz, prefix + "measured height");
53 this.test.assertEquals(img.height, sz, prefix + "measured height");
54 this.test.assertEquals(img.width, sz, prefix + "measured width");
54 this.test.assertEquals(img.width, sz, prefix + "measured width");
55 this.test.assertEquals(img.height_attr, sz_attr, prefix + "height attr");
55 this.test.assertEquals(img.height_attr, sz_attr, prefix + "height attr");
56 this.test.assertEquals(img.width_attr, sz_attr, prefix + "width attr");
56 this.test.assertEquals(img.width_attr, sz_attr, prefix + "width attr");
57 });
57 });
58 };
58 };
59 this.test_img_shape("image/png", false);
59 this.test_img_shape("image/png", false);
60 this.test_img_shape("image/png", true);
60 this.test_img_shape("image/png", true);
61 this.test_img_shape("image/jpeg", false);
61 this.test_img_shape("image/jpeg", false);
62 this.test_img_shape("image/jpeg", true);
62 this.test_img_shape("image/jpeg", true);
63 });
63 });
@@ -1,98 +1,98 b''
1 //
1 //
2 // Various output tests
2 // Various output tests
3 //
3 //
4
4
5 casper.notebook_test(function () {
5 casper.notebook_test(function () {
6
6
7 this.test_coalesced_output = function (msg, code, expected) {
7 this.test_coalesced_output = function (msg, code, expected) {
8 this.then(function () {
8 this.then(function () {
9 this.echo("Test coalesced output: " + msg);
9 this.echo("Test coalesced output: " + msg);
10 });
10 });
11
11
12 this.thenEvaluate(function (code) {
12 this.thenEvaluate(function (code) {
13 IPython.notebook.insert_cell_at_index(0, "code");
13 IPython.notebook.insert_cell_at_index("code", 0);
14 var cell = IPython.notebook.get_cell(0);
14 var cell = IPython.notebook.get_cell(0);
15 cell.set_text(code);
15 cell.set_text(code);
16 cell.execute();
16 cell.execute();
17 }, {code: code});
17 }, {code: code});
18
18
19 this.wait_for_output(0);
19 this.wait_for_output(0);
20
20
21 this.then(function () {
21 this.then(function () {
22 var results = this.evaluate(function () {
22 var results = this.evaluate(function () {
23 var cell = IPython.notebook.get_cell(0);
23 var cell = IPython.notebook.get_cell(0);
24 return cell.output_area.outputs;
24 return cell.output_area.outputs;
25 });
25 });
26 this.test.assertEquals(results.length, expected.length, "correct number of outputs");
26 this.test.assertEquals(results.length, expected.length, "correct number of outputs");
27 for (var i = 0; i < results.length; i++) {
27 for (var i = 0; i < results.length; i++) {
28 var r = results[i];
28 var r = results[i];
29 var ex = expected[i];
29 var ex = expected[i];
30 this.test.assertEquals(r.output_type, ex.output_type, "output " + i);
30 this.test.assertEquals(r.output_type, ex.output_type, "output " + i);
31 if (r.output_type === 'stream') {
31 if (r.output_type === 'stream') {
32 this.test.assertEquals(r.name, ex.name, "stream " + i);
32 this.test.assertEquals(r.name, ex.name, "stream " + i);
33 this.test.assertEquals(r.text, ex.text, "content " + i);
33 this.test.assertEquals(r.text, ex.text, "content " + i);
34 }
34 }
35 }
35 }
36 });
36 });
37
37
38 };
38 };
39
39
40 this.thenEvaluate(function () {
40 this.thenEvaluate(function () {
41 IPython.notebook.insert_cell_at_index(0, "code");
41 IPython.notebook.insert_cell_at_index("code", 0);
42 var cell = IPython.notebook.get_cell(0);
42 var cell = IPython.notebook.get_cell(0);
43 cell.set_text([
43 cell.set_text([
44 "from __future__ import print_function",
44 "from __future__ import print_function",
45 "import sys",
45 "import sys",
46 "from IPython.display import display"
46 "from IPython.display import display"
47 ].join("\n")
47 ].join("\n")
48 );
48 );
49 cell.execute();
49 cell.execute();
50 });
50 });
51
51
52 this.test_coalesced_output("stdout", [
52 this.test_coalesced_output("stdout", [
53 "print(1)",
53 "print(1)",
54 "sys.stdout.flush()",
54 "sys.stdout.flush()",
55 "print(2)",
55 "print(2)",
56 "sys.stdout.flush()",
56 "sys.stdout.flush()",
57 "print(3)"
57 "print(3)"
58 ].join("\n"), [{
58 ].join("\n"), [{
59 output_type: "stream",
59 output_type: "stream",
60 name: "stdout",
60 name: "stdout",
61 text: "1\n2\n3\n"
61 text: "1\n2\n3\n"
62 }]
62 }]
63 );
63 );
64
64
65 this.test_coalesced_output("stdout+sdterr", [
65 this.test_coalesced_output("stdout+sdterr", [
66 "print(1)",
66 "print(1)",
67 "sys.stdout.flush()",
67 "sys.stdout.flush()",
68 "print(2)",
68 "print(2)",
69 "print(3, file=sys.stderr)"
69 "print(3, file=sys.stderr)"
70 ].join("\n"), [{
70 ].join("\n"), [{
71 output_type: "stream",
71 output_type: "stream",
72 name: "stdout",
72 name: "stdout",
73 text: "1\n2\n"
73 text: "1\n2\n"
74 },{
74 },{
75 output_type: "stream",
75 output_type: "stream",
76 name: "stderr",
76 name: "stderr",
77 text: "3\n"
77 text: "3\n"
78 }]
78 }]
79 );
79 );
80
80
81 this.test_coalesced_output("display splits streams", [
81 this.test_coalesced_output("display splits streams", [
82 "print(1)",
82 "print(1)",
83 "sys.stdout.flush()",
83 "sys.stdout.flush()",
84 "display(2)",
84 "display(2)",
85 "print(3)"
85 "print(3)"
86 ].join("\n"), [{
86 ].join("\n"), [{
87 output_type: "stream",
87 output_type: "stream",
88 name: "stdout",
88 name: "stdout",
89 text: "1\n"
89 text: "1\n"
90 },{
90 },{
91 output_type: "display_data",
91 output_type: "display_data",
92 },{
92 },{
93 output_type: "stream",
93 output_type: "stream",
94 name: "stdout",
94 name: "stdout",
95 text: "3\n"
95 text: "3\n"
96 }]
96 }]
97 );
97 );
98 });
98 });
General Comments 0
You need to be logged in to leave comments. Login now