def test_redirector_output_trap(): """ This test check not only that the redirector_output_trap does trap the output, but also that it does it in a gready way, that is by calling the callback ASAP. """ from IPython.kernel.core.redirector_output_trap import RedirectorOutputTrap out = StringIO() trap = RedirectorOutputTrap(out.write, out.write) try: trap.set() for i in range(10): os.system('echo %ic' % i) print "%ip" % i print >>out, i except: trap.unset() raise trap.unset() result1 = out.getvalue() result2 = "".join("%ic\n%ip\n%i\n" %(i, i, i) for i in range(10)) assert result1 == result2
def test_redirector_output_trap(): """ This test check not only that the redirector_output_trap does trap the output, but also that it does it in a gready way, that is by calling the callback ASAP. """ from IPython.kernel.core.redirector_output_trap import RedirectorOutputTrap out = StringIO() trap = RedirectorOutputTrap(out.write, out.write) try: trap.set() for i in range(10): os.system('echo %ic' % i) print "%ip" % i print >> out, i except: trap.unset() raise trap.unset() result1 = out.getvalue() result2 = "".join("%ic\n%ip\n%i\n" % (i, i, i) for i in range(10)) assert result1 == result2
def test_redirector_output_trap(self): """Check the greedy trapping behavior of the traps. This test check not only that the redirector_output_trap does trap the output, but also that it does it in a gready way, that is by calling the callback ASAP. """ from IPython.kernel.core.redirector_output_trap import RedirectorOutputTrap out = StringIO() trap = RedirectorOutputTrap(out.write, out.write) try: trap.set() for i in range(10): os.system("echo %ic" % i) print("%ip" % i) print(i, file=out) except: trap.unset() raise trap.unset() result1 = out.getvalue() result2 = "".join("%ic\n%ip\n%i\n" % (i, i, i) for i in range(10)) self.assertEquals(result1, result2)