File: time.py

package info (click to toggle)
python-memoize 1.0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 108 kB
  • sloc: python: 324; makefile: 3
file content (30 lines) | stat: -rw-r--r-- 510 bytes parent folder | download | duplicates (3)
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
from __future__ import absolute_import

from time import time as _time, sleep as _sleep


_time_travel = False
_time_offset = 0.0


def start_time_travel():
    """For testing.

    Causes :func:`sleep` to return immediately, but still effect the
    output of :func:`time`.

    """
    global _time_travel
    _time_travel = True


def time():
    return _time() + _time_offset


def sleep(amount):
    global _time_offset
    if _time_travel:
        _time_offset += amount
    else:
        _sleep(amount)