tests/mocktime.py
author Gregory Szorc <gregory.szorc@gmail.com>
Wed, 07 Mar 2018 20:41:59 -0800
changeset 37006 8e89c2bec1f7
parent 34316 12b355964de8
child 43076 2372284d9457
permissions -rw-r--r--
httppeer: refactor how httppeer is created (API) Previously, we passed a bunch of arguments to httppeer.__init__, validated them, then possibly constructed a valid instance. A short while ago, we refactored sshpeer so all the validation and setup work occurs before the constructor. We introduced a makepeer() to hold most of this logic. This commit gives httppeer the same treatment. As a sign that the previous design was poor, __del__ no longer conditionally checks for the presence of an attribute that may not be defined (it is always defined in the new code). .. api:: httppeer.httppeer.__init__ now takes additional arguments. Instances should be obtained by calling httppeer.instance() or httppeer.makepeer() instead. Differential Revision: https://phab.mercurial-scm.org/D2725
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
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
     6
class mocktime(object):
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
     7
    def __init__(self, increment):
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
     8
        self.time = 0
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
     9
        self.increment = [float(s) for s in increment.split()]
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    10
        self.pos = 0
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    11
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    12
    def __call__(self):
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    13
        self.time += self.increment[self.pos % len(self.increment)]
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    14
        self.pos += 1
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    15
        return self.time
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    16
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    17
def uisetup(ui):
12b355964de8 test-patchbomb: use mocktime
Jun Wu <quark@fb.com>
parents:
diff changeset
    18
    time.time = mocktime(os.environ.get('MOCKTIME', '0.1'))