tests/mocktime.py
author Arseniy Alekseyev <aalekseyev@janestreet.com>
Mon, 26 Jun 2023 11:15:30 +0100
branchstable
changeset 50724 a10d823a8e3d
parent 48946 642e31cb55f0
permissions -rw-r--r--
dirstate: avoid leaking disk space in `hg debugrebuilddirstate` Before this MR running `hg debugrebuilddirstate` simply grows the dirstate without bound, never shrinking it, because the unused bytes counter stays low, even though the entirety of the file becomes unused.

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'))