def test_print_strict_strio(): f = StringIO() real_write = f.write def strict_write(data): if not isinstance(data, text_type): raise TypeError real_write(data.encode("utf-8").decode("utf-8")) f.write = strict_write print_(b"\xff\xfe".decode(_encoding, "surrogateescape"), file=f) assert f.getvalue() == u"\ufffd\ufffd\n"
def test_print(): f = BytesIO() print_(u"foo", file=f) out = f.getvalue() assert isinstance(out, bytes) assert out == b"foo" + linesepb f = StringIO() print_(u"foo", file=f) out = f.getvalue() assert isinstance(out, str) assert out == "foo" + os.linesep print_(u"foo", file=f, flush=True) f = TextIO() print_(u"foo", file=f) out = f.getvalue() assert isinstance(out, text_type) assert out == u"foo" + linesepu f = TextIO() print_(u"", file=f, end=b"\n") out = f.getvalue() assert isinstance(out, text_type) assert out == linesepu f = BytesIO() print_("", file=f, end=b"\n") out = f.getvalue() assert isinstance(out, bytes) assert out == linesepb
def test_print_bytes(objects, sep, end, flush): h = StringIO() print_(*objects, sep=sep, end=end, flush=flush, file=h) h.getvalue()
def test_print_py3_stringio(): if os.name != "nt" and PY3: f = StringIO() print_(b"\xff\xfe", file=f) assert f.getvalue() == \ b"\xff\xfe\n".decode(_encoding, "surrogateescape")