tests/mocktime.py
author Martin von Zweigbergk <martinvonz@google.com>
Tue, 18 Jan 2022 12:57:55 -0800
changeset 48756 86e4b86df932
parent 43076 2372284d9457
child 48875 6000f5b25c9b
permissions -rw-r--r--
filemerge: when not keeping premerge, don't write markers to context When premerge is enabled (as it is for non-binary inputs by default) and the markers are not kept, we currently still write it to the output context and then restore the previous content right after. With the refactoring in the previous patch, we can easily avoid that step and instead write the output in the opposite case (i.e. when it's successful or when the markers are supposed to be kept). Differential Revision: https://phab.mercurial-scm.org/D12149
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34316
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
     1
from __future__ import absolute_import
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
     2
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
     3
import os
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
     4
import time
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
     5
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 34316
diff changeset
     6
34316
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
     7
class mocktime(object):
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
     8
    def __init__(self, increment):
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
     9
        self.time = 0
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    10
        self.increment = [float(s) for s in increment.split()]
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    11
        self.pos = 0
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    12
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    13
    def __call__(self):
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    14
        self.time += self.increment[self.pos % len(self.increment)]
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    15
        self.pos += 1
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    16
        return self.time
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    17
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 34316
diff changeset
    18
34316
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    19
def uisetup(ui):
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    20
    time.time = mocktime(os.environ.get('MOCKTIME', '0.1'))