def test_utf8_encode_ascii(): assert utf8_encode_ascii("abc", "??", "??") == "abc" def eh(errors, encoding, reason, p, start, end): lst.append((errors, encoding, p, start, end)) return "<FOO>", end lst = [] input = u"\u1234".encode("utf8") assert utf8_encode_ascii(input, "??", eh) == "<FOO>" assert lst == [("??", "ascii", input, 0, 1)] lst = [] input = u"\u1234\u5678abc\u8765\u4321".encode("utf8") assert utf8_encode_ascii(input, "??", eh) == "<FOO>abc<FOO>" assert lst == [("??", "ascii", input, 0, 2), ("??", "ascii", input, 5, 7)]
def test_utf8_encode_ascii_2(u): def eh(errors, encoding, reason, p, start, end): return "?" * (end - start), end assert utf8_encode_ascii(u.encode("utf8"), "replace", eh) == u.encode("ascii", "replace")