[PATCH 6 of 7] util: enable getpid to be replaced

timeless timeless at mozdev.org
Wed Feb 3 16:40:48 EST 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1454490682 0
#      Wed Feb 03 09:11:22 2016 +0000
# Node ID 0594bc25250938518eaffe34d7a06b719e47cef5
# Parent  ed58e3820ee3c6aa1500cfbe92bf4d390df849e4
util: enable getpid to be replaced

This will enable tests to write stable process ids.

diff --git a/hgext/blackbox.py b/hgext/blackbox.py
--- a/hgext/blackbox.py
+++ b/hgext/blackbox.py
@@ -31,7 +31,7 @@
 
 from mercurial import util, cmdutil
 from mercurial.i18n import _
-import errno, os, re
+import errno, re
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
@@ -123,7 +123,7 @@
             if blackbox:
                 date = util.datestr(None, '%Y/%m/%d %H:%M:%S')
                 user = util.getuser()
-                pid = str(os.getpid())
+                pid = str(util.getpid())
                 formattedmsg = msg[0] % msg[1:]
                 try:
                     blackbox.write('%s %s (%s)> %s' %
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -796,7 +796,7 @@
         initfn()
 
     if not opts['daemon']:
-        writepid(os.getpid())
+        writepid(util.getpid())
 
     if opts['daemon_pipefds']:
         lockpath = opts['daemon_pipefds']
diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -262,7 +262,7 @@
         hellomsg += '\n'
         hellomsg += 'encoding: ' + encoding.encoding
         hellomsg += '\n'
-        hellomsg += 'pid: %d' % os.getpid()
+        hellomsg += 'pid: %d' % util.getpid()
 
         # write the hello msg in -one- chunk
         self.cout.write(hellomsg)
diff --git a/mercurial/lock.py b/mercurial/lock.py
--- a/mercurial/lock.py
+++ b/mercurial/lock.py
@@ -9,7 +9,6 @@
 
 import contextlib
 import errno
-import os
 import socket
 import time
 import warnings
@@ -77,8 +76,8 @@
         self.release()
 
     def _getpid(self):
-        # wrapper around os.getpid() to make testing easier
-        return os.getpid()
+        # wrapper around util.getpid() to make testing easier
+        return util.getpid()
 
     def lock(self):
         timeout = self.timeout
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -65,6 +65,7 @@
 findexe = platform.findexe
 gethgcmd = platform.gethgcmd
 getuser = platform.getuser
+getpid = os.getpid
 groupmembers = platform.groupmembers
 groupname = platform.groupname
 hidewindow = platform.hidewindow
diff --git a/tests/test-lock.py b/tests/test-lock.py
--- a/tests/test-lock.py
+++ b/tests/test-lock.py
@@ -28,7 +28,7 @@
         self._pidoffset = pidoffset
         super(lockwrapper, self).__init__(*args, **kwargs)
     def _getpid(self):
-        return os.getpid() + self._pidoffset
+        return super(lockwrapper, self)._getpid() + self._pidoffset
 
 class teststate(object):
     def __init__(self, testcase, dir, pidoffset=0):


More information about the Mercurial-devel mailing list