Example #1
0
 def test_pid_by_port_sockstat(self, call_mock):
   """
   Tests the pid_by_port function with a sockstat response.
   """
   call_mock.side_effect = mock_call(system.GET_PID_BY_PORT_SOCKSTAT % 9051, GET_PID_BY_PORT_SOCKSTAT_RESULTS)
   self.assertEqual(4397, system.pid_by_port(9051))
   self.assertEqual(4397, system.pid_by_port('9051'))
   self.assertEqual(None, system.pid_by_port(123))
Example #2
0
 def test_pid_by_port_sockstat(self, call_mock):
   """
   Tests the pid_by_port function with a sockstat response.
   """
   call_mock.side_effect = mock_call(system.GET_PID_BY_PORT_SOCKSTAT % 9051, GET_PID_BY_PORT_SOCKSTAT_RESULTS)
   self.assertEqual(4397, system.pid_by_port(9051))
   self.assertEqual(4397, system.pid_by_port('9051'))
   self.assertEqual(None, system.pid_by_port(123))
Example #3
0
  def test_pid_by_port_lsof(self, call_mock):
    """
    Tests the pid_by_port function with a lsof response.
    """

    call_mock.side_effect = mock_call(system.GET_PID_BY_PORT_LSOF, GET_PID_BY_PORT_LSOF_RESULTS)
    self.assertEqual(1745, system.pid_by_port(9051))
    self.assertEqual(1745, system.pid_by_port('9051'))
    self.assertEqual(329, system.pid_by_port(80))
    self.assertEqual(None, system.pid_by_port(123))
Example #4
0
  def test_pid_by_port_netstat(self, call_mock):
    """
    Tests the pid_by_port function with a netstat response.
    """

    call_mock.side_effect = mock_call(system.GET_PID_BY_PORT_NETSTAT, GET_PID_BY_PORT_NETSTAT_RESULTS)
    self.assertEqual(1641, system.pid_by_port(9051))
    self.assertEqual(1641, system.pid_by_port('9051'))
    self.assertEqual(None, system.pid_by_port(631))
    self.assertEqual(None, system.pid_by_port(123))
Example #5
0
  def test_pid_by_port_lsof(self, call_mock):
    """
    Tests the pid_by_port function with a lsof response.
    """

    call_mock.side_effect = mock_call(system.GET_PID_BY_PORT_LSOF, GET_PID_BY_PORT_LSOF_RESULTS)
    self.assertEqual(1745, system.pid_by_port(9051))
    self.assertEqual(1745, system.pid_by_port('9051'))
    self.assertEqual(329, system.pid_by_port(80))
    self.assertEqual(None, system.pid_by_port(123))
Example #6
0
  def test_pid_by_port_netstat(self, call_mock):
    """
    Tests the pid_by_port function with a netstat response.
    """

    call_mock.side_effect = mock_call(system.GET_PID_BY_PORT_NETSTAT, GET_PID_BY_PORT_NETSTAT_RESULTS)
    self.assertEqual(1641, system.pid_by_port(9051))
    self.assertEqual(1641, system.pid_by_port('9051'))
    self.assertEqual(None, system.pid_by_port(631))
    self.assertEqual(None, system.pid_by_port(123))
Example #7
0
def start_tor():
  tor_process = system.pid_by_port(SOCKS_PORT)
  if  tor_process is None:
    tor_process = system.pid_by_name('tor')
  if  tor_process is None:
    tor_process = stem.process.launch_tor_with_config(
      config={
        'SocksPort': str(SOCKS_PORT),
        'ControlPort': str(CONTROL_PORT),
        'ExitNodes': '{ru}',
      },
      init_msg_handler=print_bootstrap_lines,
    )
  else:
    print "tor already running, no need to start"