##// END OF EJS Templates
Properly cleanup Tee, which reveals some resource leakage....
Matthias Bussonnier -
Show More
@@ -32,7 +32,7 b' def test_tee_simple():'
32 32
33 33 class TeeTestCase(unittest.TestCase):
34 34
35 def tchan(self, channel, check='close'):
35 def tchan(self, channel):
36 36 trap = StringIO()
37 37 chan = StringIO()
38 38 text = 'Hello'
@@ -41,28 +41,27 b' class TeeTestCase(unittest.TestCase):'
41 41 setattr(sys, channel, trap)
42 42
43 43 tee = Tee(chan, channel=channel)
44
44 45 print(text, end='', file=chan)
45 setattr(sys, channel, std_ori)
46 46 trap_val = trap.getvalue()
47 47 nt.assert_equal(chan.getvalue(), text)
48 if check=='close':
49 tee.close()
50 else:
51 del tee
48
49 tee.close()
50
51 setattr(sys, channel, std_ori)
52 assert getattr(sys, channel) == std_ori
52 53
53 54 def test(self):
54 55 for chan in ['stdout', 'stderr']:
55 for check in ['close', 'del']:
56 self.tchan(chan, check)
56 self.tchan(chan)
57 57
58 58 def test_io_init():
59 59 """Test that io.stdin/out/err exist at startup"""
60 60 for name in ('stdin', 'stdout', 'stderr'):
61 61 cmd = "from IPython.utils import io;print(io.%s.__class__)"%name
62 p = Popen([sys.executable, '-c', cmd],
63 stdout=PIPE)
64 p.wait()
65 classname = p.stdout.read().strip().decode('ascii')
62 with Popen([sys.executable, '-c', cmd], stdout=PIPE) as p:
63 p.wait()
64 classname = p.stdout.read().strip().decode('ascii')
66 65 # __class__ is a reference to the class object in Python 3, so we can't
67 66 # just test for string equality.
68 67 assert 'IPython.utils.io.IOStream' in classname, classname
@@ -79,6 +78,7 b' def test_IOStream_init():'
79 78 iostream = IOStream(BadStringIO())
80 79 iostream.write('hi, bad iostream\n')
81 80 assert not hasattr(iostream, 'name')
81 iostream.close()
82 82
83 83 def test_capture_output():
84 84 """capture_output() context works"""
General Comments 0
You need to be logged in to leave comments. Login now