示例#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.TextIO()
         sys.stderr = capture.TextIO()
         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
示例#2
0
 def test_unicode_and_str_mixture(self):
     f = capture.TextIO()
     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)
示例#3
0
 def test_text(self):
     f = capture.TextIO()
     f.write("hello")
     s = f.getvalue()
     assert s == "hello"
     f.close()