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


Python Controller.get_pid方法代码示例

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

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

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


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