test_io.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """Test IO capturing functionality"""
  2. import io
  3. import zmq
  4. from jupyter_client.session import Session
  5. from ipykernel.iostream import IOPubThread, OutStream
  6. import nose.tools as nt
  7. def test_io_api():
  8. """Test that wrapped stdout has the same API as a normal TextIO object"""
  9. session = Session()
  10. ctx = zmq.Context()
  11. pub = ctx.socket(zmq.PUB)
  12. thread = IOPubThread(pub)
  13. thread.start()
  14. stream = OutStream(session, thread, 'stdout')
  15. # cleanup unused zmq objects before we start testing
  16. thread.stop()
  17. thread.close()
  18. ctx.term()
  19. assert stream.errors is None
  20. assert not stream.isatty()
  21. with nt.assert_raises(io.UnsupportedOperation):
  22. stream.detach()
  23. with nt.assert_raises(io.UnsupportedOperation):
  24. next(stream)
  25. with nt.assert_raises(io.UnsupportedOperation):
  26. stream.read()
  27. with nt.assert_raises(io.UnsupportedOperation):
  28. stream.readline()
  29. with nt.assert_raises(io.UnsupportedOperation):
  30. stream.seek()
  31. with nt.assert_raises(io.UnsupportedOperation):
  32. stream.tell()