Show More
@@ -9,9 +9,9 b' from ..nbbase import (' | |||||
9 | new_metadata, new_author, new_heading_cell, nbformat, nbformat_minor |
|
9 | new_metadata, new_author, new_heading_cell, nbformat, nbformat_minor | |
10 | ) |
|
10 | ) | |
11 |
|
11 | |||
12 |
# some random base64-encoded * |
|
12 | # some random base64-encoded *text* | |
13 | png = encodestring(os.urandom(5)) |
|
13 | png = encodestring(os.urandom(5)).decode('ascii') | |
14 | jpeg = encodestring(os.urandom(6)) |
|
14 | jpeg = encodestring(os.urandom(6)).decode('ascii') | |
15 |
|
15 | |||
16 | ws = new_worksheet(name='worksheet1') |
|
16 | ws = new_worksheet(name='worksheet1') | |
17 |
|
17 |
@@ -1,4 +1,5 b'' | |||||
1 | import pprint |
|
1 | import pprint | |
|
2 | from base64 import decodestring | |||
2 | from unittest import TestCase |
|
3 | from unittest import TestCase | |
3 |
|
4 | |||
4 | from ..nbjson import reads, writes |
|
5 | from ..nbjson import reads, writes | |
@@ -29,5 +30,42 b' class TestJSON(formattest.NBFormatTest, TestCase):' | |||||
29 | s = writes(nb0, split_lines=True) |
|
30 | s = writes(nb0, split_lines=True) | |
30 | self.assertEqual(nbjson.reads(s),nb0) |
|
31 | self.assertEqual(nbjson.reads(s),nb0) | |
31 |
|
32 | |||
|
33 | def test_read_png(self): | |||
|
34 | """PNG output data is b64 unicode""" | |||
|
35 | s = writes(nb0) | |||
|
36 | nb1 = nbjson.reads(s) | |||
|
37 | found_png = False | |||
|
38 | for cell in nb1.worksheets[0].cells: | |||
|
39 | if not 'outputs' in cell: | |||
|
40 | continue | |||
|
41 | for output in cell.outputs: | |||
|
42 | if 'png' in output: | |||
|
43 | found_png = True | |||
|
44 | pngdata = output['png'] | |||
|
45 | self.assertEqual(type(pngdata), unicode) | |||
|
46 | # test that it is valid b64 data | |||
|
47 | b64bytes = pngdata.encode('ascii') | |||
|
48 | raw_bytes = decodestring(b64bytes) | |||
|
49 | assert found_png, "never found png output" | |||
|
50 | ||||
|
51 | def test_read_jpeg(self): | |||
|
52 | """JPEG output data is b64 unicode""" | |||
|
53 | s = writes(nb0) | |||
|
54 | nb1 = nbjson.reads(s) | |||
|
55 | found_jpeg = False | |||
|
56 | for cell in nb1.worksheets[0].cells: | |||
|
57 | if not 'outputs' in cell: | |||
|
58 | continue | |||
|
59 | for output in cell.outputs: | |||
|
60 | if 'jpeg' in output: | |||
|
61 | found_jpeg = True | |||
|
62 | jpegdata = output['jpeg'] | |||
|
63 | self.assertEqual(type(jpegdata), unicode) | |||
|
64 | # test that it is valid b64 data | |||
|
65 | b64bytes = jpegdata.encode('ascii') | |||
|
66 | raw_bytes = decodestring(b64bytes) | |||
|
67 | assert found_jpeg, "never found jpeg output" | |||
|
68 | ||||
|
69 | ||||
32 |
|
70 | |||
33 |
|
71 |
General Comments 0
You need to be logged in to leave comments.
Login now