File: test_floatclock.py

package info (click to toggle)
python-pyinstrument 5.1.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,624 kB
  • sloc: python: 6,713; ansic: 897; makefile: 46; sh: 26; javascript: 18
file content (34 lines) | stat: -rw-r--r-- 748 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
29
30
31
32
33
34
import ctypes
import time

import pytest

import pyinstrument.low_level.stat_profile as native_module

lib = ctypes.CDLL(native_module.__file__)

pyi_floatclock = lib.pyi_floatclock
pyi_floatclock.argtypes = [ctypes.c_int]
pyi_floatclock.restype = ctypes.c_double


def test_floatclock():
    time_a = pyi_floatclock(0)
    time.sleep(0.001)
    time_b = pyi_floatclock(0)
    assert time_b > time_a


def test_is_in_seconds():
    floatclock_time_a = pyi_floatclock(0)
    time_a = time.time()

    time.sleep(0.1)

    floatclock_time_b = pyi_floatclock(0)
    time_b = time.time()

    floatclock_duration = floatclock_time_b - floatclock_time_a
    duration = time_b - time_a

    assert floatclock_duration == pytest.approx(duration, rel=0.1)