예제 #1
0
def test_str_to_bytes_raises_on_non_base32_decode_char(ascii_non_base32_str_valid_length):
    """
    Assert that :func:`~ulid.base32.str_to_bytes` 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.str_to_bytes(ascii_non_base32_str_valid_length, len(ascii_non_base32_str_valid_length))
    ex.match(NON_BASE_32_EXC_REGEX)
예제 #2
0
def test_str_to_bytes_raises_on_extended_ascii_str(extended_ascii_str_valid_length):
    """
    Assert that :func:`~ulid.base32.str_to_bytes` raises a :class:`~ValueError` when given a :class:`~str`
    instance that includes extended ascii characters.
    """
    with pytest.raises(ValueError) as ex:
        base32.str_to_bytes(extended_ascii_str_valid_length, len(extended_ascii_str_valid_length))
    assert ex.match(NON_ASCII_EXC_REGEX)
예제 #3
0
def test_str_to_bytes_raises_on_unexpected_length(invalid_str_26):
    """
    Assert that :func:`~ulid.base32.str_to_bytes` raises a :class:`~ValueError` when given a :class:`~str`
    instance that does not match the expected length.
    """
    with pytest.raises(ValueError) as ex:
        base32.str_to_bytes(invalid_str_26, 26)
    assert ex.match(DECODE_ULID_STR_LEN_EXC_REGEX)
예제 #4
0
def test_str_to_bytes_raises_on_timestamp_msb_overflow(
        invalid_str_10_msb_invalid):
    """
    Assert that :func:`~ulid.base32.str_to_bytes` raises a :class:`~ValueError` when given a :class:`~str`
    instance that includes a valid length timestamp but MSB too large causing an overflow.
    """
    with pytest.raises(ValueError) as ex:
        base32.str_to_bytes(invalid_str_10_msb_invalid,
                            len(invalid_str_10_msb_invalid))
    ex.match(TIMESTAMP_OVERFLOW_EXC_REGEX)
예제 #5
0
def test_str_to_bytes_returns_expected_bytes(valid_str_valid_length):
    """
    Assert that :func:`~ulid.base32.str_to_bytes` decodes a valid string that is 10, 16, or 26 characters long
    into a :class:`~bytes` instance.
    """
    decoded = base32.str_to_bytes(valid_str_valid_length, len(valid_str_valid_length))
    assert isinstance(decoded, bytes)
    assert len(decoded) == len(valid_str_valid_length)