Patchwork D844: test-patchbomb: use mocktime

login
register
mail settings
Submitter phabricator
Date Sept. 29, 2017, 6:58 p.m.
Message ID <a13271040cbba7a9a90d0470f7e9fda0@localhost.localdomain>
Download mbox | patch
Permalink /patch/24219/
State Not Applicable
Headers show

Comments

phabricator - Sept. 29, 2017, 6:58 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGb4dbebdaf9e0: test-patchbomb: use mocktime (authored by quark, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D844?vs=2163&id=2164

REVISION DETAIL
  https://phab.mercurial-scm.org/D844

AFFECTED FILES
  tests/mocktime.py
  tests/test-patchbomb.t
  tests/test-progress.t

CHANGE DETAILS




To: quark, #hg-reviewers, indygreg
Cc: mercurial-devel

Patch

diff --git a/tests/test-progress.t b/tests/test-progress.t
--- a/tests/test-progress.t
+++ b/tests/test-progress.t
@@ -185,35 +185,17 @@ 
 
 #if no-chg
 
-  $ cat > mocktime.py <<EOF
-  > import os
-  > import time
-  > 
-  > class mocktime(object):
-  >     def __init__(self, increment):
-  >         self.time = 0
-  >         self.increment = [int(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', '11'))
-  > EOF
-
   $ cp $HGRCPATH.orig $HGRCPATH
   $ echo "[extensions]" >> $HGRCPATH
-  $ echo "mocktime=`pwd`/mocktime.py" >> $HGRCPATH
+  $ echo "mocktime=$TESTDIR/mocktime.py" >> $HGRCPATH
   $ echo "progress=" >> $HGRCPATH
   $ echo "loop=`pwd`/loop.py" >> $HGRCPATH
   $ echo "[progress]" >> $HGRCPATH
   $ echo "assume-tty=1" >> $HGRCPATH
   $ echo "delay=25" >> $HGRCPATH
   $ echo "width=60" >> $HGRCPATH
 
-  $ hg -y loop 8
+  $ MOCKTIME=11 hg -y loop 8
   \r (no-eol) (esc)
   loop [=========>                                ] 2/8 1m07s\r (no-eol) (esc)
   loop [===============>                            ] 3/8 56s\r (no-eol) (esc)
@@ -274,7 +256,7 @@ 
                                                               \r (no-eol) (esc)
 
 Time estimates should not fail when there's no end point:
-  $ hg -y loop -- -4
+  $ MOCKTIME=11 hg -y loop -- -4
   \r (no-eol) (esc)
   loop [ <=>                                              ] 2\r (no-eol) (esc)
   loop [  <=>                                             ] 3\r (no-eol) (esc)
diff --git a/tests/test-patchbomb.t b/tests/test-patchbomb.t
--- a/tests/test-patchbomb.t
+++ b/tests/test-patchbomb.t
@@ -323,7 +323,8 @@ 
   $ hg email -m test.mbox -f quux -t foo -c bar -s test 0:tip \
   > --config extensions.progress= --config progress.assume-tty=1 \
   > --config progress.delay=0 --config progress.refresh=0 \
-  > --config progress.width=60
+  > --config progress.width=60 \
+  > --config extensions.mocktime=$TESTDIR/mocktime.py
   this patch series consists of 2 patches.
   
   
diff --git a/tests/mocktime.py b/tests/mocktime.py
new file mode 100644
--- /dev/null
+++ b/tests/mocktime.py
@@ -0,0 +1,18 @@ 
+from __future__ import absolute_import
+
+import os
+import time
+
+class mocktime(object):
+    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'))