def test_parse_raises_when_float_negative(): """ Assert that :func:`~ulid.api.parse` raises a :class:`~ValueError` when given a negative float number. """ with pytest.raises(ValueError) as ex: api.parse(float(-1)) assert ex.match(INT_NEGATIVE_EXC_REGEX)
def test_parse_raises_when_given_unsupported_type(unsupported_type): """ Assert that :func:`~ulid.api.parse` raises a :class:`~ValueError` when a value of an unsupported type. """ with pytest.raises(ValueError) as ex: api.parse(unsupported_type) assert ex.match(PARSE_UNSUPPORTED_TYPE_REGEX)
def test_parse_error_on_invalid_length_str(invalid_str_10_16_26_32_36): """ Assert that :func:`~ulid.api.parse` returns a new :class:`~ulid.ulid.ULID` instance from the given :class:`~str` instance that represents timestamp data. """ with pytest.raises(ValueError) as ex: api.parse(invalid_str_10_16_26_32_36) assert ex.match(PARSE_STR_LEN_EXC_REGEX)
def test_parse_raises_when_buffer_type_not_128_bits(buffer_type, invalid_bytes_128): """ Assert that :func:`~ulid.api.parse` raises a :class:`~ValueError` when given bytes that is not 128 bit in length. """ value = buffer_type(invalid_bytes_128) with pytest.raises(ValueError) as ex: api.parse(value) assert ex.match(BYTES_SIZE_EXC_REGEX)
def test_parse_raises_when_float_greater_than_128_bits( invalid_bytes_128_overflow): """ Assert that :func:`~ulid.api.parse` raises a :class:`~ValueError` when given float cannot be stored in 128 bits. """ value = float(int.from_bytes(invalid_bytes_128_overflow, byteorder='big')) with pytest.raises(ValueError) as ex: api.parse(value) assert ex.match(INT_SIZE_EXC_REGEX)
def test_parse_returns_ulid_instance_from_ulid_str(valid_bytes_128): """ Assert that :func:`~ulid.api.parse` returns a new :class:`~ulid.ulid.ULID` instance from the given :class:`~str` instance that represents a fill ULID. """ value = base32.encode(valid_bytes_128) instance = api.parse(value) assert isinstance(instance, ulid.ULID) assert instance.bytes == valid_bytes_128
def test_parse_returns_ulid_instance_from_uuid_hex_str(): """ Assert that :func:`~ulid.api.parse` returns a new :class:`~ulid.ulid.ULID` instance from the given :class:`~uuid.UUID` instance in its hex string format. """ value = uuid.uuid4() instance = api.parse(value.hex) assert isinstance(instance, ulid.ULID) assert instance.bytes == value.bytes
def test_parse_returns_given_ulid_instance(): """ Assert that :func:`~ulid.api.parse` returns the given :class:`~ulid.ulid.ULID` instance when given one. """ value = api.new() instance = api.parse(value) assert isinstance(instance, ulid.ULID) assert instance == value
def test_parse_returns_ulid_instance_from_float(valid_bytes_128): """ Assert that :func:`~ulid.api.parse` returns a new :class:`~ulid.ulid.ULID` instance from a valid ULID stored as a float. """ value = float(int.from_bytes(valid_bytes_128, byteorder='big')) instance = api.parse(value) assert isinstance(instance, ulid.ULID) assert instance.int == int(value)
def test_parse_returns_ulid_instance_from_timestamp_str(valid_bytes_48): """ Assert that :func:`~ulid.api.parse` returns a new :class:`~ulid.ulid.ULID` instance from the given :class:`~str` instance that represents timestamp data. """ value = base32.encode_timestamp(valid_bytes_48) instance = api.parse(value) assert isinstance(instance, ulid.ULID) assert instance.timestamp().str == value
def test_parse_returns_ulid_instance_from_randomness_str(valid_bytes_80): """ Assert that :func:`~ulid.api.parse` returns a new :class:`~ulid.ulid.ULID` instance from the given :class:`~str` instance that represents randomness data. """ value = base32.encode_randomness(valid_bytes_80) instance = api.parse(value) assert isinstance(instance, ulid.ULID) assert instance.randomness().str == value
def test_parse_returns_ulid_instance_from_buffer_type(buffer_type, valid_bytes_128): """ Assert that :func:`~ulid.api.parse` returns a new :class:`~ulid.ulid.ULID` instance from a valid set of 128 bytes representing by the given buffer type. """ value = buffer_type(valid_bytes_128) instance = api.parse(value) assert isinstance(instance, ulid.ULID) assert instance.bytes == valid_bytes_128