commit 6c275ae49fae5ca45c8e596b6119841458a95fb6 Author: Damian Johnson atagar@torproject.org Date: Sat Jan 21 22:37:24 2012 -0800
Renaming get_connection_options() to get_options()
The Runner.get_connection_options() method is no longer really connection torrc options, but rather all custom options for our instance. This is frequently used so having a shorter name is nice to have, too. --- test/integ/connection/authentication.py | 16 ++++++------ test/integ/connection/connect.py | 2 +- test/integ/connection/protocolinfo.py | 12 ++++---- test/integ/util/system.py | 2 +- test/runner.py | 41 ++++++++++++++---------------- 5 files changed, 35 insertions(+), 38 deletions(-)
diff --git a/test/integ/connection/authentication.py b/test/integ/connection/authentication.py index 0388f79..e84542f 100644 --- a/test/integ/connection/authentication.py +++ b/test/integ/connection/authentication.py @@ -49,13 +49,13 @@ class TestAuthenticate(unittest.TestCase): Tests the authenticate function with something like its pydoc example. """
- connection_options = test.runner.get_runner().get_connection_options() + tor_options = test.runner.get_runner().get_options()
try: control_socket = stem.socket.ControlPort(control_port = test.runner.CONTROL_PORT) except stem.socket.SocketError: # assert that we didn't have a socket to connect to - self.assertFalse(test.runner.Torrc.PORT in connection_options) + self.assertFalse(test.runner.Torrc.PORT in tor_options) return
try: @@ -65,7 +65,7 @@ class TestAuthenticate(unittest.TestCase): except stem.connection.IncorrectSocketType: self.fail() except stem.connection.MissingPassword: - self.assertTrue(test.runner.Torrc.PASSWORD in connection_options) + self.assertTrue(test.runner.Torrc.PASSWORD in tor_options) controller_password = test.runner.CONTROL_PASSWORD
try: @@ -88,8 +88,8 @@ class TestAuthenticate(unittest.TestCase): # authenticate with
runner = test.runner.get_runner() - connection_options = runner.get_connection_options() - is_password_only = test.runner.Torrc.PASSWORD in connection_options and not test.runner.Torrc.COOKIE in connection_options + tor_options = runner.get_options() + is_password_only = test.runner.Torrc.PASSWORD in tor_options and not test.runner.Torrc.COOKIE in tor_options
# tests without a password control_socket = runner.get_tor_socket(False) @@ -246,9 +246,9 @@ class TestAuthenticate(unittest.TestCase): bool tuple of the form (password_auth, cookie_auth) """
- connection_options = test.runner.get_runner().get_connection_options() - password_auth = test.runner.Torrc.PASSWORD in connection_options - cookie_auth = test.runner.Torrc.COOKIE in connection_options + tor_options = test.runner.get_runner().get_options() + password_auth = test.runner.Torrc.PASSWORD in tor_options + cookie_auth = test.runner.Torrc.COOKIE in tor_options
return password_auth, cookie_auth
diff --git a/test/integ/connection/connect.py b/test/integ/connection/connect.py index 1264e9e..d67f702 100644 --- a/test/integ/connection/connect.py +++ b/test/integ/connection/connect.py @@ -56,7 +56,7 @@ class TestConnect(unittest.TestCase): ctl_socket = test.runner.CONTROL_SOCKET_PATH control_socket = stem.connection.connect_socket_file(socket_path = ctl_socket, password = ctl_pw, controller = controller)
- if opt_type in test.runner.get_runner().get_connection_options(): + if opt_type in test.runner.get_runner().get_options(): test.runner.exercise_socket(self, control_socket) control_socket.close() else: diff --git a/test/integ/connection/protocolinfo.py b/test/integ/connection/protocolinfo.py index c9b4992..76ef38e 100644 --- a/test/integ/connection/protocolinfo.py +++ b/test/integ/connection/protocolinfo.py @@ -73,7 +73,7 @@ class TestProtocolInfo(unittest.TestCase):
stem.util.system.CALL_MOCKING = port_lookup_filter
- if test.runner.Torrc.PORT in test.runner.get_runner().get_connection_options(): + if test.runner.Torrc.PORT in test.runner.get_runner().get_options(): control_socket = stem.socket.ControlPort(control_port = test.runner.CONTROL_PORT) protocolinfo_response = stem.connection.get_protocolinfo(control_socket) self.assert_protocolinfo_attr(protocolinfo_response) @@ -104,7 +104,7 @@ class TestProtocolInfo(unittest.TestCase):
stem.util.system.CALL_MOCKING = socket_lookup_filter
- if test.runner.Torrc.SOCKET in test.runner.get_runner().get_connection_options(): + if test.runner.Torrc.SOCKET in test.runner.get_runner().get_options(): control_socket = stem.socket.ControlSocketFile(test.runner.CONTROL_SOCKET_PATH) protocolinfo_response = stem.connection.get_protocolinfo(control_socket) self.assert_protocolinfo_attr(protocolinfo_response) @@ -145,14 +145,14 @@ class TestProtocolInfo(unittest.TestCase): # This should never have test.runner.TorConnection.NONE. If we somehow got # a protocolinfo_response from that config then we have an issue. :)
- connection_options = test.runner.get_runner().get_connection_options() + tor_options = test.runner.get_runner().get_options()
auth_methods = []
- if test.runner.Torrc.COOKIE in connection_options: + if test.runner.Torrc.COOKIE in tor_options: auth_methods.append(stem.connection.AuthMethod.COOKIE)
- if test.runner.Torrc.PASSWORD in connection_options: + if test.runner.Torrc.PASSWORD in tor_options: auth_methods.append(stem.connection.AuthMethod.PASSWORD)
if not auth_methods: @@ -162,7 +162,7 @@ class TestProtocolInfo(unittest.TestCase): self.assertEqual(tuple(auth_methods), protocolinfo_response.auth_methods)
auth_cookie_path = None - if test.runner.Torrc.COOKIE in connection_options: + if test.runner.Torrc.COOKIE in tor_options: auth_cookie_path = test.runner.get_runner().get_auth_cookie_path()
self.assertEqual(auth_cookie_path, protocolinfo_response.cookie_path) diff --git a/test/integ/util/system.py b/test/integ/util/system.py index ecf88d5..986734e 100644 --- a/test/integ/util/system.py +++ b/test/integ/util/system.py @@ -319,5 +319,5 @@ class TestSystem(unittest.TestCase): True if our test runner has a control port, False otherwise. """
- return test.runner.Torrc.PORT in test.runner.get_runner().get_connection_options() + return test.runner.Torrc.PORT in test.runner.get_runner().get_options()
diff --git a/test/runner.py b/test/runner.py index 31e3815..5719e67 100644 --- a/test/runner.py +++ b/test/runner.py @@ -4,6 +4,7 @@ to start and stop tor, and by the integration tests themselves for information about the tor test instance they're running against.
RunnerStopped - Runner doesn't have an active tor instance. +TorInaccessable - Tor can't be queried for the information.
get_runner - Singleton for fetching our runtime context. Runner - Runtime context for our integration tests. @@ -12,10 +13,10 @@ Runner - Runtime context for our integration tests. |- is_running - checks if our tor test instance is running |- is_accessible - checks if our tor instance can be connected to |- is_ptraceable - checks if DisableDebuggerAttachment is set + |- get_options - custom torrc options used for our test instance |- get_test_dir - testing directory path |- get_torrc_path - path to our tor instance's torrc |- get_torrc_contents - contents of our tor instance's torrc - |- get_connection_options - connection related options we're running with |- get_pid - process id of our tor process |- get_tor_socket - provides a socket to the tor instance +- get_tor_version - provides the version of tor we're running against @@ -124,7 +125,7 @@ class Runner: self._test_dir = "" self._tor_cwd = "" self._torrc_contents = "" - self._extra_torrc_opts = None + self._custom_opts = None self._tor_process = None
def start(self, tor_cmd, extra_torrc_opts, quiet = False): @@ -172,7 +173,7 @@ class Runner: os.chdir(tor_cwd) data_dir_path = "./%s" % os.path.basename(self._test_dir)
- self._extra_torrc_opts = extra_torrc_opts + self._custom_opts = extra_torrc_opts self._torrc_contents = get_torrc(extra_torrc_opts) % data_dir_path
try: @@ -211,7 +212,7 @@ class Runner: self._test_dir = "" self._tor_cwd = "" self._torrc_contents = "" - self._extra_torrc_opts = None + self._custom_opts = None self._tor_process = None
_print_status("done\n", STATUS_ATTR, quiet) @@ -249,8 +250,7 @@ class Runner: True if tor has a control socket or port, False otherwise """
- conn_opts = self.get_connection_options() - return Torrc.PORT in conn_opts or Torrc.SOCKET in conn_opts + return Torrc.PORT in self._custom_opts or Torrc.SOCKET in self._custom_opts
def is_ptraceable(self): """ @@ -273,6 +273,16 @@ class Runner:
return str(getconf_response) != "DisableDebuggerAttachment=1"
+ def get_options(self): + """ + Provides the custom torrc options our tor instance is running with. + + Returns: + list of Torrc enumerations being used by our test instance + """ + + return self._custom_opts + def get_test_dir(self): """ Provides the absolute path for our testing directory. @@ -334,17 +344,6 @@ class Runner:
return self._get("_torrc_contents")
- def get_connection_options(self): - """ - Provides the connection related options we're running with. - - Returns: - list of connection contstants (test.runner.OPT_*) we're running with - """ - - # TODO: rename function - return self._extra_torrc_opts - def get_pid(self): """ Provides the process id of the tor process. @@ -373,11 +372,9 @@ class Runner: TorInaccessable if tor can't be connected to """
- conn_opts = self.get_connection_options() - - if Torrc.PORT in conn_opts: + if Torrc.PORT in self._custom_opts: control_socket = stem.socket.ControlPort(control_port = CONTROL_PORT) - elif Torrc.SOCKET in conn_opts: + elif Torrc.SOCKET in self._custom_opts: control_socket = stem.socket.ControlSocketFile(CONTROL_SOCKET_PATH) else: raise TorInaccessable("Unable to connect to tor")
@@ -462,7 +459,7 @@ class Runner: # resides in is only accessable by the tor user (and refuses to finish # starting if it isn't).
- if Torrc.SOCKET in self.get_connection_options(): + if Torrc.SOCKET in self._custom_opts: try: socket_dir = os.path.dirname(CONTROL_SOCKET_PATH) _print_status(" making control socket directory (%s)... " % socket_dir, STATUS_ATTR, quiet)
tor-commits@lists.torproject.org