[tor-commits] [stem/master] Removing test.runner.get_connection_type()
atagar at torproject.org
atagar at torproject.org
Mon Jan 16 18:10:10 UTC 2012
commit 6846ce359ede2c697688a2e143a3b3625f8a540b
Author: Damian Johnson <atagar at torproject.org>
Date: Mon Jan 16 10:09:46 2012 -0800
Removing test.runner.get_connection_type()
Integration tests used the get_connection_type() method to either query or
infer attributes about the connection it was running against. This was stupid -
they should query the attributes directly and make test assertions based on
that. The get_connection_type() value was our testing target which should
simply be a user friendly tag for a set of testing attributes. Next I'll be
moving testing targets completely from the runner so they only exist in
'run_tests.py'.
---
test/integ/connection/authentication.py | 13 +++----
test/integ/connection/connect.py | 7 +---
test/integ/connection/protocolinfo.py | 54 +++++++++++++-----------------
test/integ/util/system.py | 3 +-
test/integ/version.py | 3 +-
test/runner.py | 14 +-------
6 files changed, 33 insertions(+), 61 deletions(-)
diff --git a/test/integ/connection/authentication.py b/test/integ/connection/authentication.py
index 612e058..519e40a 100644
--- a/test/integ/connection/authentication.py
+++ b/test/integ/connection/authentication.py
@@ -30,10 +30,8 @@ class TestAuthenticate(unittest.TestCase):
"""
def setUp(self):
- connection_type = test.runner.get_runner().get_connection_type()
-
# none of these tests apply if there's no control connection
- if connection_type == test.runner.TorConnection.NONE:
+ if not test.runner.get_runner().is_accessible():
self.skipTest("(no connection)")
def test_authenticate_general(self):
@@ -51,8 +49,7 @@ class TestAuthenticate(unittest.TestCase):
Tests the authenticate function with something like its pydoc example.
"""
- connection_type = test.runner.get_runner().get_connection_type()
- connection_options = test.runner.CONNECTION_OPTS[connection_type]
+ connection_options = test.runner.get_runner().get_connection_options()
try:
control_socket = stem.socket.ControlPort(control_port = test.runner.CONTROL_PORT)
@@ -91,7 +88,8 @@ class TestAuthenticate(unittest.TestCase):
# authenticate with
runner = test.runner.get_runner()
- is_password_only = test.runner.TorConnection.PASSWORD == runner.get_connection_type()
+ connection_options = runner.get_connection_options()
+ is_password_only = test.runner.OPT_PASSWORD in connection_options and not test.runner.OPT_COOKIE in connection_options
# tests without a password
control_socket = runner.get_tor_socket(False)
@@ -248,8 +246,7 @@ class TestAuthenticate(unittest.TestCase):
bool tuple of the form (password_auth, cookie_auth)
"""
- connection_type = test.runner.get_runner().get_connection_type()
- connection_options = test.runner.CONNECTION_OPTS[connection_type]
+ connection_options = test.runner.get_runner().get_connection_options()
password_auth = test.runner.OPT_PASSWORD in connection_options
cookie_auth = test.runner.OPT_COOKIE in connection_options
diff --git a/test/integ/connection/connect.py b/test/integ/connection/connect.py
index 6b0c16e..eea07a8 100644
--- a/test/integ/connection/connect.py
+++ b/test/integ/connection/connect.py
@@ -16,10 +16,8 @@ class TestConnect(unittest.TestCase):
"""
def setUp(self):
- connection_type = test.runner.get_runner().get_connection_type()
-
# none of these tests apply if there's no control connection
- if connection_type == test.runner.TorConnection.NONE:
+ if not test.runner.get_runner().is_accessible():
self.skipTest("(no connection)")
def test_connect_port(self):
@@ -46,7 +44,6 @@ class TestConnect(unittest.TestCase):
sys.stdout = StringIO.StringIO()
try:
- connection_type = test.runner.get_runner().get_connection_type()
ctl_pw = test.runner.CONTROL_PASSWORD
controller = stem.connection.Controller.NONE
@@ -59,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.CONNECTION_OPTS[connection_type]:
+ if opt_type in test.runner.get_runner().get_connection_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 0214534..24edd04 100644
--- a/test/integ/connection/protocolinfo.py
+++ b/test/integ/connection/protocolinfo.py
@@ -27,9 +27,8 @@ class TestProtocolInfo(unittest.TestCase):
"""
runner = test.runner.get_runner()
- connection_type = runner.get_connection_type()
- if connection_type == test.runner.TorConnection.NONE:
+ if not runner.is_accessible():
self.skipTest("(no connection)")
control_socket = runner.get_tor_socket(False)
@@ -46,7 +45,7 @@ class TestProtocolInfo(unittest.TestCase):
self.assertNotEqual(None, protocolinfo_response.tor_version)
self.assertNotEqual(None, protocolinfo_response.auth_methods)
- self.assert_protocolinfo_attr(protocolinfo_response, connection_type)
+ self.assert_protocolinfo_attr(protocolinfo_response)
def test_get_protocolinfo_by_port(self):
"""
@@ -73,12 +72,11 @@ class TestProtocolInfo(unittest.TestCase):
return False
stem.util.system.CALL_MOCKING = port_lookup_filter
- connection_type = test.runner.get_runner().get_connection_type()
- if test.runner.OPT_PORT in test.runner.CONNECTION_OPTS[connection_type]:
+ if test.runner.OPT_PORT in test.runner.get_runner().get_connection_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, connection_type)
+ self.assert_protocolinfo_attr(protocolinfo_response)
# we should have a usable socket at this point
self.assertTrue(control_socket.is_alive())
@@ -105,12 +103,11 @@ class TestProtocolInfo(unittest.TestCase):
return False
stem.util.system.CALL_MOCKING = socket_lookup_filter
- connection_type = test.runner.get_runner().get_connection_type()
- if test.runner.OPT_SOCKET in test.runner.CONNECTION_OPTS[connection_type]:
+ if test.runner.OPT_SOCKET in test.runner.get_runner().get_connection_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, connection_type)
+ self.assert_protocolinfo_attr(protocolinfo_response)
# we should have a usable socket at this point
self.assertTrue(control_socket.is_alive())
@@ -127,20 +124,19 @@ class TestProtocolInfo(unittest.TestCase):
"""
runner = test.runner.get_runner()
- connection_type = runner.get_connection_type()
- if connection_type == test.runner.TorConnection.NONE:
+ if not runner.is_accessible():
self.skipTest("(no connection)")
control_socket = runner.get_tor_socket(False)
for i in range(5):
protocolinfo_response = stem.connection.get_protocolinfo(control_socket)
- self.assert_protocolinfo_attr(protocolinfo_response, connection_type)
+ self.assert_protocolinfo_attr(protocolinfo_response)
control_socket.close()
- def assert_protocolinfo_attr(self, protocolinfo_response, connection_type):
+ def assert_protocolinfo_attr(self, protocolinfo_response):
"""
Makes assertions that the protocolinfo response's attributes match those of
a given connection type.
@@ -149,28 +145,24 @@ 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. :)
- if connection_type == test.runner.TorConnection.OPEN:
- auth_methods = (stem.connection.AuthMethod.NONE,)
- elif connection_type == test.runner.TorConnection.PASSWORD:
- auth_methods = (stem.connection.AuthMethod.PASSWORD,)
- elif connection_type == test.runner.TorConnection.COOKIE:
- auth_methods = (stem.connection.AuthMethod.COOKIE,)
- elif connection_type == test.runner.TorConnection.MULTIPLE:
- auth_methods = (stem.connection.AuthMethod.COOKIE, stem.connection.AuthMethod.PASSWORD)
- elif connection_type == test.runner.TorConnection.SOCKET:
- auth_methods = (stem.connection.AuthMethod.NONE,)
- elif connection_type == test.runner.TorConnection.SCOOKIE:
- auth_methods = (stem.connection.AuthMethod.COOKIE,)
- elif connection_type == test.runner.TorConnection.PTRACE:
- auth_methods = (stem.connection.AuthMethod.NONE,)
- else:
- self.fail("Unrecognized connection type: %s" % connection_type)
+ connection_options = test.runner.get_runner().get_connection_options()
+
+ auth_methods = []
+
+ if test.runner.OPT_COOKIE in connection_options:
+ auth_methods.append(stem.connection.AuthMethod.COOKIE)
+
+ if test.runner.OPT_PASSWORD in connection_options:
+ auth_methods.append(stem.connection.AuthMethod.PASSWORD)
+
+ if not auth_methods:
+ auth_methods.append(stem.connection.AuthMethod.NONE)
self.assertEqual((), protocolinfo_response.unknown_auth_methods)
- self.assertEqual(auth_methods, protocolinfo_response.auth_methods)
+ self.assertEqual(tuple(auth_methods), protocolinfo_response.auth_methods)
auth_cookie_path = None
- if test.runner.OPT_COOKIE in test.runner.CONNECTION_OPTS[connection_type]:
+ if test.runner.OPT_COOKIE in connection_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 e06c05b..2acb488 100644
--- a/test/integ/util/system.py
+++ b/test/integ/util/system.py
@@ -319,6 +319,5 @@ class TestSystem(unittest.TestCase):
True if our test runner has a control port, False otherwise.
"""
- connection_type = runner = test.runner.get_runner().get_connection_type()
- return test.runner.OPT_PORT in test.runner.CONNECTION_OPTS[connection_type]
+ return test.runner.OPT_PORT in test.runner.get_runner().get_connection_options()
diff --git a/test/integ/version.py b/test/integ/version.py
index 9bd7ee7..9fa7fd8 100644
--- a/test/integ/version.py
+++ b/test/integ/version.py
@@ -40,9 +40,8 @@ class TestVersion(unittest.TestCase):
"""
runner = test.runner.get_runner()
- connection_type = runner.get_connection_type()
- if connection_type == test.runner.TorConnection.NONE:
+ if not runner.is_accessible():
self.skipTest("(no connection)")
control_socket = runner.get_tor_socket()
diff --git a/test/runner.py b/test/runner.py
index 4d163bf..50a1031 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -15,7 +15,6 @@ Runner - Runtime context for our integration tests.
|- 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_type - method by which controllers can connect to tor
|- 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
@@ -357,17 +356,6 @@ class Runner:
return self._get("_torrc_contents")
- def get_connection_type(self):
- """
- Provides the method we can use for connecting to the tor instance.
-
- Returns:
- test.runner.TorConnection enumeration for the method we can use for
- connecting to the tor test instance
- """
-
- return self._connection_type
-
def get_connection_options(self):
"""
Provides the connection related options we're running with.
@@ -376,7 +364,7 @@ class Runner:
list of connection contstants (test.runner.OPT_*) we're running with
"""
- return CONNECTION_OPTS[self.get_connection_type()]
+ return CONNECTION_OPTS[self._connection_type]
def get_pid(self):
"""
More information about the tor-commits
mailing list