[tor-commits] [stem/master] Dropping get_* prefix from system functions
atagar at torproject.org
atagar at torproject.org
Tue Sep 2 03:55:48 UTC 2014
commit 87f9549091d4050578b963238179a584b2936491
Author: Damian Johnson <atagar at torproject.org>
Date: Mon Sep 1 18:02:49 2014 -0700
Dropping get_* prefix from system functions
---
docs/change_log.rst | 10 +--
docs/tutorials/east_of_the_sun.rst | 4 +-
stem/connection.py | 14 ++--
stem/control.py | 8 +-
stem/util/connection.py | 2 +-
stem/util/proc.py | 4 +
stem/util/system.py | 67 +++++++++++------
test/integ/util/system.py | 142 ++++++++++++++++++------------------
test/unit/control/controller.py | 6 +-
test/unit/response/protocolinfo.py | 2 +-
test/unit/util/connection.py | 2 +-
test/unit/util/system.py | 120 +++++++++++++++---------------
12 files changed, 202 insertions(+), 179 deletions(-)
diff --git a/docs/change_log.rst b/docs/change_log.rst
index 24e39f0..dbb5581 100644
--- a/docs/change_log.rst
+++ b/docs/change_log.rst
@@ -147,12 +147,12 @@ and a myriad of smaller improvements and fixes.
* Connection resolution via the :func:`~stem.util.connection.get_connections` function (:trac:`7910`)
* :func:`~stem.util.system.set_process_name` inserted spaces between characters (:trac:`8631`)
- * :func:`~stem.util.system.get_pid_by_name` can now pull for all processes with a given name
+ * :func:`~stem.util.system.pid_by_name` can now pull for all processes with a given name
* :func:`~stem.util.system.call` ignored the subprocess' exit status
- * Added :func:`stem.util.system.get_name_by_pid`
- * Added :func:`stem.util.system.get_user`
- * Added :func:`stem.util.system.get_start_time`
- * Added :func:`stem.util.system.get_bsd_jail_path`
+ * Added :func:`stem.util.system.name_by_pid`
+ * Added :func:`stem.util.system.user`
+ * Added :func:`stem.util.system.start_time`
+ * Added :func:`stem.util.system.bsd_jail_path`
* Added :func:`stem.util.system.is_tarfile`
* Added :func:`stem.util.connection.is_private_address`
diff --git a/docs/tutorials/east_of_the_sun.rst b/docs/tutorials/east_of_the_sun.rst
index 374275e..fa7635b 100644
--- a/docs/tutorials/east_of_the_sun.rst
+++ b/docs/tutorials/east_of_the_sun.rst
@@ -38,7 +38,7 @@ simple script that dumps Tor's present connections.
import sys
from stem.util.connection import get_connections, get_system_resolvers
- from stem.util.system import get_pid_by_name
+ from stem.util.system import pid_by_name
resolvers = get_system_resolvers()
@@ -49,7 +49,7 @@ simple script that dumps Tor's present connections.
picked_resolver = resolvers[0] # lets just opt for the first
print "Our platform supports connection resolution via: %s (picked %s)" % (', '.join(resolvers), picked_resolver)
- tor_pids = get_pid_by_name('tor', multiple = True)
+ tor_pids = pid_by_name('tor', multiple = True)
if not tor_pids:
print "Unable to get tor's pid. Is it running?"
diff --git a/stem/connection.py b/stem/connection.py
index cc28fa5..a38422b 100644
--- a/stem/connection.py
+++ b/stem/connection.py
@@ -1012,7 +1012,7 @@ def get_protocolinfo(controller):
# attempt to expand relative cookie paths
if protocolinfo_response.cookie_path:
- _expand_cookie_path(protocolinfo_response, stem.util.system.get_pid_by_name, 'tor')
+ _expand_cookie_path(protocolinfo_response, stem.util.system.pid_by_name, 'tor')
# attempt to expand relative cookie paths via the control port or socket file
@@ -1023,10 +1023,10 @@ def get_protocolinfo(controller):
if isinstance(control_socket, stem.socket.ControlPort):
if control_socket.get_address() == '127.0.0.1':
- pid_method = stem.util.system.get_pid_by_port
+ pid_method = stem.util.system.pid_by_port
_expand_cookie_path(protocolinfo_response, pid_method, control_socket.get_port())
elif isinstance(control_socket, stem.socket.ControlSocketFile):
- pid_method = stem.util.system.get_pid_by_open_file
+ pid_method = stem.util.system.pid_by_open_file
_expand_cookie_path(protocolinfo_response, pid_method, control_socket.get_socket_path())
return protocolinfo_response
@@ -1102,7 +1102,7 @@ def _expand_cookie_path(protocolinfo_response, pid_resolver, pid_resolution_arg)
if not tor_pid:
raise IOError('pid lookup failed')
- tor_cwd = stem.util.system.get_cwd(tor_pid)
+ tor_cwd = stem.util.system.cwd(tor_pid)
if not tor_cwd:
raise IOError('cwd lookup failed')
@@ -1110,9 +1110,9 @@ def _expand_cookie_path(protocolinfo_response, pid_resolver, pid_resolution_arg)
cookie_path = stem.util.system.expand_path(cookie_path, tor_cwd)
except IOError as exc:
resolver_labels = {
- stem.util.system.get_pid_by_name: ' by name',
- stem.util.system.get_pid_by_port: ' by port',
- stem.util.system.get_pid_by_open_file: ' by socket file',
+ stem.util.system.pid_by_name: ' by name',
+ stem.util.system.pid_by_port: ' by port',
+ stem.util.system.pid_by_open_file: ' by socket file',
}
pid_resolver_label = resolver_labels.get(pid_resolver, '')
diff --git a/stem/control.py b/stem/control.py
index 7c5d7bd..e5f4769 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1242,7 +1242,7 @@ class Controller(BaseController):
pid = self.get_pid(None)
if pid:
- user = stem.util.system.get_user(pid)
+ user = stem.util.system.user(pid)
if user:
self._set_cache({'user': user})
@@ -1290,15 +1290,15 @@ class Controller(BaseController):
pid = int(pid_file_contents)
if not pid:
- pid = stem.util.system.get_pid_by_name('tor')
+ pid = stem.util.system.pid_by_name('tor')
if not pid:
control_socket = self.get_socket()
if isinstance(control_socket, stem.socket.ControlPort):
- pid = stem.util.system.get_pid_by_port(control_socket.get_port())
+ pid = stem.util.system.pid_by_port(control_socket.get_port())
elif isinstance(control_socket, stem.socket.ControlSocketFile):
- pid = stem.util.system.get_pid_by_open_file(control_socket.get_socket_path())
+ pid = stem.util.system.pid_by_open_file(control_socket.get_socket_path())
if pid:
self._set_cache({'pid': pid})
diff --git a/stem/util/connection.py b/stem/util/connection.py
index 461f40a..0c5b744 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -172,7 +172,7 @@ def get_connections(resolver, process_pid = None, process_name = None):
raise ValueError('%s resolution requires a pid' % resolver)
if resolver == Resolver.PROC:
- return [Connection(*conn) for conn in stem.util.proc.get_connections(process_pid)]
+ return [Connection(*conn) for conn in stem.util.proc.connections(process_pid)]
resolver_command = RESOLVER_COMMAND[resolver].format(pid = process_pid)
diff --git a/stem/util/proc.py b/stem/util/proc.py
index ac1f6f6..b05d283 100644
--- a/stem/util/proc.py
+++ b/stem/util/proc.py
@@ -15,6 +15,10 @@ Dave Daeschler, Giampaolo Rodola' and is under the BSD license.
**These functions are not being vended to stem users. They may change in the
future, use them at your own risk.**
+.. deprecated:: 1.3.0
+ Many functions were previously named with a get_* prefix. Those names are
+ now aliases, and will be dropped in Stem version 2.0.0.
+
**Module Overview:**
::
diff --git a/stem/util/system.py b/stem/util/system.py
index b42a03f..89eac3f 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -6,6 +6,10 @@ Helper functions for working with the underlying system. These are mostly os
dependent, only working on linux, osx, and bsd. In almost all cases they're
best-effort, providing **None** if the lookup fails.
+.. deprecated:: 1.3.0
+ Many functions were previously named with a get_* prefix. Those names are
+ now aliases, and will be dropped in Stem version 2.0.0.
+
**Module Overview:**
::
@@ -18,15 +22,15 @@ best-effort, providing **None** if the lookup fails.
is_running - determines if a given process is running
call - runs the given system command and provides back the results
- get_name_by_pid - gets the name for a process by the given pid
- get_pid_by_name - gets the pid for a process by the given name
- get_pid_by_port - gets the pid for a process listening to a given port
- get_pid_by_open_file - gets the pid for the process with an open file
- get_cwd - provides the current working directory for a given process
- get_user - provides the user a process is running under
- get_start_time - provides the unix timestamp when the process started
- get_bsd_jail_id - provides the BSD jail id a given process is running within
- get_bsd_jail_path - provides the path of the given BSD jail
+ name_by_pid - gets the name for a process by the given pid
+ pid_by_name - gets the pid for a process by the given name
+ pid_by_port - gets the pid for a process listening to a given port
+ pid_by_open_file - gets the pid for the process with an open file
+ cwd - provides the current working directory for a given process
+ user - provides the user a process is running under
+ start_time - provides the unix timestamp when the process started
+ bsd_jail_id - provides the BSD jail id a given process is running within
+ bsd_jail_path - provides the path of the given BSD jail
is_tarfile - checks if the given path is a tarball
expand_path - expands relative paths and ~ entries
@@ -233,7 +237,7 @@ def is_running(command):
return None
-def get_name_by_pid(pid):
+def name_by_pid(pid):
"""
Attempts to determine the name a given process is running under (not
including arguments). This uses...
@@ -252,7 +256,7 @@ def get_name_by_pid(pid):
if stem.util.proc.is_available():
try:
- process_name = stem.util.proc.get_stats(pid, stem.util.proc.Stat.COMMAND)[0]
+ process_name = stem.util.proc.stats(pid, stem.util.proc.Stat.COMMAND)[0]
except IOError:
pass
@@ -273,7 +277,7 @@ def get_name_by_pid(pid):
return process_name
-def get_pid_by_name(process_name, multiple = False):
+def pid_by_name(process_name, multiple = False):
"""
Attempts to determine the process id for a running process, using...
@@ -421,7 +425,7 @@ def get_pid_by_name(process_name, multiple = False):
return [] if multiple else None
-def get_pid_by_port(port):
+def pid_by_port(port):
"""
Attempts to determine the process id for a process with the given port,
using...
@@ -541,7 +545,7 @@ def get_pid_by_port(port):
return None # all queries failed
-def get_pid_by_open_file(path):
+def pid_by_open_file(path):
"""
Attempts to determine the process id for a process with the given open file,
using...
@@ -579,7 +583,7 @@ def get_pid_by_open_file(path):
return None # all queries failed
-def get_cwd(pid):
+def cwd(pid):
"""
Provides the working directory of the given process.
@@ -592,12 +596,12 @@ def get_cwd(pid):
# try fetching via the proc contents if it's available
if stem.util.proc.is_available():
try:
- return stem.util.proc.get_cwd(pid)
+ return stem.util.proc.cwd(pid)
except IOError:
pass
# Fall back to a pwdx query. This isn't available on BSD.
- logging_prefix = 'get_cwd(%s):' % pid
+ logging_prefix = 'cwd(%s):' % pid
if is_available('pwdx'):
# pwdx results are of the form:
@@ -648,7 +652,7 @@ def get_cwd(pid):
return None # all queries failed
-def get_user(pid):
+def user(pid):
"""
Provides the user a process is running under.
@@ -665,7 +669,7 @@ def get_user(pid):
try:
import pwd # only available on unix platforms
- uid = stem.util.proc.get_uid(pid)
+ uid = stem.util.proc.uid(pid)
if uid and uid.isdigit():
return pwd.getpwuid(int(uid)).pw_name
@@ -681,7 +685,7 @@ def get_user(pid):
return None
-def get_start_time(pid):
+def start_time(pid):
"""
Provides the unix timestamp when the given process started.
@@ -696,7 +700,7 @@ def get_start_time(pid):
if stem.util.proc.is_available():
try:
- return float(stem.util.proc.get_stats(pid, stem.util.proc.Stat.START_TIME)[0])
+ return float(stem.util.proc.stats(pid, stem.util.proc.Stat.START_TIME)[0])
except IOError:
pass
@@ -712,7 +716,7 @@ def get_start_time(pid):
return None
-def get_bsd_jail_id(pid):
+def bsd_jail_id(pid):
"""
Gets the jail id for a process. These seem to only exist for FreeBSD (this
style for jails does not exist on Linux, OSX, or OpenBSD).
@@ -742,12 +746,12 @@ def get_bsd_jail_id(pid):
if os_name == 'FreeBSD':
log.warn('Unable to get the jail id for process %s.' % pid)
else:
- log.debug('get_bsd_jail_id(%s): jail ids do not exist on %s' % (pid, os_name))
+ log.debug('bsd_jail_id(%s): jail ids do not exist on %s' % (pid, os_name))
return 0
-def get_bsd_jail_path(jid):
+def bsd_jail_path(jid):
"""
Provides the path of the given FreeBSD jail.
@@ -1066,3 +1070,18 @@ def _set_proc_title(process_name):
# AttributeError: dlsym(0x7fff6a41d1e0, setproctitle): symbol not found
pass
+
+
+# TODO: drop with stem 2.x
+# We renamed our methods to drop a redundant 'get_*' prefix, so alias the old
+# names for backward compatability.
+
+get_name_by_pid = name_by_pid
+get_pid_by_name = pid_by_name
+get_pid_by_port = pid_by_port
+get_pid_by_open_file = pid_by_open_file
+get_cwd = cwd
+get_user = user
+get_start_time = start_time
+get_bsd_jail_id = bsd_jail_id
+get_bsd_jail_path = bsd_jail_path
diff --git a/test/integ/util/system.py b/test/integ/util/system.py
index 69b7c78..c075a27 100644
--- a/test/integ/util/system.py
+++ b/test/integ/util/system.py
@@ -76,9 +76,9 @@ class TestSystem(unittest.TestCase):
self.assertTrue(stem.util.system.is_running('tor'))
self.assertFalse(stem.util.system.is_running('blarg_and_stuff'))
- def test_get_pid_by_name(self):
+ def test_pid_by_name(self):
"""
- Checks general usage of the stem.util.system.get_pid_by_name function. This
+ Checks general usage of the stem.util.system.pid_by_name function. This
will fail if there's other tor instances running.
"""
@@ -90,12 +90,12 @@ class TestSystem(unittest.TestCase):
return
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_name('tor'))
- self.assertEquals(None, stem.util.system.get_pid_by_name('blarg_and_stuff'))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_name('tor'))
+ self.assertEquals(None, stem.util.system.pid_by_name('blarg_and_stuff'))
- def test_get_pid_by_name_pgrep(self):
+ def test_pid_by_name_pgrep(self):
"""
- Tests the get_pid_by_name function with a pgrep response.
+ Tests the pid_by_name function with a pgrep response.
"""
if self._is_extra_tor_running():
@@ -113,11 +113,11 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_name('tor'))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_name('tor'))
- def test_get_pid_by_name_pidof(self):
+ def test_pid_by_name_pidof(self):
"""
- Tests the get_pid_by_name function with a pidof response.
+ Tests the pid_by_name function with a pidof response.
"""
if self._is_extra_tor_running():
@@ -135,11 +135,11 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_name('tor'))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_name('tor'))
- def test_get_pid_by_name_ps_linux(self):
+ def test_pid_by_name_ps_linux(self):
"""
- Tests the get_pid_by_name function with the linux variant of ps.
+ Tests the pid_by_name function with the linux variant of ps.
"""
if self._is_extra_tor_running():
@@ -160,11 +160,11 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_name('tor'))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_name('tor'))
- def test_get_pid_by_name_ps_bsd(self):
+ def test_pid_by_name_ps_bsd(self):
"""
- Tests the get_pid_by_name function with the bsd variant of ps.
+ Tests the pid_by_name function with the bsd variant of ps.
"""
if self._is_extra_tor_running():
@@ -185,11 +185,11 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_name('tor'))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_name('tor'))
- def test_get_pid_by_name_lsof(self):
+ def test_pid_by_name_lsof(self):
"""
- Tests the get_pid_by_name function with a lsof response.
+ Tests the pid_by_name function with a lsof response.
"""
runner = test.runner.get_runner()
@@ -211,14 +211,14 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
our_tor_pid = test.runner.get_runner().get_pid()
- all_tor_pids = stem.util.system.get_pid_by_name('tor', multiple = True)
+ all_tor_pids = stem.util.system.pid_by_name('tor', multiple = True)
if len(all_tor_pids) == 1:
self.assertEquals(our_tor_pid, all_tor_pids[0])
- def test_get_pid_by_port(self):
+ def test_pid_by_port(self):
"""
- Checks general usage of the stem.util.system.get_pid_by_port function.
+ Checks general usage of the stem.util.system.pid_by_port function.
"""
runner = test.runner.get_runner()
@@ -241,12 +241,12 @@ class TestSystem(unittest.TestCase):
return
tor_pid, tor_port = runner.get_pid(), test.runner.CONTROL_PORT
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_port(tor_port))
- self.assertEquals(None, stem.util.system.get_pid_by_port(99999))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_port(tor_port))
+ self.assertEquals(None, stem.util.system.pid_by_port(99999))
- def test_get_pid_by_port_netstat(self):
+ def test_pid_by_port_netstat(self):
"""
- Tests the get_pid_by_port function with a netstat response.
+ Tests the pid_by_port function with a netstat response.
"""
runner = test.runner.get_runner()
@@ -271,11 +271,11 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_port(test.runner.CONTROL_PORT))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_port(test.runner.CONTROL_PORT))
- def test_get_pid_by_port_sockstat(self):
+ def test_pid_by_port_sockstat(self):
"""
- Tests the get_pid_by_port function with a sockstat response.
+ Tests the pid_by_port function with a sockstat response.
"""
runner = test.runner.get_runner()
@@ -300,11 +300,11 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_port(test.runner.CONTROL_PORT))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_port(test.runner.CONTROL_PORT))
- def test_get_pid_by_port_lsof(self):
+ def test_pid_by_port_lsof(self):
"""
- Tests the get_pid_by_port function with a lsof response.
+ Tests the pid_by_port function with a lsof response.
"""
runner = test.runner.get_runner()
@@ -329,24 +329,24 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
tor_pid = test.runner.get_runner().get_pid()
- self.assertEquals(tor_pid, stem.util.system.get_pid_by_port(test.runner.CONTROL_PORT))
+ self.assertEquals(tor_pid, stem.util.system.pid_by_port(test.runner.CONTROL_PORT))
- def test_get_pid_by_open_file(self):
+ def test_pid_by_open_file(self):
"""
- Checks the stem.util.system.get_pid_by_open_file function.
+ Checks the stem.util.system.pid_by_open_file function.
"""
# check a directory that exists, but isn't claimed by any application
tmpdir = tempfile.mkdtemp()
- self.assertEquals(None, stem.util.system.get_pid_by_open_file(tmpdir))
+ self.assertEquals(None, stem.util.system.pid_by_open_file(tmpdir))
# check a directory that doesn't exist
os.rmdir(tmpdir)
- self.assertEquals(None, stem.util.system.get_pid_by_open_file(tmpdir))
+ self.assertEquals(None, stem.util.system.pid_by_open_file(tmpdir))
- def test_get_cwd(self):
+ def test_cwd(self):
"""
- Checks general usage of the stem.util.system.get_cwd function.
+ Checks general usage of the stem.util.system.cwd function.
"""
runner = test.runner.get_runner()
@@ -359,12 +359,12 @@ class TestSystem(unittest.TestCase):
return
runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
- self.assertEquals(tor_cwd, stem.util.system.get_cwd(runner_pid))
- self.assertEquals(None, stem.util.system.get_cwd(99999))
+ self.assertEquals(tor_cwd, stem.util.system.cwd(runner_pid))
+ self.assertEquals(None, stem.util.system.cwd(99999))
- def test_get_cwd_pwdx(self):
+ def test_cwd_pwdx(self):
"""
- Tests the get_pid_by_cwd function with a pwdx response.
+ Tests the pid_by_cwd function with a pwdx response.
"""
runner = test.runner.get_runner()
@@ -386,11 +386,11 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
- self.assertEquals(tor_cwd, stem.util.system.get_cwd(runner_pid))
+ self.assertEquals(tor_cwd, stem.util.system.cwd(runner_pid))
- def test_get_cwd_lsof(self):
+ def test_cwd_lsof(self):
"""
- Tests the get_pid_by_cwd function with a lsof response.
+ Tests the pid_by_cwd function with a lsof response.
"""
runner = test.runner.get_runner()
@@ -412,20 +412,20 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
runner_pid, tor_cwd = runner.get_pid(), runner.get_tor_cwd()
- self.assertEquals(tor_cwd, stem.util.system.get_cwd(runner_pid))
+ self.assertEquals(tor_cwd, stem.util.system.cwd(runner_pid))
- def test_get_user_none(self):
+ def test_user_none(self):
"""
- Tests the get_user function when the process doesn't exist.
+ Tests the user function when the process doesn't exist.
"""
- self.assertEqual(None, stem.util.system.get_user(None))
- self.assertEqual(None, stem.util.system.get_user(-5))
- self.assertEqual(None, stem.util.system.get_start_time(98765))
+ self.assertEqual(None, stem.util.system.user(None))
+ self.assertEqual(None, stem.util.system.user(-5))
+ self.assertEqual(None, stem.util.system.start_time(98765))
- def test_get_user_proc(self):
+ def test_user_proc(self):
"""
- Tests the get_user function with a proc response.
+ Tests the user function with a proc response.
"""
if not stem.util.proc.is_available():
@@ -440,12 +440,12 @@ class TestSystem(unittest.TestCase):
# we started our tor process so it should be running with the same user
pid = test.runner.get_runner().get_pid()
- self.assertTrue(getpass.getuser(), stem.util.system.get_user(pid))
+ self.assertTrue(getpass.getuser(), stem.util.system.user(pid))
@patch('stem.util.proc.is_available', Mock(return_value = False))
- def test_get_user_ps(self):
+ def test_user_ps(self):
"""
- Tests the get_user function with a ps response.
+ Tests the user function with a ps response.
"""
if not stem.util.system.is_available('ps'):
@@ -453,20 +453,20 @@ class TestSystem(unittest.TestCase):
return
pid = test.runner.get_runner().get_pid()
- self.assertTrue(getpass.getuser(), stem.util.system.get_user(pid))
+ self.assertTrue(getpass.getuser(), stem.util.system.user(pid))
- def test_get_start_time_none(self):
+ def test_start_time_none(self):
"""
- Tests the get_start_time function when the process doesn't exist.
+ Tests the start_time function when the process doesn't exist.
"""
- self.assertEqual(None, stem.util.system.get_start_time(None))
- self.assertEqual(None, stem.util.system.get_start_time(-5))
- self.assertEqual(None, stem.util.system.get_start_time(98765))
+ self.assertEqual(None, stem.util.system.start_time(None))
+ self.assertEqual(None, stem.util.system.start_time(-5))
+ self.assertEqual(None, stem.util.system.start_time(98765))
- def test_get_start_time_proc(self):
+ def test_start_time_proc(self):
"""
- Tests the get_start_time function with a proc response.
+ Tests the start_time function with a proc response.
"""
if not stem.util.proc.is_available():
@@ -479,12 +479,12 @@ class TestSystem(unittest.TestCase):
call_mock.side_effect = call_replacement
pid = test.runner.get_runner().get_pid()
- self.assertTrue(stem.util.system.get_start_time(pid) >= 0)
+ self.assertTrue(stem.util.system.start_time(pid) >= 0)
@patch('stem.util.proc.is_available', Mock(return_value = False))
- def test_get_start_time_ps(self):
+ def test_start_time_ps(self):
"""
- Tests the get_start_time function with a ps response.
+ Tests the start_time function with a ps response.
"""
if not stem.util.system.is_available('ps'):
@@ -492,16 +492,16 @@ class TestSystem(unittest.TestCase):
return
pid = test.runner.get_runner().get_pid()
- self.assertTrue(stem.util.system.get_start_time(pid) >= 0)
+ self.assertTrue(stem.util.system.start_time(pid) >= 0)
- def test_get_bsd_jail_id(self):
+ def test_bsd_jail_id(self):
"""
- Exercises the stem.util.system.get_bsd_jail_id function, running through
+ Exercises the stem.util.system.bsd_jail_id function, running through
the failure case (since I'm not on BSD I can't really test this function
properly).
"""
- self.assertEquals(0, stem.util.system.get_bsd_jail_id(99999))
+ self.assertEquals(0, stem.util.system.bsd_jail_id(99999))
def test_expand_path(self):
"""
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index bc6711b..dd61feb 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -329,8 +329,8 @@ class TestControl(unittest.TestCase):
self.assertEqual('atagar', self.controller.get_user())
@patch('stem.socket.ControlSocket.is_localhost', Mock(return_value = True))
- @patch('stem.util.system.get_pid_by_name', Mock(return_value = 432))
- @patch('stem.util.system.get_user', Mock(return_value = 'atagar'))
+ @patch('stem.util.system.pid_by_name', Mock(return_value = 432))
+ @patch('stem.util.system.user', Mock(return_value = 'atagar'))
def test_get_user_by_system(self):
"""
Exercise the get_user() resolution via the system module.
@@ -371,7 +371,7 @@ class TestControl(unittest.TestCase):
open_mock.assert_called_once_with('/tmp/pid_file')
@patch('stem.socket.ControlSocket.is_localhost', Mock(return_value = True))
- @patch('stem.util.system.get_pid_by_name', Mock(return_value = 432))
+ @patch('stem.util.system.pid_by_name', Mock(return_value = 432))
def test_get_pid_by_name(self):
"""
Exercise the get_pid() resolution via the process name.
diff --git a/test/unit/response/protocolinfo.py b/test/unit/response/protocolinfo.py
index 15c7f97..fa87a0d 100644
--- a/test/unit/response/protocolinfo.py
+++ b/test/unit/response/protocolinfo.py
@@ -176,7 +176,7 @@ class TestProtocolInfoResponse(unittest.TestCase):
control_message = mocking.get_message(RELATIVE_COOKIE_PATH)
stem.response.convert('PROTOCOLINFO', control_message)
- stem.connection._expand_cookie_path(control_message, stem.util.system.get_pid_by_name, 'tor')
+ stem.connection._expand_cookie_path(control_message, stem.util.system.pid_by_name, 'tor')
self.assertEquals(os.path.join('/tmp/foo', 'tor-browser_en-US', 'Data', 'control_auth_cookie'), control_message.cookie_path)
diff --git a/test/unit/util/connection.py b/test/unit/util/connection.py
index dc1a9eb..f44a851 100644
--- a/test/unit/util/connection.py
+++ b/test/unit/util/connection.py
@@ -145,7 +145,7 @@ class TestConnection(unittest.TestCase):
self.assertEqual('BitTorrent', stem.util.connection.port_usage(6999))
self.assertEqual(None, stem.util.connection.port_usage(30000)) # unrecognized port
- @patch('stem.util.proc.get_connections')
+ @patch('stem.util.proc.connections')
def test_get_connections_by_proc(self, proc_mock):
"""
Checks the get_connections function with the proc resolver.
diff --git a/test/unit/util/system.py b/test/unit/util/system.py
index 7324c2b..911f151 100644
--- a/test/unit/util/system.py
+++ b/test/unit/util/system.py
@@ -18,7 +18,7 @@ try:
except ImportError:
from mock import Mock, patch
-# Base responses for the get_pid_by_name tests. The 'success' and
+# Base responses for the pid_by_name tests. The 'success' and
# 'multiple_results' entries are filled in by tests.
GET_PID_BY_NAME_BASE_RESULTS = {
@@ -138,9 +138,9 @@ class TestSystem(unittest.TestCase):
@patch('stem.util.system.call')
@patch('stem.util.proc.is_available', Mock(return_value = False))
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_name_by_pid_ps(self, call_mock):
+ def test_name_by_pid_ps(self, call_mock):
"""
- Tests the get_name_by_pid function with ps responses.
+ Tests the name_by_pid function with ps responses.
"""
responses = {
@@ -156,13 +156,13 @@ class TestSystem(unittest.TestCase):
for test_input in responses:
expected_response = 'vim' if test_input == 'success' else None
- self.assertEquals(expected_response, system.get_name_by_pid(test_input))
+ self.assertEquals(expected_response, system.name_by_pid(test_input))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_name_pgrep(self, call_mock):
+ def test_pid_by_name_pgrep(self, call_mock):
"""
- Tests the get_pid_by_name function with pgrep responses.
+ Tests the pid_by_name function with pgrep responses.
"""
responses = dict(GET_PID_BY_NAME_BASE_RESULTS)
@@ -172,15 +172,15 @@ class TestSystem(unittest.TestCase):
for test_input in responses:
expected_response = 1111 if test_input == 'success' else None
- self.assertEquals(expected_response, system.get_pid_by_name(test_input))
+ self.assertEquals(expected_response, system.pid_by_name(test_input))
- self.assertEquals([123, 456, 789], system.get_pid_by_name('multiple_results', multiple = True))
+ self.assertEquals([123, 456, 789], system.pid_by_name('multiple_results', multiple = True))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_name_pidof(self, call_mock):
+ def test_pid_by_name_pidof(self, call_mock):
"""
- Tests the get_pid_by_name function with pidof responses.
+ Tests the pid_by_name function with pidof responses.
"""
responses = dict(GET_PID_BY_NAME_BASE_RESULTS)
@@ -190,16 +190,16 @@ class TestSystem(unittest.TestCase):
for test_input in responses:
expected_response = 1111 if test_input == 'success' else None
- self.assertEquals(expected_response, system.get_pid_by_name(test_input))
+ self.assertEquals(expected_response, system.pid_by_name(test_input))
- self.assertEquals([123, 456, 789], system.get_pid_by_name('multiple_results', multiple = True))
+ self.assertEquals([123, 456, 789], system.pid_by_name('multiple_results', multiple = True))
@patch('stem.util.system.call')
@patch('stem.util.system.is_bsd', Mock(return_value = False))
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_name_ps_linux(self, call_mock):
+ def test_pid_by_name_ps_linux(self, call_mock):
"""
- Tests the get_pid_by_name function with the linux variant of ps.
+ Tests the pid_by_name function with the linux variant of ps.
"""
responses = dict(GET_PID_BY_NAME_BASE_RESULTS)
@@ -209,32 +209,32 @@ class TestSystem(unittest.TestCase):
for test_input in responses:
expected_response = 1111 if test_input == 'success' else None
- self.assertEquals(expected_response, system.get_pid_by_name(test_input))
+ self.assertEquals(expected_response, system.pid_by_name(test_input))
- self.assertEquals([123, 456, 789], system.get_pid_by_name('multiple_results', multiple = True))
+ self.assertEquals([123, 456, 789], system.pid_by_name('multiple_results', multiple = True))
@patch('stem.util.system.call')
@patch('stem.util.system.is_bsd', Mock(return_value = True))
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_name_ps_bsd(self, call_mock):
+ def test_pid_by_name_ps_bsd(self, call_mock):
"""
- Tests the get_pid_by_name function with the bsd variant of ps.
+ Tests the pid_by_name function with the bsd variant of ps.
"""
call_mock.side_effect = mock_call(system.GET_PID_BY_NAME_PS_BSD, GET_PID_BY_NAME_PS_BSD)
- self.assertEquals(1, system.get_pid_by_name('launchd'))
- self.assertEquals(11, system.get_pid_by_name('DirectoryService'))
- self.assertEquals(None, system.get_pid_by_name('blarg'))
+ self.assertEquals(1, system.pid_by_name('launchd'))
+ self.assertEquals(11, system.pid_by_name('DirectoryService'))
+ self.assertEquals(None, system.pid_by_name('blarg'))
call_mock.side_effect = mock_call(system.GET_PID_BY_NAME_PS_BSD, GET_PID_BY_NAME_PS_BSD_MULTIPLE)
- self.assertEquals([1, 41], system.get_pid_by_name('launchd', multiple = True))
+ self.assertEquals([1, 41], system.pid_by_name('launchd', multiple = True))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_name_lsof(self, call_mock):
+ def test_pid_by_name_lsof(self, call_mock):
"""
- Tests the get_pid_by_name function with lsof responses.
+ Tests the pid_by_name function with lsof responses.
"""
responses = dict(GET_PID_BY_NAME_BASE_RESULTS)
@@ -244,69 +244,69 @@ class TestSystem(unittest.TestCase):
for test_input in responses:
expected_response = 1111 if test_input == 'success' else None
- self.assertEquals(expected_response, system.get_pid_by_name(test_input))
+ self.assertEquals(expected_response, system.pid_by_name(test_input))
- self.assertEquals([123, 456, 789], system.get_pid_by_name('multiple_results', multiple = True))
+ self.assertEquals([123, 456, 789], system.pid_by_name('multiple_results', multiple = True))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_port_netstat(self, call_mock):
+ def test_pid_by_port_netstat(self, call_mock):
"""
- Tests the get_pid_by_port function with a netstat response.
+ Tests the pid_by_port function with a netstat response.
"""
call_mock.side_effect = mock_call(system.GET_PID_BY_PORT_NETSTAT, GET_PID_BY_PORT_NETSTAT_RESULTS)
- self.assertEquals(1641, system.get_pid_by_port(9051))
- self.assertEquals(1641, system.get_pid_by_port('9051'))
- self.assertEquals(None, system.get_pid_by_port(631))
- self.assertEquals(None, system.get_pid_by_port(123))
+ self.assertEquals(1641, system.pid_by_port(9051))
+ self.assertEquals(1641, system.pid_by_port('9051'))
+ self.assertEquals(None, system.pid_by_port(631))
+ self.assertEquals(None, system.pid_by_port(123))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_port_sockstat(self, call_mock):
+ def test_pid_by_port_sockstat(self, call_mock):
"""
- Tests the get_pid_by_port function with a sockstat response.
+ Tests the pid_by_port function with a sockstat response.
"""
call_mock.side_effect = mock_call(system.GET_PID_BY_PORT_SOCKSTAT % 9051, GET_PID_BY_PORT_SOCKSTAT_RESULTS)
- self.assertEquals(4397, system.get_pid_by_port(9051))
- self.assertEquals(4397, system.get_pid_by_port('9051'))
- self.assertEquals(None, system.get_pid_by_port(123))
+ self.assertEquals(4397, system.pid_by_port(9051))
+ self.assertEquals(4397, system.pid_by_port('9051'))
+ self.assertEquals(None, system.pid_by_port(123))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_port_lsof(self, call_mock):
+ def test_pid_by_port_lsof(self, call_mock):
"""
- Tests the get_pid_by_port function with a lsof response.
+ Tests the pid_by_port function with a lsof response.
"""
call_mock.side_effect = mock_call(system.GET_PID_BY_PORT_LSOF, GET_PID_BY_PORT_LSOF_RESULTS)
- self.assertEquals(1745, system.get_pid_by_port(9051))
- self.assertEquals(1745, system.get_pid_by_port('9051'))
- self.assertEquals(329, system.get_pid_by_port(80))
- self.assertEquals(None, system.get_pid_by_port(123))
+ self.assertEquals(1745, system.pid_by_port(9051))
+ self.assertEquals(1745, system.pid_by_port('9051'))
+ self.assertEquals(329, system.pid_by_port(80))
+ self.assertEquals(None, system.pid_by_port(123))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_pid_by_open_file_lsof(self, call_mock):
+ def test_pid_by_open_file_lsof(self, call_mock):
"""
- Tests the get_pid_by_open_file function with a lsof response.
+ Tests the pid_by_open_file function with a lsof response.
"""
lsof_query = system.GET_PID_BY_FILE_LSOF % '/tmp/foo'
call_mock.side_effect = mock_call(lsof_query, ['4762'])
- self.assertEquals(4762, system.get_pid_by_open_file('/tmp/foo'))
+ self.assertEquals(4762, system.pid_by_open_file('/tmp/foo'))
call_mock.return_value = []
call_mock.side_effect = None
- self.assertEquals(None, system.get_pid_by_open_file('/tmp/somewhere_else'))
+ self.assertEquals(None, system.pid_by_open_file('/tmp/somewhere_else'))
@patch('stem.util.system.call')
@patch('stem.util.proc.is_available', Mock(return_value = False))
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_cwd_pwdx(self, call_mock):
+ def test_cwd_pwdx(self, call_mock):
"""
- Tests the get_cwd function with a pwdx response.
+ Tests the cwd function with a pwdx response.
"""
responses = {
@@ -320,14 +320,14 @@ class TestSystem(unittest.TestCase):
for test_input in responses:
expected_response = '/home/atagar' if test_input == '3799' else None
- self.assertEquals(expected_response, system.get_cwd(test_input))
+ self.assertEquals(expected_response, system.cwd(test_input))
@patch('stem.util.system.call')
@patch('stem.util.proc.is_available', Mock(return_value = False))
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_cwd_lsof(self, call_mock):
+ def test_cwd_lsof(self, call_mock):
"""
- Tests the get_cwd function with a lsof response.
+ Tests the cwd function with a lsof response.
"""
responses = {
@@ -340,13 +340,13 @@ class TestSystem(unittest.TestCase):
for test_input in responses:
expected_response = '/Users/atagar/tor/src/or' if test_input == '75717' else None
- self.assertEquals(expected_response, system.get_cwd(test_input))
+ self.assertEquals(expected_response, system.cwd(test_input))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_bsd_jail_id(self, call_mock):
+ def test_bsd_jail_id(self, call_mock):
"""
- Tests the get_bsd_jail_id function.
+ Tests the bsd_jail_id function.
"""
responses = {
@@ -362,22 +362,22 @@ class TestSystem(unittest.TestCase):
for test_input in responses:
expected_response = 1 if test_input == '1111' else 0
- self.assertEquals(expected_response, system.get_bsd_jail_id(test_input))
+ self.assertEquals(expected_response, system.bsd_jail_id(test_input))
@patch('stem.util.system.call')
@patch('stem.util.system.is_available', Mock(return_value = True))
- def test_get_bsd_jail_path(self, call_mock):
+ def test_bsd_jail_path(self, call_mock):
"""
- Tests the get_bsd_jail_path function.
+ Tests the bsd_jail_path function.
"""
# check when we don't have a jail
call_mock.return_value = []
- self.assertEquals(None, system.get_bsd_jail_path(1))
+ self.assertEquals(None, system.bsd_jail_path(1))
call_mock.side_effect = mock_call(system.GET_BSD_JAIL_PATH % '1', GET_BSD_JAIL_PATH_RESULTS)
- self.assertEquals('/usr/jails/tor-jail', system.get_bsd_jail_path(1))
+ self.assertEquals('/usr/jails/tor-jail', system.bsd_jail_path(1))
@patch('platform.system', Mock(return_value = 'Linux'))
@patch('os.path.join', Mock(side_effect = posixpath.join))
More information about the tor-commits
mailing list