Beispiel #1
0
def test_decode_randomness_with_incorrect_size_bytes_raises(valid_bytes_128):
    """
    Assert that :func:`~ulid.codec.decode_randomness` raises a :class:`~ValueError` when given
    a type that cannot be represented as exactly 80 bits.
    """
    with pytest.raises(ValueError) as ex:
        codec.decode_randomness(valid_bytes_128)
    assert ex.match(RANDOMNESS_SIZE_EXC_REGEX)
Beispiel #2
0
def test_decode_randomness_with_unsupported_type_raises(unsupported_type):
    """
    Assert that :func:`~ulid.codec.decode_randomness` raises a :class:`~ValueError` when given
    a type it cannot compute a randomness value from.
    """
    with pytest.raises(ValueError) as ex:
        codec.decode_randomness(unsupported_type())
    assert ex.match(UNSUPPORTED_RANDOMNESS_TYPE_EXC_REGEX)
Beispiel #3
0
def test_decode_randomness_ulid_returns_randomness_instance(valid_bytes_128):
    """
    Assert that :func:`~ulid.codec.decode_randomness` returns a new :class:`~ulid.ulid.Randomness` instance
    from the given random values as a :class:`~ulid.ulid.ULID`.
    """
    value = ulid.ULID(valid_bytes_128)
    instance = codec.decode_randomness(value)
    assert isinstance(instance, ulid.Randomness)
    assert instance == value.randomness()
Beispiel #4
0
def test_decode_randomness_str_returns_randomness_instance(valid_bytes_80):
    """
    Assert that :func:`~ulid.codec.decode_randomness` returns a new :class:`~ulid.ulid.Randomness` instance
    from the given random values as an :class:`~str`.
    """
    value = base32.encode_randomness(valid_bytes_80)
    instance = codec.decode_randomness(value)
    assert isinstance(instance, ulid.Randomness)
    assert instance.str == value
Beispiel #5
0
def test_decode_randomness_float_returns_randomness_instance(valid_bytes_80):
    """
    Assert that :func:`~ulid.codec.decode_randomness` returns a new :class:`~ulid.ulid.Randomness` instance
    from the given random values as an :class:`~float`.
    """
    value = float(int.from_bytes(valid_bytes_80, byteorder='big'))
    instance = codec.decode_randomness(value)
    assert isinstance(instance, ulid.Randomness)
    assert instance.int == int(value)
Beispiel #6
0
def test_decode_randomness_bytes_returns_randomness_instance(
        buffer_type, valid_bytes_80):
    """
    Assert that :func:`~ulid.codec.decode_randomness` returns a new :class:`~ulid.ulid.Randomness` instance
    from the given random values as an object that supports the buffer protocol.
    """
    value = buffer_type(valid_bytes_80)
    instance = codec.decode_randomness(value)
    assert isinstance(instance, ulid.Randomness)
    assert instance.bytes == value