[tor-commits] [bridgedb/develop] Move getBridgeDBPID() from test_bridgedb.py to bridgedb.test.util.

isis at torproject.org isis at torproject.org
Wed Aug 27 06:03:36 UTC 2014


commit c9db4818c890429e699f81723ca98c663388ec0f
Author: Isis Lovecruft <isis at torproject.org>
Date:   Wed Aug 27 05:18:06 2014 +0000

    Move getBridgeDBPID() from test_bridgedb.py to bridgedb.test.util.
---
 lib/bridgedb/test/test_bridgedb.py |   25 ++-----------------------
 lib/bridgedb/test/util.py          |   22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/lib/bridgedb/test/test_bridgedb.py b/lib/bridgedb/test/test_bridgedb.py
index 0d53fef..8627aed 100644
--- a/lib/bridgedb/test/test_bridgedb.py
+++ b/lib/bridgedb/test/test_bridgedb.py
@@ -21,6 +21,7 @@ from twisted.trial import unittest
 from twisted.trial.unittest import SkipTest
 
 from bridgedb.test.util import pidExists
+from bridgedb.test.util import getBridgeDBPID
 
 
 class BridgeDBCliTest(unittest.TestCase):
@@ -31,31 +32,9 @@ class BridgeDBCliTest(unittest.TestCase):
         topdir = here.rstrip('_trial_temp')
         self.rundir = os.path.join(topdir, 'run')
         self.pidfile = os.path.join(self.rundir, 'bridgedb.pid')
-        self.pid = self.getBridgeDBPID(self.pidfile)
+        self.pid = getBridgeDBPID(self.pidfile)
         self.assignmentsFile = os.path.join(self.rundir, 'assignments.log')
 
-    def getBridgeDBPID(self, pidfile="bridgedb.pid"):
-        """Read the ``bridgedb.pid`` file in **rundir**, if it exists, to get
-        the PID.
-
-        :param str pidfile: The path to the BridgeDB pidfile.
-        :rtype: int
-        :returns: The process ID, if available, otherwise ``0``.
-        """
-        fh = None
-        try:
-            fh = open(pidfile)
-        except (IOError, OSError) as err:
-            print(err)
-            pid = 0
-        else:
-            pid = int(fh.read())
-
-        if fh:
-            fh.close()
-
-        return pid
-
     def doSleep(self):
         """Sleep for some ammount of time.
 
diff --git a/lib/bridgedb/test/util.py b/lib/bridgedb/test/util.py
index 1067526..287fa26 100644
--- a/lib/bridgedb/test/util.py
+++ b/lib/bridgedb/test/util.py
@@ -87,6 +87,28 @@ def pidExists(pid):
     else:
         return True
 
+def getBridgeDBPID(pidfile="bridgedb.pid"):
+    """Read the ``bridgedb.pid`` file in **rundir**, if it exists, to get the
+    PID.
+
+    :param str pidfile: The path to the BridgeDB pidfile.
+    :rtype: int
+    :returns: The process ID, if available, otherwise ``0``.
+    """
+    fh = None
+    try:
+        fh = open(pidfile)
+    except (IOError, OSError) as err:
+        print(err)
+        pid = 0
+    else:
+        pid = int(fh.read())
+
+    if fh:
+        fh.close()
+
+    return pid
+
 
 #: Mixin class for use with :api:`~twisted.trial.unittest.TestCase`. A
 #: ``TestCaseMixin`` can be used to add additional methods, which should be





More information about the tor-commits mailing list