def test_value_error_end_of_string(unquoted): """ Test that we get errors for invalid hex escapes at the end of the string. """ s = quote(unquoted) bad_string = s + "%" with pytest.raises(ValueError) as exc_info: decode(bad_string) # Expect a message with the index of the error in it. expected = "invalid percent-encoded triplet at index {:d}".format(len(s)) assert expected == str(exc_info.value)
def test_overlong_forms(): """ Test UTF-8 overlong forms. An easy way to sneak in ␀ when you're not expecting it, so we should throw a decoding error. """ with pytest.raises(UnicodeDecodeError): decode("%C0%80") with pytest.raises(UnicodeDecodeError): decode("%E0%80%80") with pytest.raises(UnicodeDecodeError): decode("%F0%80%80%80")
def test_full_unicode_range(s): "Some printable ASCII characters should be quoted." assert s == decode(quote(s))
def test_decode_nul(): "Test decoding the ␀ character." assert "\x00" == decode("%00")
def test_bad_pct_escape(): "Tests an invalid percent escape." s = "hello%2gworld" with pytest.raises(ValueError): decode(s)
def test_ascii_printable(s): "Some printable ASCII characters should be quoted." assert s == decode(quote(s))
def test_identity_for_alphanumerics(s): "Alphanumerics should be returned verbatim." assert s == decode(s)