tests/mocktime.py
author Gregory Szorc <gregory.szorc@gmail.com>
Mon, 21 Feb 2022 13:08:28 -0700
changeset 48946 642e31cb55f0
parent 48875 6000f5b25c9b
permissions -rw-r--r--
py3: use class X: instead of class X(object): The inheritance from object is implied in Python 3. So this should be equivalent. This change was generated via an automated search and replace. So there may have been some accidental changes. Differential Revision: https://phab.mercurial-scm.org/D12352

import os
import time


class mocktime:
    def __init__(self, increment):
        self.time = 0
        self.increment = [float(s) for s in increment.split()]
        self.pos = 0

    def __call__(self):
        self.time += self.increment[self.pos % len(self.increment)]
        self.pos += 1
        return self.time


def uisetup(ui):
    time.time = mocktime(os.environ.get('MOCKTIME', '0.1'))