util: enable getpid to be replaced
authortimeless <timeless@mozdev.org>
Wed, 03 Feb 2016 09:11:22 +0000
changeset 28027 14033c5dd261
parent 28026 a6db1163befa
child 28028 ac49ecb2a897
util: enable getpid to be replaced This will enable tests to write stable process ids.
hgext/blackbox.py
mercurial/cmdutil.py
mercurial/commandserver.py
mercurial/lock.py
mercurial/util.py
tests/test-lock.py
--- a/hgext/blackbox.py	Mon Feb 08 00:47:36 2016 +0000
+++ b/hgext/blackbox.py	Wed Feb 03 09:11:22 2016 +0000
@@ -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)
@@ -107,7 +107,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' %
--- a/mercurial/cmdutil.py	Mon Feb 08 00:47:36 2016 +0000
+++ b/mercurial/cmdutil.py	Wed Feb 03 09:11:22 2016 +0000
@@ -796,7 +796,7 @@
         initfn()
 
     if not opts['daemon']:
-        writepid(os.getpid())
+        writepid(util.getpid())
 
     if opts['daemon_pipefds']:
         lockpath = opts['daemon_pipefds']
--- a/mercurial/commandserver.py	Mon Feb 08 00:47:36 2016 +0000
+++ b/mercurial/commandserver.py	Wed Feb 03 09:11:22 2016 +0000
@@ -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)
--- a/mercurial/lock.py	Mon Feb 08 00:47:36 2016 +0000
+++ b/mercurial/lock.py	Wed Feb 03 09:11:22 2016 +0000
@@ -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
--- a/mercurial/util.py	Mon Feb 08 00:47:36 2016 +0000
+++ b/mercurial/util.py	Wed Feb 03 09:11:22 2016 +0000
@@ -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
--- a/tests/test-lock.py	Mon Feb 08 00:47:36 2016 +0000
+++ b/tests/test-lock.py	Wed Feb 03 09:11:22 2016 +0000
@@ -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):