def test_io_isatty(): session = Session() ctx = zmq.Context() pub = ctx.socket(zmq.PUB) thread = IOPubThread(pub) thread.start() stream = OutStream(session, thread, 'stdout', isatty=True) assert stream.isatty()
def redirect_output(session, pub_socket): """Prevent any of the widgets from permanently hijacking stdout or stderr""" sys.stdout = OutStream(session, pub_socket, u'stdout') sys.stderr = OutStream(session, pub_socket, u'stderr') try: yield finally: sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__
def test_io_api(): """Test that wrapped stdout has the same API as a normal TextIO object""" session = Session() ctx = zmq.Context() pub = ctx.socket(zmq.PUB) thread = IOPubThread(pub) thread.start() stream = OutStream(session, thread, 'stdout') # cleanup unused zmq objects before we start testing thread.stop() thread.close() ctx.term() assert stream.errors is None assert not stream.isatty() with nt.assert_raises(io.UnsupportedOperation): stream.detach() with nt.assert_raises(io.UnsupportedOperation): next(stream) with nt.assert_raises(io.UnsupportedOperation): stream.read() with nt.assert_raises(io.UnsupportedOperation): stream.readline() with nt.assert_raises(io.UnsupportedOperation): stream.seek() with nt.assert_raises(io.UnsupportedOperation): stream.tell()
def test_io_api(): """Test that wrapped stdout has the same API as a normal TextIO object""" session = Session() ctx = zmq.Context() pub = ctx.socket(zmq.PUB) thread = IOPubThread(pub) thread.start() stream = OutStream(session, thread, 'stdout') # cleanup unused zmq objects before we start testing thread.stop() thread.close() ctx.term() assert stream.errors is None assert not stream.isatty() with pytest.raises(io.UnsupportedOperation): stream.detach() with pytest.raises(io.UnsupportedOperation): next(stream) with pytest.raises(io.UnsupportedOperation): stream.read() with pytest.raises(io.UnsupportedOperation): stream.readline() with pytest.raises(io.UnsupportedOperation): stream.seek(0) with pytest.raises(io.UnsupportedOperation): stream.tell() with pytest.raises(TypeError): stream.write(b'')
def __init__(self, process_stream, session, socket, name): self._process_stream = process_stream self._thread_stream = OutStream(session, socket, name) self._thread_id = threading.currentThread().ident
def _stderr_default(self): from ipykernel.iostream import OutStream return OutStream(self.session, self.iopub_socket, u'stderr', pipe=False)