##// END OF EJS Templates
Merge pull request #13206 from sgaist/nose_cleanup_first_step...
Merge pull request #13206 from sgaist/nose_cleanup_first_step Nose cleanup first step

File last commit:

r26920:c8161eb2
r26949:24290cb1 merge
Show More
test_io.py
87 lines | 2.5 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"""
Min RK
preserve umask in atomic_writing...
r19932 # Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
import sys
Srinivas Reddy Thatiparthy
Remove PY3 variable
r23108 from io import StringIO
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
MinRK
io.Term.cin/out/err replaced by io.stdin/out/err...
r3800 from subprocess import Popen, PIPE
Thomas Kluyver
Remove most uses of ParametricTestCase
r12372 import unittest
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
Christopher Welborn
IOStream: Ignore missing attrs from `dir()`. #6386...
r23229 from IPython.utils.io import IOStream, Tee, capture_output
Thomas Kluyver
Use StringIO.StringIO on Python 2....
r13366
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
def test_tee_simple():
"Very simple check with stdout only"
chan = StringIO()
text = 'Hello'
tee = Tee(chan, channel='stdout')
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print(text, file=chan)
Samuel Gaist
[utils][tests][io] Remove nose
r26920 assert chan.getvalue() == text + "\n"
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
Thomas Kluyver
Remove most uses of ParametricTestCase
r12372 class TeeTestCase(unittest.TestCase):
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
Matthias Bussonnier
Properly cleanup Tee, which reveals some resource leakage....
r25056 def tchan(self, channel):
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 trap = StringIO()
chan = StringIO()
text = 'Hello'
std_ori = getattr(sys, channel)
setattr(sys, channel, trap)
tee = Tee(chan, channel=channel)
Matthias Bussonnier
Properly cleanup Tee, which reveals some resource leakage....
r25056
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print(text, end='', file=chan)
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 trap_val = trap.getvalue()
Samuel Gaist
[utils][tests][io] Remove nose
r26920 self.assertEqual(chan.getvalue(), text)
Matthias Bussonnier
Properly cleanup Tee, which reveals some resource leakage....
r25056
tee.close()
setattr(sys, channel, std_ori)
assert getattr(sys, channel) == std_ori
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
def test(self):
for chan in ['stdout', 'stderr']:
Matthias Bussonnier
Properly cleanup Tee, which reveals some resource leakage....
r25056 self.tchan(chan)
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'):
Matthias Bussonnier
remove some py3compat usage
r24265 cmd = "from IPython.utils import io;print(io.%s.__class__)"%name
Matthias Bussonnier
Properly cleanup Tee, which reveals some resource leakage....
r25056 with Popen([sys.executable, '-c', cmd], stdout=PIPE) as p:
p.wait()
classname = p.stdout.read().strip().decode('ascii')
Thomas Kluyver
Various fixes to tests in IPython.utils.
r4891 # __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
Matthias Bussonnier
Use proper xunit format for some test....
r25109 class TestIOStream(unittest.TestCase):
def test_IOStream_init(self):
"""IOStream initializes from a file-like object missing attributes. """
# Cause a failure from getattr and dir(). (Issue #6386)
class BadStringIO(StringIO):
def __dir__(self):
attrs = super().__dir__()
attrs.append('name')
return attrs
with self.assertWarns(DeprecationWarning):
iostream = IOStream(BadStringIO())
iostream.write('hi, bad iostream\n')
assert not hasattr(iostream, 'name')
iostream.close()
def test_capture_output(self):
"""capture_output() context works"""
with capture_output() as io:
Samuel Gaist
[utils][tests][io] Remove nose
r26920 print("hi, stdout")
print("hi, stderr", file=sys.stderr)
self.assertEqual(io.stdout, "hi, stdout\n")
self.assertEqual(io.stderr, "hi, stderr\n")