本文整理汇总了Python中stem.control.Controller.get_pid方法的典型用法代码示例。如果您正苦于以下问题:Python Controller.get_pid方法的具体用法?Python Controller.get_pid怎么用?Python Controller.get_pid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stem.control.Controller
的用法示例。
在下文中一共展示了Controller.get_pid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestControl
# 需要导入模块: from stem.control import Controller [as 别名]
# 或者: from stem.control.Controller import get_pid [as 别名]
#.........这里部分代码省略.........
# no default value, accept the error
self.assertRaises(ProtocolError, self.controller.get_protocolinfo)
@patch("stem.socket.ControlSocket.is_localhost", Mock(return_value=False))
def test_get_user_remote(self):
"""
Exercise the get_user() method for a non-local socket.
"""
self.assertRaises(ValueError, self.controller.get_user)
self.assertEqual(123, self.controller.get_user(123))
@patch("stem.socket.ControlSocket.is_localhost", Mock(return_value=True))
@patch("stem.control.Controller.get_info", Mock(return_value="atagar"))
def test_get_user_by_getinfo(self):
"""
Exercise the get_user() resolution via its getinfo option.
"""
self.assertEqual("atagar", self.controller.get_user())
@patch("stem.socket.ControlSocket.is_localhost", Mock(return_value=True))
@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.
"""
self.assertEqual("atagar", self.controller.get_user())
@patch("stem.socket.ControlSocket.is_localhost", Mock(return_value=False))
def test_get_pid_remote(self):
"""
Exercise the get_pid() method for a non-local socket.
"""
self.assertRaises(ValueError, self.controller.get_pid)
self.assertEqual(123, self.controller.get_pid(123))
@patch("stem.socket.ControlSocket.is_localhost", Mock(return_value=True))
@patch("stem.control.Controller.get_info", Mock(return_value="321"))
def test_get_pid_by_getinfo(self):
"""
Exercise the get_pid() resolution via its getinfo option.
"""
self.assertEqual(321, self.controller.get_pid())
@patch("stem.socket.ControlSocket.is_localhost", Mock(return_value=True))
@patch("stem.control.Controller.get_conf")
@patch("stem.control.open", create=True)
def test_get_pid_by_pid_file(self, open_mock, get_conf_mock):
"""
Exercise the get_pid() resolution via a PidFile.
"""
get_conf_mock.return_value = "/tmp/pid_file"
open_mock.return_value = io.BytesIO(b"432")
self.assertEqual(432, self.controller.get_pid())
open_mock.assert_called_once_with("/tmp/pid_file")
@patch("stem.socket.ControlSocket.is_localhost", Mock(return_value=True))
@patch("stem.util.system.pid_by_name", Mock(return_value=432))
示例2: TestControl
# 需要导入模块: from stem.control import Controller [as 别名]
# 或者: from stem.control.Controller import get_pid [as 别名]
#.........这里部分代码省略.........
get_protocolinfo_mock.side_effect = ProtocolError
# get a default value when the call fails
self.assertEqual(
"default returned",
self.controller.get_protocolinfo(default = "default returned")
)
# no default value, accept the error
self.assertRaises(ProtocolError, self.controller.get_protocolinfo)
@patch('stem.socket.ControlSocket.is_localhost', Mock(return_value = False))
def test_get_user_remote(self):
"""
Exercise the get_user() method for a non-local socket.
"""
self.assertRaises(ValueError, self.controller.get_user)
self.assertEqual(123, self.controller.get_user(123))
@patch('stem.socket.ControlSocket.is_localhost', Mock(return_value = True))
@patch('stem.control.Controller.get_info', Mock(return_value = 'atagar'))
def test_get_user_by_getinfo(self):
"""
Exercise the get_user() resolution via its getinfo option.
"""
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'))
def test_get_user_by_system(self):
"""
Exercise the get_user() resolution via the system module.
"""
self.assertEqual('atagar', self.controller.get_user())
@patch('stem.socket.ControlSocket.is_localhost', Mock(return_value = False))
def test_get_pid_remote(self):
"""
Exercise the get_pid() method for a non-local socket.
"""
self.assertRaises(ValueError, self.controller.get_pid)
self.assertEqual(123, self.controller.get_pid(123))
@patch('stem.socket.ControlSocket.is_localhost', Mock(return_value = True))
@patch('stem.control.Controller.get_info', Mock(return_value = '321'))
def test_get_pid_by_getinfo(self):
"""
Exercise the get_pid() resolution via its getinfo option.
"""
self.assertEqual(321, self.controller.get_pid())
@patch('stem.socket.ControlSocket.is_localhost', Mock(return_value = True))
@patch('stem.control.Controller.get_conf')
@patch('stem.control.open', create = True)
def test_get_pid_by_pid_file(self, open_mock, get_conf_mock):
"""
Exercise the get_pid() resolution via a PidFile.
示例3: TestControl
# 需要导入模块: from stem.control import Controller [as 别名]
# 或者: from stem.control.Controller import get_pid [as 别名]
#.........这里部分代码省略.........
# no default value, accept the error
self.assertRaises(ProtocolError, self.controller.get_protocolinfo)
@patch('stem.socket.ControlSocket.is_localhost', Mock(return_value = False))
def test_get_user_remote(self):
"""
Exercise the get_user() method for a non-local socket.
"""
self.assertRaises(ValueError, self.controller.get_user)
self.assertEqual(123, self.controller.get_user(123))
@patch('stem.socket.ControlSocket.is_localhost', Mock(return_value = True))
@patch('stem.control.Controller.get_info', Mock(return_value = 'atagar'))
def test_get_user_by_getinfo(self):
"""
Exercise the get_user() resolution via its getinfo option.
"""
self.assertEqual('atagar', self.controller.get_user())
@patch('stem.socket.ControlSocket.is_localhost', Mock(return_value = True))
@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.
"""
self.assertEqual('atagar', self.controller.get_user())
@patch('stem.socket.ControlSocket.is_localhost', Mock(return_value = False))
def test_get_pid_remote(self):
"""
Exercise the get_pid() method for a non-local socket.
"""
self.assertRaises(ValueError, self.controller.get_pid)
self.assertEqual(123, self.controller.get_pid(123))
@patch('stem.socket.ControlSocket.is_localhost', Mock(return_value = True))
@patch('stem.control.Controller.get_info', Mock(return_value = '321'))
def test_get_pid_by_getinfo(self):
"""
Exercise the get_pid() resolution via its getinfo option.
"""
self.assertEqual(321, self.controller.get_pid())
@patch('stem.socket.ControlSocket.is_localhost', Mock(return_value = True))
@patch('stem.control.Controller.get_conf')
@patch('stem.control.open', create = True)
def test_get_pid_by_pid_file(self, open_mock, get_conf_mock):
"""
Exercise the get_pid() resolution via a PidFile.
"""
get_conf_mock.return_value = '/tmp/pid_file'
open_mock.return_value = io.BytesIO(b'432')
self.assertEqual(432, self.controller.get_pid())
open_mock.assert_called_once_with('/tmp/pid_file')
@patch('stem.socket.ControlSocket.is_localhost', Mock(return_value = True))
@patch('stem.util.system.pid_by_name', Mock(return_value = 432))