示例#1
0
文件: system.py 项目: patrickod/stem
  def test_cwd_pwdx(self, call_mock):
    """
    Tests the cwd function with a pwdx response.
    """
    responses = {
      '3799': ['3799: /home/atagar'],
      '5839': ['5839: No such process'],
      '1234': ['malformed output'],
      '7878': None,
    }

    call_mock.side_effect = mock_call(system.GET_CWD_PWDX, responses)

    for test_input in responses:
      expected_response = '/home/atagar' if test_input == '3799' else None
      self.assertEqual(expected_response, system.cwd(test_input))
示例#2
0
文件: system.py 项目: rl1987/stem
    def test_cwd_pwdx(self, call_mock):
        """
    Tests the cwd function with a pwdx response.
    """
        responses = {
            '3799': ['3799: /home/atagar'],
            '5839': ['5839: No such process'],
            '1234': ['malformed output'],
            '7878': None,
        }

        call_mock.side_effect = mock_call(system.GET_CWD_PWDX, responses)

        for test_input in responses:
            expected_response = '/home/atagar' if test_input == '3799' else None
            self.assertEqual(expected_response, system.cwd(test_input))
示例#3
0
    def test_cwd_lsof(self, call_mock):
        """
    Tests the cwd function with a lsof response.
    """

        responses = {
            '75717': ['p75717', 'n/Users/atagar/tor/src/or'],
            '1234': ['malformed output'],
            '7878': [],
        }

        call_mock.side_effect = mock_call(system.GET_CWD_LSOF, responses)

        for test_input in responses:
            expected_response = '/Users/atagar/tor/src/or' if test_input == '75717' else None
            self.assertEqual(expected_response, system.cwd(test_input))
示例#4
0
  def test_cwd_lsof(self, call_mock):
    """
    Tests the cwd function with a lsof response.
    """

    responses = {
      '75717': ['p75717', 'n/Users/atagar/tor/src/or'],
      '1234': ['malformed output'],
      '7878': [],
    }

    call_mock.side_effect = mock_call(system.GET_CWD_LSOF, responses)

    for test_input in responses:
      expected_response = '/Users/atagar/tor/src/or' if test_input == '75717' else None
      self.assertEqual(expected_response, system.cwd(test_input))
示例#5
0
def get_config_location():
  """
  Provides the location of the torrc, raising an IOError with the reason if the
  path can't be determined.
  """

  controller = tor_controller()
  config_location = controller.get_info('config-file', None)
  tor_pid, tor_prefix = controller.controller.get_pid(None), CONFIG['tor.chroot']

  if not config_location:
    raise IOError('unable to query the torrc location')

  try:
    tor_cwd = system.cwd(tor_pid)
    return tor_prefix + system.expand_path(config_location, tor_cwd)
  except IOError as exc:
    raise IOError("querying tor's pwd failed because %s" % exc)