Show More
@@ -50,7 +50,7 b' class RedirectorOutputTrap(OutputTrap):' | |||||
50 | """ Set the hooks: set the redirectors and call the base class. |
|
50 | """ Set the hooks: set the redirectors and call the base class. | |
51 | """ |
|
51 | """ | |
52 | self.out_redirector.start() |
|
52 | self.out_redirector.start() | |
53 |
|
|
53 | self.err_redirector.start() | |
54 | OutputTrap.set(self) |
|
54 | OutputTrap.set(self) | |
55 |
|
55 | |||
56 |
|
56 | |||
@@ -60,9 +60,9 b' class RedirectorOutputTrap(OutputTrap):' | |||||
60 | """ |
|
60 | """ | |
61 | OutputTrap.unset(self) |
|
61 | OutputTrap.unset(self) | |
62 | # Flush the redirectors before stopping them |
|
62 | # Flush the redirectors before stopping them | |
63 | self.on_out_write('') |
|
|||
64 | self.err_redirector.stop() |
|
|||
65 | self.on_err_write('') |
|
63 | self.on_err_write('') | |
|
64 | self.err_redirector.stop() | |||
|
65 | self.on_out_write('') | |||
66 | self.out_redirector.stop() |
|
66 | self.out_redirector.stop() | |
67 |
|
67 | |||
68 |
|
68 |
@@ -1,14 +1,31 b'' | |||||
|
1 | # encoding: utf-8 | |||
|
2 | ||||
1 | """ |
|
3 | """ | |
2 | Test the output capture at the OS level, using file descriptors. |
|
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 | import os |
|
17 | import os | |
6 | from cStringIO import StringIO |
|
18 | from cStringIO import StringIO | |
|
19 | import sys | |||
7 |
|
20 | |||
8 |
|
21 | |||
9 | def test_redirector(): |
|
22 | def test_redirector(): | |
10 | """ Checks that the redirector can be used to do synchronous capture. |
|
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 | from IPython.kernel.core.fd_redirector import FDRedirector |
|
29 | from IPython.kernel.core.fd_redirector import FDRedirector | |
13 | r = FDRedirector() |
|
30 | r = FDRedirector() | |
14 | out = StringIO() |
|
31 | out = StringIO() | |
@@ -23,13 +40,19 b' def test_redirector():' | |||||
23 | raise |
|
40 | raise | |
24 | r.stop() |
|
41 | r.stop() | |
25 | assert out.getvalue() == "".join("%ic\n%i\n" %(i, i) for i in range(10)) |
|
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 | def test_redirector_output_trap(): |
|
47 | def test_redirector_output_trap(): | |
29 | """ This test check not only that the redirector_output_trap does |
|
48 | """ This test check not only that the redirector_output_trap does | |
30 | trap the output, but also that it does it in a gready way, that |
|
49 | trap the output, but also that it does it in a gready way, that | |
31 |
is by calling the call |
|
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 | from IPython.kernel.core.redirector_output_trap import RedirectorOutputTrap |
|
56 | from IPython.kernel.core.redirector_output_trap import RedirectorOutputTrap | |
34 | out = StringIO() |
|
57 | out = StringIO() | |
35 | trap = RedirectorOutputTrap(out.write, out.write) |
|
58 | trap = RedirectorOutputTrap(out.write, out.write) | |
@@ -43,8 +66,16 b' def test_redirector_output_trap():' | |||||
43 | trap.unset() |
|
66 | trap.unset() | |
44 | raise |
|
67 | raise | |
45 | trap.unset() |
|
68 | trap.unset() | |
|
69 | sys.stdout.flush() | |||
|
70 | sys.stderr.flush() | |||
46 | assert out.getvalue() == "".join("%ic\n%ip\n%i\n" %(i, i, i) |
|
71 | assert out.getvalue() == "".join("%ic\n%ip\n%i\n" %(i, i, i) | |
47 | for i in range(10)) |
|
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