Show More
@@ -1,64 +1,64 b'' | |||
|
1 | 1 | // |
|
2 | 2 | // Test display of images |
|
3 | 3 | // |
|
4 | 4 | // The effect of shape metadata is validated, |
|
5 | 5 | // using Image(retina=True) |
|
6 | 6 | // |
|
7 | 7 | |
|
8 | 8 | |
|
9 | 9 | // 2x2 black square in b64 jpeg and png |
|
10 | 10 | b64_image_data = { |
|
11 | 11 | "image/png" : "b'iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAC0lEQVR4nGNgQAYAAA4AAamRc7EA\\nAAAASUVORK5CYII='", |
|
12 | 12 | "image/jpeg" : "b'/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a\\nHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy\\nMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAACAAIDASIA\\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK\\nU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD5/ooo\\noA//2Q=='" |
|
13 | 13 | } |
|
14 | 14 | |
|
15 | 15 | |
|
16 | 16 | casper.notebook_test(function () { |
|
17 | 17 | // this.printLog(); |
|
18 | 18 | this.test_img_shape = function(fmt, retina) { |
|
19 | 19 | this.thenEvaluate(function (b64data, retina) { |
|
20 | 20 | IPython.notebook.get_cell(0).clear_output(); |
|
21 | 21 | var cell = IPython.notebook.get_cell(0); |
|
22 | 22 | cell.set_text([ |
|
23 | 23 | "import base64", |
|
24 | 24 | "from IPython.display import display, Image", |
|
25 | 25 | "data = base64.decodestring(" + b64data + ")", |
|
26 | 26 | "retina = bool(" + retina + ")", |
|
27 | 27 | "display(Image(data, retina=retina))" |
|
28 | 28 | ].join("\n")); |
|
29 | 29 | cell.execute(); |
|
30 | 30 | }, {b64data : b64_image_data[fmt], retina : retina ? 1:0 }); |
|
31 | 31 | |
|
32 | 32 | this.wait_for_output(0); |
|
33 | 33 | |
|
34 | 34 | this.then(function() { |
|
35 | 35 | var img = this.evaluate(function() { |
|
36 | 36 | // get a summary of the image that was just displayed |
|
37 | 37 | var cell = IPython.notebook.get_cell(0); |
|
38 | 38 | var img = $(cell.output_area.element.find("img")[0]); |
|
39 | 39 | return { |
|
40 | 40 | src : img.attr("src"), |
|
41 | 41 | width : img.width(), |
|
42 | 42 | height : img.height(), |
|
43 | 43 | width_attr : img.attr("width"), |
|
44 | 44 | height_attr : img.attr("height") |
|
45 | 45 | }; |
|
46 | 46 | }); |
|
47 | 47 | var prefix = "Image('" + fmt + "', retina=" + retina + ") "; |
|
48 |
this.test.assert |
|
|
48 | this.test.assertType(img, "object", prefix + "img was displayed"); | |
|
49 | 49 | this.test.assertEquals(img.src.split(',')[0], "data:" + fmt + ";base64", |
|
50 | 50 | prefix + "data-uri prefix" |
|
51 | 51 | ); |
|
52 | 52 | var sz = retina ? 1 : 2; |
|
53 | 53 | var sz_attr = retina ? "1" : undefined; |
|
54 | 54 | this.test.assertEquals(img.height, sz, prefix + "measured height"); |
|
55 | 55 | this.test.assertEquals(img.width, sz, prefix + "measured width"); |
|
56 | 56 | this.test.assertEquals(img.height_attr, sz_attr, prefix + "height attr"); |
|
57 | 57 | this.test.assertEquals(img.width_attr, sz_attr, prefix + "width attr"); |
|
58 | 58 | }); |
|
59 | 59 | }; |
|
60 | 60 | this.test_img_shape("image/png", false); |
|
61 | 61 | this.test_img_shape("image/png", true); |
|
62 | 62 | this.test_img_shape("image/jpeg", false); |
|
63 | 63 | this.test_img_shape("image/jpeg", true); |
|
64 | 64 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now