Project: pygitweb

a00b9e0 from __future__ import annotations
from pygittools import formatting
def test_to_utf8_returns_string_input_unchanged() -> None:
assert formatting.to_utf8("hello") == "hello"
def test_to_utf8_decodes_utf8_bytes_successfully() -> None:
assert formatting.to_utf8("cafe".encode("utf-8")) == "cafe" # noqa: UP012
def test_to_utf8_uses_fallback_encoding_when_utf8_fails() -> None:
assert formatting.to_utf8(b"\xf1") == "ñ"
def test_to_utf8_fallback_decode_uses_replace_for_invalid_bytes() -> None:
original: str = formatting.FALLBACK_ENCODING
formatting.FALLBACK_ENCODING = "ascii"
try:
assert formatting.to_utf8(b"\xffabc") == "\ufffdabc"
finally:
formatting.FALLBACK_ENCODING = original