本文整理汇总了Python中stem.control.Controller.get_user方法的典型用法代码示例。如果您正苦于以下问题:Python Controller.get_user方法的具体用法?Python Controller.get_user怎么用?Python Controller.get_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stem.control.Controller
的用法示例。
在下文中一共展示了Controller.get_user方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestControl
# 需要导入模块: from stem.control import Controller [as 别名]
# 或者: from stem.control.Controller import get_user [as 别名]
#.........这里部分代码省略.........
get_info_mock.side_effect = ControllerError("nope, too bad")
self.assertRaises(ControllerError, self.controller.get_accounting_stats)
self.assertEqual("my default", self.controller.get_accounting_stats("my default"))
@patch("stem.connection.get_protocolinfo")
def test_get_protocolinfo(self, get_protocolinfo_mock):
"""
Exercises the get_protocolinfo() method.
"""
# use the handy mocked protocolinfo response
get_protocolinfo_mock.return_value = mocking.get_protocolinfo_response()
# compare the str representation of these object, because the class
# does not have, nor need, a direct comparison operator
self.assertEqual(str(mocking.get_protocolinfo_response()), str(self.controller.get_protocolinfo()))
# raise an exception in the stem.connection.get_protocolinfo() call
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.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.
"""
示例2: TestControl
# 需要导入模块: from stem.control import Controller [as 别名]
# 或者: from stem.control.Controller import get_user [as 别名]
#.........这里部分代码省略.........
def test_get_protocolinfo(self, get_protocolinfo_mock):
"""
Exercises the get_protocolinfo() method.
"""
# use the handy mocked protocolinfo response
get_protocolinfo_mock.return_value = mocking.get_protocolinfo_response()
# compare the str representation of these object, because the class
# does not have, nor need, a direct comparison operator
self.assertEqual(
str(mocking.get_protocolinfo_response()),
str(self.controller.get_protocolinfo())
)
# raise an exception in the stem.connection.get_protocolinfo() call
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.
"""
示例3: TestControl
# 需要导入模块: from stem.control import Controller [as 别名]
# 或者: from stem.control.Controller import get_user [as 别名]
#.........这里部分代码省略.........
"""
Exercises the get_protocolinfo() method.
"""
# use the handy mocked protocolinfo response
protocolinfo_msg = ControlMessage.from_str('250-PROTOCOLINFO 1\r\n250 OK\r\n', 'PROTOCOLINFO')
get_protocolinfo_mock.return_value = protocolinfo_msg
# compare the str representation of these object, because the class
# does not have, nor need, a direct comparison operator
self.assertEqual(
str(protocolinfo_msg),
str(self.controller.get_protocolinfo())
)
# raise an exception in the stem.connection.get_protocolinfo() call
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.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.
"""