Exemple #1
0
 def test_capturing_modify_sysouterr_in_between(self):
     oldout = sys.stdout
     olderr = sys.stderr
     with self.getcapture() as cap:
         sys.stdout.write("hello")
         sys.stderr.write("world")
         sys.stdout = capture.CaptureIO()
         sys.stderr = capture.CaptureIO()
         print("not seen")
         sys.stderr.write("not seen\n")
         out, err = cap.readouterr()
     assert out == "hello"
     assert err == "world"
     assert sys.stdout == oldout
     assert sys.stderr == olderr
Exemple #2
0
 def test_write_bytes_to_buffer(self):
     """In python3, stdout / stderr are text io wrappers (exposing a buffer
     property of the underlying bytestream).  See issue #1407
     """
     f = capture.CaptureIO()
     f.buffer.write(b'foo\r\n')
     assert f.getvalue() == 'foo\r\n'
Exemple #3
0
 def test_unicode_and_str_mixture(self):
     f = capture.CaptureIO()
     if sys.version_info >= (3, 0):
         f.write("\u00f6")
         pytest.raises(TypeError, "f.write(bytes('hello', 'UTF-8'))")
     else:
         f.write(unicode("\u00f6", 'UTF-8'))
         f.write("hello")  # bytes
         s = f.getvalue()
         f.close()
         assert isinstance(s, unicode)
Exemple #4
0
 def test_unicode_and_str_mixture(self):
     f = capture.CaptureIO()
     if sys.version_info >= (3, 0):
         f.write("\u00f6")
         pytest.raises(TypeError, f.write, b"hello")
     else:
         f.write(u"\u00f6")
         f.write(b"hello")
         s = f.getvalue()
         f.close()
         assert isinstance(s, text_type)
Exemple #5
0
 def test_text(self):
     f = capture.CaptureIO()
     f.write("hello")
     s = f.getvalue()
     assert s == "hello"
     f.close()
Exemple #6
0
 def test_unicode_and_str_mixture(self):
     f = capture.CaptureIO()
     f.write("\u00f6")
     pytest.raises(TypeError, f.write, b"hello")