Show More
@@ -91,39 +91,39 b' class ExecuteReply(object):' | |||||
91 |
|
91 | |||
92 | def __repr__(self): |
|
92 | def __repr__(self): | |
93 | pyout = self.metadata['pyout'] or {} |
|
93 | pyout = self.metadata['pyout'] or {} | |
94 | text_out = pyout.get('text/plain', '') |
|
94 | text_out = pyout.get('data', {}).get('text/plain', '') | |
95 | if len(text_out) > 32: |
|
95 | if len(text_out) > 32: | |
96 | text_out = text_out[:29] + '...' |
|
96 | text_out = text_out[:29] + '...' | |
97 |
|
97 | |||
98 | return "<ExecuteReply[%i]: %s>" % (self.execution_count, text_out) |
|
98 | return "<ExecuteReply[%i]: %s>" % (self.execution_count, text_out) | |
99 |
|
99 | |||
100 | def _repr_html_(self): |
|
100 | def _repr_html_(self): | |
101 | pyout = self.metadata['pyout'] or {} |
|
101 | pyout = self.metadata['pyout'] or {'data':{}} | |
102 | return pyout.get("text/html") |
|
102 | return pyout['data'].get("text/html") | |
103 |
|
103 | |||
104 | def _repr_latex_(self): |
|
104 | def _repr_latex_(self): | |
105 | pyout = self.metadata['pyout'] or {} |
|
105 | pyout = self.metadata['pyout'] or {'data':{}} | |
106 | return pyout.get("text/latex") |
|
106 | return pyout['data'].get("text/latex") | |
107 |
|
107 | |||
108 | def _repr_json_(self): |
|
108 | def _repr_json_(self): | |
109 | pyout = self.metadata['pyout'] or {} |
|
109 | pyout = self.metadata['pyout'] or {'data':{}} | |
110 | return pyout.get("application/json") |
|
110 | return pyout['data'].get("application/json") | |
111 |
|
111 | |||
112 | def _repr_javascript_(self): |
|
112 | def _repr_javascript_(self): | |
113 | pyout = self.metadata['pyout'] or {} |
|
113 | pyout = self.metadata['pyout'] or {'data':{}} | |
114 | return pyout.get("application/javascript") |
|
114 | return pyout['data'].get("application/javascript") | |
115 |
|
115 | |||
116 | def _repr_png_(self): |
|
116 | def _repr_png_(self): | |
117 | pyout = self.metadata['pyout'] or {} |
|
117 | pyout = self.metadata['pyout'] or {'data':{}} | |
118 | return pyout.get("image/png") |
|
118 | return pyout['data'].get("image/png") | |
119 |
|
119 | |||
120 | def _repr_jpeg_(self): |
|
120 | def _repr_jpeg_(self): | |
121 | pyout = self.metadata['pyout'] or {} |
|
121 | pyout = self.metadata['pyout'] or {'data':{}} | |
122 | return pyout.get("image/jpeg") |
|
122 | return pyout['data'].get("image/jpeg") | |
123 |
|
123 | |||
124 | def _repr_svg_(self): |
|
124 | def _repr_svg_(self): | |
125 | pyout = self.metadata['pyout'] or {} |
|
125 | pyout = self.metadata['pyout'] or {'data':{}} | |
126 | return pyout.get("image/svg+xml") |
|
126 | return pyout['data'].get("image/svg+xml") | |
127 |
|
127 | |||
128 |
|
128 | |||
129 | class Metadata(dict): |
|
129 | class Metadata(dict): | |
@@ -834,9 +834,9 b' class Client(HasTraits):' | |||||
834 | elif msg_type == 'pyin': |
|
834 | elif msg_type == 'pyin': | |
835 | md.update({'pyin' : content['code']}) |
|
835 | md.update({'pyin' : content['code']}) | |
836 | elif msg_type == 'display_data': |
|
836 | elif msg_type == 'display_data': | |
837 |
md['outputs'].append(content |
|
837 | md['outputs'].append(content) | |
838 | elif msg_type == 'pyout': |
|
838 | elif msg_type == 'pyout': | |
839 |
md['pyout'] = content |
|
839 | md['pyout'] = content | |
840 | else: |
|
840 | else: | |
841 | # unhandled msg_type (status, etc.) |
|
841 | # unhandled msg_type (status, etc.) | |
842 | pass |
|
842 | pass |
@@ -593,7 +593,7 b' class TestView(ClusterTestCase, ParametricTestCase):' | |||||
593 | er = ar.get() |
|
593 | er = ar.get() | |
594 | self._wait_for(lambda : bool(er.pyout)) |
|
594 | self._wait_for(lambda : bool(er.pyout)) | |
595 | self.assertEquals(str(er), "<ExecuteReply[%i]: 5>" % er.execution_count) |
|
595 | self.assertEquals(str(er), "<ExecuteReply[%i]: 5>" % er.execution_count) | |
596 | self.assertEquals(er.pyout['text/plain'], '5') |
|
596 | self.assertEquals(er.pyout['data']['text/plain'], '5') | |
597 |
|
597 | |||
598 | def test_execute_reply_stdout(self): |
|
598 | def test_execute_reply_stdout(self): | |
599 | e0 = self.client[self.client.ids[0]] |
|
599 | e0 = self.client[self.client.ids[0]] | |
@@ -610,7 +610,8 b' class TestView(ClusterTestCase, ParametricTestCase):' | |||||
610 | self._wait_for(lambda : all(ar.pyout)) |
|
610 | self._wait_for(lambda : all(ar.pyout)) | |
611 |
|
611 | |||
612 | expected = [{'text/plain' : '5'}] * len(view) |
|
612 | expected = [{'text/plain' : '5'}] * len(view) | |
613 | self.assertEquals(ar.pyout, expected) |
|
613 | mimes = [ out['data'] for out in ar.pyout ] | |
|
614 | self.assertEquals(mimes, expected) | |||
614 |
|
615 | |||
615 | def test_execute_silent(self): |
|
616 | def test_execute_silent(self): | |
616 | """execute does not trigger pyout with silent=True""" |
|
617 | """execute does not trigger pyout with silent=True""" | |
@@ -645,9 +646,10 b' class TestView(ClusterTestCase, ParametricTestCase):' | |||||
645 | ar = view.execute("[ display(i) for i in range(5) ]", block=True) |
|
646 | ar = view.execute("[ display(i) for i in range(5) ]", block=True) | |
646 |
|
647 | |||
647 | self._wait_for(lambda : all(len(er.outputs) >= 5 for er in ar)) |
|
648 | self._wait_for(lambda : all(len(er.outputs) >= 5 for er in ar)) | |
648 |
|
|
649 | expected = [ {u'text/plain' : unicode(j)} for j in range(5) ] | |
649 | expected = [outs] * len(view) |
|
650 | for outputs in ar.outputs: | |
650 | self.assertEquals(ar.outputs, expected) |
|
651 | mimes = [ out['data'] for out in outputs ] | |
|
652 | self.assertEquals(mimes, expected) | |||
651 |
|
653 | |||
652 | def test_apply_displaypub(self): |
|
654 | def test_apply_displaypub(self): | |
653 | """apply tracks display_pub output""" |
|
655 | """apply tracks display_pub output""" | |
@@ -661,9 +663,10 b' class TestView(ClusterTestCase, ParametricTestCase):' | |||||
661 | ar = view.apply_async(publish) |
|
663 | ar = view.apply_async(publish) | |
662 | ar.get(5) |
|
664 | ar.get(5) | |
663 | self._wait_for(lambda : all(len(out) >= 5 for out in ar.outputs)) |
|
665 | self._wait_for(lambda : all(len(out) >= 5 for out in ar.outputs)) | |
664 |
|
|
666 | expected = [ {u'text/plain' : unicode(j)} for j in range(5) ] | |
665 | expected = [outs] * len(view) |
|
667 | for outputs in ar.outputs: | |
666 | self.assertEquals(ar.outputs, expected) |
|
668 | mimes = [ out['data'] for out in outputs ] | |
|
669 | self.assertEquals(mimes, expected) | |||
667 |
|
670 | |||
668 | def test_execute_raises(self): |
|
671 | def test_execute_raises(self): | |
669 | """exceptions in execute requests raise appropriately""" |
|
672 | """exceptions in execute requests raise appropriately""" | |
@@ -672,7 +675,7 b' class TestView(ClusterTestCase, ParametricTestCase):' | |||||
672 | self.assertRaisesRemote(ZeroDivisionError, ar.get, 2) |
|
675 | self.assertRaisesRemote(ZeroDivisionError, ar.get, 2) | |
673 |
|
676 | |||
674 | @dec.skipif_not_matplotlib |
|
677 | @dec.skipif_not_matplotlib | |
675 |
def test_ |
|
678 | def test_magic_pylab(self): | |
676 | """%pylab works on engines""" |
|
679 | """%pylab works on engines""" | |
677 | view = self.client[-1] |
|
680 | view = self.client[-1] | |
678 | ar = view.execute("%pylab inline") |
|
681 | ar = view.execute("%pylab inline") | |
@@ -684,6 +687,8 b' class TestView(ClusterTestCase, ParametricTestCase):' | |||||
684 | self._wait_for(lambda : all(ar.outputs)) |
|
687 | self._wait_for(lambda : all(ar.outputs)) | |
685 | self.assertEquals(len(reply.outputs), 1) |
|
688 | self.assertEquals(len(reply.outputs), 1) | |
686 | output = reply.outputs[0] |
|
689 | output = reply.outputs[0] | |
687 |
self.assertTrue(" |
|
690 | self.assertTrue("data" in output) | |
|
691 | data = output['data'] | |||
|
692 | self.assertTrue("image/png" in data) | |||
688 |
|
693 | |||
689 |
|
694 |
General Comments 0
You need to be logged in to leave comments.
Login now