def test_idempotency(): ulid = ULID() assert ULID.from_bytes(ulid.bytes) == ulid assert ULID.from_str(str(ulid)) == ulid assert ULID.from_uuid(ulid.to_uuid()) == ulid assert ULID.from_int(int(ulid)) == ulid assert ULID.from_hex(ulid.hex) == ulid
def test_ulid(): ulid = ULID() t = time.time() now = utcnow() assert len(ulid.bytes) == constants.BYTES_LEN assert len(str(ulid)) == constants.REPR_LEN assert all(c in base32.ENCODE for c in str(ulid)) assert isinstance(ulid.to_uuid(), uuid.UUID) assert isinstance(ulid.timestamp, float) assert ulid.timestamp == pytest.approx(t) assert isinstance(ulid.datetime, datetime) datetimes_almost_equal(ulid.datetime, now)