##// END OF EJS Templates
add missing Normal on NoColors...
add missing Normal on NoColors closes #1963

File last commit:

r7324:c0cdaa33
r7580:69276604
Show More
test_io.py
85 lines | 2.7 KiB | text/x-python | PythonLexer
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 # encoding: utf-8
"""Tests for io.py"""
#-----------------------------------------------------------------------------
Matthias BUSSONNIER
update copyright to 2011/20xx-2011...
r5390 # Copyright (C) 2008-2011 The IPython Development Team
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 #
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import sys
MinRK
always use StringIO, never cStringIO...
r4794 from StringIO import StringIO
MinRK
io.Term.cin/out/err replaced by io.stdin/out/err...
r3800 from subprocess import Popen, PIPE
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
import nose.tools as nt
from IPython.testing import decorators as dec
MinRK
move capture_output util from parallel tests to utils.io
r7324 from IPython.utils.io import Tee, capture_output
Thomas Kluyver
Various fixes to tests in IPython.utils.
r4891 from IPython.utils.py3compat import doctest_refactor_print
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
#-----------------------------------------------------------------------------
# Tests
#-----------------------------------------------------------------------------
def test_tee_simple():
"Very simple check with stdout only"
chan = StringIO()
text = 'Hello'
tee = Tee(chan, channel='stdout')
Thomas Kluyver
Various fixes to tests in IPython.utils.
r4891 print >> chan, text
nt.assert_equal(chan.getvalue(), text+"\n")
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
class TeeTestCase(dec.ParametricTestCase):
def tchan(self, channel, check='close'):
trap = StringIO()
chan = StringIO()
text = 'Hello'
std_ori = getattr(sys, channel)
setattr(sys, channel, trap)
tee = Tee(chan, channel=channel)
print >> chan, text,
setattr(sys, channel, std_ori)
trap_val = trap.getvalue()
nt.assert_equals(chan.getvalue(), text)
if check=='close':
tee.close()
else:
del tee
def test(self):
for chan in ['stdout', 'stderr']:
for check in ['close', 'del']:
yield self.tchan(chan, check)
MinRK
io.Term.cin/out/err replaced by io.stdin/out/err...
r3800
def test_io_init():
"""Test that io.stdin/out/err exist at startup"""
for name in ('stdin', 'stdout', 'stderr'):
Thomas Kluyver
Various fixes to tests in IPython.utils.
r4891 cmd = doctest_refactor_print("from IPython.utils import io;print io.%s.__class__"%name)
p = Popen([sys.executable, '-c', cmd],
MinRK
io.Term.cin/out/err replaced by io.stdin/out/err...
r3800 stdout=PIPE)
p.wait()
Thomas Kluyver
Various fixes to tests in IPython.utils.
r4891 classname = p.stdout.read().strip().decode('ascii')
# __class__ is a reference to the class object in Python 3, so we can't
# just test for string equality.
assert 'IPython.utils.io.IOStream' in classname, classname
MinRK
move capture_output util from parallel tests to utils.io
r7324
def test_capture_output():
"""capture_output() context works"""
with capture_output() as io:
print 'hi, stdout'
print >> sys.stderr, 'hi, stderr'
nt.assert_equals(io.stdout, 'hi, stdout\n')
nt.assert_equals(io.stderr, 'hi, stderr\n')