def test_decode_randomness_raises_on_non_base32_decode_char(ascii_non_base32_str_16): """ Assert that :func:`~ulid.base32.decode_randomness` raises a :class:`~ValueError` when given a :class:`~str` instance that includes ASCII characters not part of the Base 32 decoding character set. """ with pytest.raises(ValueError) as ex: base32.decode_randomness(ascii_non_base32_str_16) ex.match(NON_BASE_32_EXC_REGEX)
def test_decode_randomness_raises_on_str_length_mismatch(invalid_str_16): """ Assert that :func:`~ulid.base32.decode_randomness` raises a :class:`~ValueError` when given a :class:`~str` instance that is not exactly 16 chars. """ with pytest.raises(ValueError) as ex: base32.decode_randomness(invalid_str_16) assert ex.match(DECODE_RANDOMNESS_STR_LEN_EXC_REGEX)
def test_decode_randomness_raises_on_non_ascii_str(extended_ascii_str_16): """ Assert that :func:`~ulid.base32.decode_randomness` raises a :class:`~ValueError` when given a :class:`~str` instance that contains extended ascii characters. """ with pytest.raises(ValueError) as ex: base32.decode_randomness(extended_ascii_str_16) assert ex.match(NON_ASCII_EXC_REGEX)
def test_decode_randomness_returns_10_bytes(valid_str_16): """ Assert that :func:`~ulid.base32.decode_randomness` decodes a valid 16 character string into a :class:`~bytes` instance that is 80 bit. """ decoded = base32.decode_randomness(valid_str_16) assert isinstance(decoded, bytes) assert len(decoded) == 10