##// END OF EJS Templates
BUG: redirector_output_trap was not closing properly the stdout.
gvaroquaux -
Show More
@@ -50,7 +50,7 b' class RedirectorOutputTrap(OutputTrap):'
50 50 """ Set the hooks: set the redirectors and call the base class.
51 51 """
52 52 self.out_redirector.start()
53 #self.err_redirector.start()
53 self.err_redirector.start()
54 54 OutputTrap.set(self)
55 55
56 56
@@ -60,9 +60,9 b' class RedirectorOutputTrap(OutputTrap):'
60 60 """
61 61 OutputTrap.unset(self)
62 62 # Flush the redirectors before stopping them
63 self.on_out_write('')
64 self.err_redirector.stop()
65 63 self.on_err_write('')
64 self.err_redirector.stop()
65 self.on_out_write('')
66 66 self.out_redirector.stop()
67 67
68 68
@@ -1,14 +1,31 b''
1 # encoding: utf-8
2
1 3 """
2 4 Test the output capture at the OS level, using file descriptors.
3 5 """
4 6
7 __docformat__ = "restructuredtext en"
8
9 #---------------------------------------------------------------------------
10 # Copyright (C) 2008 The IPython Development Team
11 #
12 # Distributed under the terms of the BSD License. The full license is in
13 # the file COPYING, distributed as part of this software.
14 #---------------------------------------------------------------------------
15
16
5 17 import os
6 18 from cStringIO import StringIO
19 import sys
7 20
8 21
9 22 def test_redirector():
10 23 """ Checks that the redirector can be used to do synchronous capture.
11 24 """
25 # Flush the stdout, so as not to have side effects between
26 # tests.
27 sys.stdout.flush()
28 sys.stderr.flush()
12 29 from IPython.kernel.core.fd_redirector import FDRedirector
13 30 r = FDRedirector()
14 31 out = StringIO()
@@ -23,13 +40,19 b' def test_redirector():'
23 40 raise
24 41 r.stop()
25 42 assert out.getvalue() == "".join("%ic\n%i\n" %(i, i) for i in range(10))
43 sys.stdout.flush()
44 sys.stderr.flush()
26 45
27 46
28 47 def test_redirector_output_trap():
29 48 """ This test check not only that the redirector_output_trap does
30 49 trap the output, but also that it does it in a gready way, that
31 is by calling the callabck ASAP.
50 is by calling the callback ASAP.
32 51 """
52 # Flush the stdout, so as not to have side effects between
53 # tests.
54 sys.stdout.flush()
55 sys.stderr.flush()
33 56 from IPython.kernel.core.redirector_output_trap import RedirectorOutputTrap
34 57 out = StringIO()
35 58 trap = RedirectorOutputTrap(out.write, out.write)
@@ -43,8 +66,16 b' def test_redirector_output_trap():'
43 66 trap.unset()
44 67 raise
45 68 trap.unset()
69 sys.stdout.flush()
70 sys.stderr.flush()
46 71 assert out.getvalue() == "".join("%ic\n%ip\n%i\n" %(i, i, i)
47 72 for i in range(10))
48 73
49
74
75
76 if __name__ == '__main__':
77 print "Testing redirector...",
78 test_redirector()
79 test_redirector_output_trap()
80 print "Done."
50 81
General Comments 0
You need to be logged in to leave comments. Login now