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_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")