def test_encode_timestamp_raises_on_bytes_length_mismatch(invalid_bytes_48): """ Assert that :func:`~ulid.base32.encode_timestamp` raises a :class:`~ValueError` when given a :class:`~bytes` instance that is not exactly 48 bit. """ with pytest.raises(ValueError) as ex: base32.encode_timestamp(invalid_bytes_48) assert ex.match(ENCODE_TIMESTAMP_BYTE_SIZE_EXC_REGEX)
def test_encode_timestamp_returns_10_char_string(valid_bytes_48): """ Assert that :func:`~ulid.base32.encode_timestamp` encodes a valid 48 bit bytes object into a :class:`~str` that is 10 characters long. """ encoded = base32.encode_timestamp(valid_bytes_48) assert isinstance(encoded, str) assert len(encoded) == 10
def test_decode_timestamp_str_returns_timestamp_instance(valid_bytes_48): """ Assert that :func:`~ulid.codec.decode_timestamp` returns a new :class:`~ulid.ulid.Timestamp` instance from the given timestamp as a :class:`~str`. """ value = base32.encode_timestamp(valid_bytes_48) instance = codec.decode_timestamp(value) assert isinstance(instance, ulid.Timestamp) assert instance.str == value
def test_from_timestamp_str_returns_ulid_instance(valid_bytes_48): """ Assert that :func:`~ulid.api.from_timestamp` returns a new :class:`~ulid.ulid.ULID` instance from the given timestamp as a :class:`~str`. """ value = base32.encode_timestamp(valid_bytes_48) instance = api.from_timestamp(value) assert isinstance(instance, ulid.ULID) assert instance.timestamp().str == 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