[tor-commits] [stem/master] Strip whitespaces from is_running ps results

atagar at torproject.org atagar at torproject.org
Mon Dec 19 17:54:15 UTC 2011


commit f1a41ecc8534327772f9eca3430e373a2b8a54b8
Author: Damian Johnson <atagar at torproject.org>
Date:   Mon Dec 19 09:52:03 2011 -0800

    Strip whitespaces from is_running ps results
    
    Fix and unit testing for whitespace in the ps results. Also fixing the unit
    test so we make sure that we get False rather than None when we confirmed that
    the command wasn't running.
---
 stem/util/system.py      |    1 +
 test/unit/util/system.py |    5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/stem/util/system.py b/stem/util/system.py
index 659d3ca..8d4708e 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -136,6 +136,7 @@ def is_running(command):
       command_listing = call(secondary_resolver)
     
     if command_listing:
+      command_listing = map(str.strip, command_listing)
       return command in command_listing
   
   return None
diff --git a/test/unit/util/system.py b/test/unit/util/system.py
index 1941c46..e3d1225 100644
--- a/test/unit/util/system.py
+++ b/test/unit/util/system.py
@@ -84,7 +84,7 @@ class TestSystem(unittest.TestCase):
     """
     
     # mock response with a linux and bsd resolver
-    running_commands = ["irssi", "moc", "tor", "ps"]
+    running_commands = ["irssi", "moc", "tor", "ps", "  firefox  "]
     
     for ps_cmd in (system.IS_RUNNING_PS_LINUX, system.IS_RUNNING_PS_BSD):
       system.CALL_MOCKING = functools.partial(mock_call, ps_cmd, running_commands)
@@ -93,7 +93,8 @@ class TestSystem(unittest.TestCase):
       self.assertTrue(system.is_running("moc"))
       self.assertTrue(system.is_running("tor"))
       self.assertTrue(system.is_running("ps"))
-      self.assertFalse(system.is_running("something_else"))
+      self.assertTrue(system.is_running("firefox"))
+      self.assertEqual(False, system.is_running("something_else"))
     
     # mock both calls failing
     system.CALL_MOCKING = lambda cmd: None



More information about the tor-commits mailing list