File: test_timestamp.py

package info (click to toggle)
python-ulid-transform 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 380 kB
  • sloc: cpp: 942; python: 695; sh: 5; makefile: 4
file content (28 lines) | stat: -rw-r--r-- 770 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import pytest
import tests.conftest  # noqa

example = "01J3YPYJJW00GW0X476W5TVBFE"
example_timestamp = 1722238847580


@pytest.mark.benchmark(group="timestamp")
def test_ut_timestamp(benchmark, impl):
    assert benchmark(lambda: impl.ulid_to_timestamp(example)) == example_timestamp


@pytest.mark.benchmark(group="timestamp")
def test_ulid2_timestamp(benchmark):
    ulid2 = pytest.importorskip("ulid2")
    assert (
        benchmark(lambda: ulid2.get_ulid_timestamp(example))
        == example_timestamp / 1000.0
    )


@pytest.mark.benchmark(group="timestamp")
def test_ulidpy_uuid(benchmark):
    ulid = pytest.importorskip("ulid")
    assert (
        benchmark(lambda: ulid.from_str(example).timestamp().timestamp)
        == example_timestamp / 1000.0
    )