##// END OF EJS Templates
test new execute/output behaviors
MinRK -
Show More
@@ -569,3 +569,89 b' class TestView(ClusterTestCase, ParametricTestCase):'
569 # parametric tests seem to require manual closing?
569 # parametric tests seem to require manual closing?
570 self.client.close()
570 self.client.close()
571
571
572
573 # begin execute tests
574
575 def test_execute_reply(self):
576 e0 = self.client[self.client.ids[0]]
577 e0.block = True
578 ar = e0.execute("5", silent=False)
579 er = ar.get()
580 time.sleep(0.2)
581 self.assertEquals(str(er), "<ExecuteReply[%i]: 5>" % er.execution_count)
582 self.assertEquals(er.pyout['text/plain'], '5')
583
584 def test_execute_reply_stdout(self):
585 e0 = self.client[self.client.ids[0]]
586 e0.block = True
587 ar = e0.execute("print (5)", silent=False)
588 er = ar.get()
589 time.sleep(0.2)
590 self.assertEquals(er.stdout.strip(), '5')
591
592 def test_execute_pyout(self):
593 """execute triggers pyout with silent=False"""
594 view = self.client[:]
595 ar = view.execute("5", silent=False, block=True)
596 time.sleep(0.2)
597 expected = [{'text/plain' : '5'}] * len(view)
598 self.assertEquals(ar.pyout, expected)
599
600 def test_execute_silent(self):
601 """execute does not trigger pyout with silent=True"""
602 view = self.client[:]
603 ar = view.execute("5", block=True)
604 expected = [None] * len(view)
605 self.assertEquals(ar.pyout, expected)
606
607 def test_execute_magic(self):
608 """execute accepts IPython commands"""
609 view = self.client[:]
610 view.execute("a = 5")
611 ar = view.execute("%whos", block=True)
612 # this will raise, if that failed
613 ar.get(5)
614 time.sleep(0.2)
615 for stdout in ar.stdout:
616 lines = stdout.splitlines()
617 self.assertEquals(lines[0].split(), ['Variable', 'Type', 'Data/Info'])
618 found = False
619 for line in lines[2:]:
620 split = line.split()
621 if split == ['a', 'int', '5']:
622 found = True
623 break
624 self.assertTrue(found, "whos output wrong: %s" % stdout)
625
626 def test_execute_displaypub(self):
627 """execute tracks display_pub output"""
628 view = self.client[:]
629 view.execute("from IPython.core.display import *")
630 ar = view.execute("[ display(i) for i in range(5) ]", block=True)
631 time.sleep(0.2)
632 outs = [ {u'text/plain' : unicode(i)} for i in range(5) ]
633 expected = [outs] * len(view)
634 self.assertEquals(ar.outputs, expected)
635
636 def test_apply_displaypub(self):
637 """apply tracks display_pub output"""
638 view = self.client[:]
639 view.execute("from IPython.core.display import *")
640
641 @interactive
642 def publish():
643 [ display(i) for i in range(5) ]
644
645 ar = view.apply_async(publish)
646 ar.get(5)
647 time.sleep(0.2)
648 outs = [ {u'text/plain' : unicode(j)} for j in range(5) ]
649 expected = [outs] * len(view)
650 self.assertEquals(ar.outputs, expected)
651
652 def test_execute_raises(self):
653 """exceptions in execute requests raise appropriately"""
654 view = self.client[-1]
655 ar = view.execute("1/0")
656 self.assertRaisesRemote(ZeroDivisionError, ar.get, 2)
657
General Comments 0
You need to be logged in to leave comments. Login now