io_test.py 584 B

12345678910111213141516171819202122232425
  1. import sys
  2. import pytest
  3. import cipy._io
  4. def test_capture_cout() -> None:
  5. with cipy._io.capture_stdout() as out:
  6. print("Hello, World")
  7. sys.stdout.flush()
  8. assert out.getvalue() == "Hello, World\n"
  9. def test_capture_cerr() -> None:
  10. with cipy._io.capture_stderr() as out:
  11. print("Hello, World", file=sys.stderr)
  12. sys.stderr.flush()
  13. assert out.getvalue() == "Hello, World\n"
  14. def test_capture_expires_scope() -> None:
  15. with cipy._io.capture_stdout() as out:
  16. pass
  17. with pytest.raises(ValueError):
  18. out.read()