Files
RustPython/extra_tests/snippets/builtin_str_encode.py
2022-05-04 02:54:59 +09:00

21 lines
584 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from testutils import assert_raises
try:
b" \xff".decode("ascii")
except UnicodeDecodeError as e:
assert e.start == 3
assert e.end == 4
else:
assert False, "should have thrown UnicodeDecodeError"
assert_raises(UnicodeEncodeError, "¿como estás?".encode, "ascii")
def round_trip(s, encoding="utf-8"):
encoded = s.encode(encoding)
decoded = encoded.decode(encoding)
assert s == decoded
round_trip("πŸ‘Ίβ™¦ πšΕžΔ‘Ζ’ β˜†β˜")
round_trip("☒🐣 α–‡π“€π•ŠΡ‚β“Ÿπ•π•₯卄σ𝔫 β™¬πŸ‘£")
round_trip("πŸ’€πŸ‘Œ ק𝔂tβ„β“žπ“· οΌ“ πŸ”₯πŸ‘€")