def as_ascii(s): """ Function to decode an input with the ASCII codec, or return as-is. Parameters ---------- s: Any object. Returns ------- output: If the input was of type `bytes`, the return value is a `str` decoded with the ASCII codec. Otherwise, the return value is identically the input. See Also -------- decoder """ return _do_decoding(s, 'ascii')
def test_do_decoding_decodes_bytes_string_to_unicode(): assert type(_do_decoding(b'bytes', 'ascii')) is py23_str assert _do_decoding(b'bytes', 'ascii') == 'bytes' assert _do_decoding(b'bytes', 'ascii') == b'bytes'.decode('ascii')