Show More
@@ -1,77 +1,78 b'' | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | """ |
|
2 | """ | |
3 | Test the output capture at the OS level, using file descriptors. |
|
3 | Test the output capture at the OS level, using file descriptors. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (C) 2008-2009 The IPython Development Team |
|
6 | # Copyright (C) 2008-2009 The IPython Development Team | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the BSD License. The full license is |
|
8 | # Distributed under the terms of the BSD License. The full license is | |
9 | # in the file COPYING, distributed as part of this software. |
|
9 | # in the file COPYING, distributed as part of this software. | |
10 | #----------------------------------------------------------------------------- |
|
10 | #----------------------------------------------------------------------------- | |
11 |
|
11 | |||
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 | # Imports |
|
13 | # Imports | |
14 | #----------------------------------------------------------------------------- |
|
14 | #----------------------------------------------------------------------------- | |
15 |
|
15 | |||
16 | # Tell nose to skip this module |
|
16 | # Tell nose to skip this module | |
17 | __test__ = {} |
|
17 | __test__ = {} | |
18 |
|
18 | |||
19 | from cStringIO import StringIO |
|
19 | from cStringIO import StringIO | |
20 | import os |
|
20 | import os | |
|
21 | import sys | |||
21 |
|
22 | |||
22 | from twisted.trial import unittest |
|
23 | from twisted.trial import unittest | |
23 |
|
24 | |||
24 | from IPython.testing import decorators as dec |
|
|||
25 |
|
||||
26 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
27 | # Tests |
|
26 | # Tests | |
28 | #----------------------------------------------------------------------------- |
|
27 | #----------------------------------------------------------------------------- | |
29 |
|
28 | |||
30 | class TestRedirector(unittest.TestCase): |
|
29 | class TestRedirector(unittest.TestCase): | |
31 |
|
30 | |||
32 | @dec.skip_win32 |
|
31 | if sys.platform == 'win32': | |
|
32 | skip = True | |||
|
33 | ||||
33 | def test_redirector(self): |
|
34 | def test_redirector(self): | |
34 | """Checks that the redirector can be used to do synchronous capture. |
|
35 | """Checks that the redirector can be used to do synchronous capture. | |
35 | """ |
|
36 | """ | |
36 | from IPython.kernel.core.fd_redirector import FDRedirector |
|
37 | from IPython.kernel.core.fd_redirector import FDRedirector | |
37 | r = FDRedirector() |
|
38 | r = FDRedirector() | |
38 | out = StringIO() |
|
39 | out = StringIO() | |
39 | try: |
|
40 | try: | |
40 | r.start() |
|
41 | r.start() | |
41 | for i in range(10): |
|
42 | for i in range(10): | |
42 | os.system('echo %ic' % i) |
|
43 | os.system('echo %ic' % i) | |
43 | print >>out, r.getvalue(), |
|
44 | print >>out, r.getvalue(), | |
44 | print >>out, i |
|
45 | print >>out, i | |
45 | except: |
|
46 | except: | |
46 | r.stop() |
|
47 | r.stop() | |
47 | raise |
|
48 | raise | |
48 | r.stop() |
|
49 | r.stop() | |
49 | result1 = out.getvalue() |
|
50 | result1 = out.getvalue() | |
50 | result2 = "".join("%ic\n%i\n" %(i, i) for i in range(10)) |
|
51 | result2 = "".join("%ic\n%i\n" %(i, i) for i in range(10)) | |
51 | self.assertEquals(result1, result2) |
|
52 | self.assertEquals(result1, result2) | |
52 |
|
53 | |||
53 | @dec.skip_win32 |
|
|||
54 | def test_redirector_output_trap(self): |
|
54 | def test_redirector_output_trap(self): | |
55 | """Check the greedy trapping behavior of the traps. |
|
55 | """Check the greedy trapping behavior of the traps. | |
56 |
|
56 | |||
57 | This test check not only that the redirector_output_trap does |
|
57 | This test check not only that the redirector_output_trap does | |
58 | trap the output, but also that it does it in a gready way, that |
|
58 | trap the output, but also that it does it in a gready way, that | |
59 | is by calling the callback ASAP. |
|
59 | is by calling the callback ASAP. | |
60 | """ |
|
60 | """ | |
61 |
from IPython.kernel.core.redirector_output_trap import |
|
61 | from IPython.kernel.core.redirector_output_trap import \ | |
|
62 | RedirectorOutputTrap | |||
62 | out = StringIO() |
|
63 | out = StringIO() | |
63 | trap = RedirectorOutputTrap(out.write, out.write) |
|
64 | trap = RedirectorOutputTrap(out.write, out.write) | |
64 | try: |
|
65 | try: | |
65 | trap.set() |
|
66 | trap.set() | |
66 | for i in range(10): |
|
67 | for i in range(10): | |
67 | os.system('echo %ic' % i) |
|
68 | os.system('echo %ic' % i) | |
68 | print "%ip" % i |
|
69 | print "%ip" % i | |
69 | print >>out, i |
|
70 | print >>out, i | |
70 | except: |
|
71 | except: | |
71 | trap.unset() |
|
72 | trap.unset() | |
72 | raise |
|
73 | raise | |
73 | trap.unset() |
|
74 | trap.unset() | |
74 | result1 = out.getvalue() |
|
75 | result1 = out.getvalue() | |
75 | result2 = "".join("%ic\n%ip\n%i\n" %(i, i, i) for i in range(10)) |
|
76 | result2 = "".join("%ic\n%ip\n%i\n" %(i, i, i) for i in range(10)) | |
76 | self.assertEquals(result1, result2) |
|
77 | self.assertEquals(result1, result2) | |
77 |
|
78 |
General Comments 0
You need to be logged in to leave comments.
Login now