当前位置: 首页>>代码示例>>Python>>正文


Python Controller.get_user方法代码示例

本文整理汇总了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.
    """
开发者ID:Fuzew,项目名称:sharp-stem,代码行数:69,代码来源:controller.py

示例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.
    """
开发者ID:ouzel,项目名称:stem,代码行数:69,代码来源:controller.py

示例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.
    """
开发者ID:patrickod,项目名称:stem,代码行数:69,代码来源:controller.py


注:本文中的stem.control.Controller.get_user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。