def test_get_cwd_lsof(self): """ Tests the get_cwd function with a lsof response. """ responses = {"75717": ["p75717", "n/Users/atagar/tor/src/or"], "1234": ["malformed output"], "7878": None} mocking.mock(system.call, 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.assertEquals(expected_response, system.get_cwd(test_input))
def getConfigLocation(): """ Provides the location of the torrc, raising an IOError with the reason if the path can't be determined. """ conn = torTools.getConn() configLocation = conn.getInfo("config-file", None) torPid, torPrefix = conn.getMyPid(), conn.getPathPrefix() if not configLocation: raise IOError("unable to query the torrc location") try: torCwd = system.get_cwd(torPid) return torPrefix + system.expand_path(configLocation, torCwd) except IOError, exc: raise IOError("querying tor's pwd failed because %s" % exc)
def test_get_cwd_lsof(self): """ Tests the get_cwd function with a lsof response. """ responses = { "75717": ["p75717", "n/Users/atagar/tor/src/or"], "1234": ["malformed output"], "7878": None, } mocking.mock(system.call, 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.assertEquals(expected_response, system.get_cwd(test_input))
def test_get_cwd_lsof(self, call_mock): """ Tests the get_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.assertEquals(expected_response, system.get_cwd(test_input))
def test_get_cwd_pwdx(self): """ Tests the get_cwd function with a pwdx response. """ responses = { "3799": ["3799: /home/atagar"], "5839": ["5839: No such process"], "1234": ["malformed output"], "7878": None, } mocking.mock(system.call, mock_call(system.GET_CWD_PWDX, responses)) for test_input in responses: expected_response = "/home/atagar" if test_input == "3799" else None self.assertEquals(expected_response, system.get_cwd(test_input))
def test_get_cwd_pwdx(self, call_mock): """ Tests the get_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.assertEquals(expected_response, system.get_cwd(test_input))