commit 7214fe9a195c71a26a2829a76d0ecfa24a0cb6b8
Author: Damian Johnson <atagar(a)torproject.org>
Date: Wed Mar 8 10:59:42 2017 -0800
Drop test runner's get_tor_version()
We left a TODO comment to replace this long ago. Might as well finally get
around to it. :P
---
test/integ/connection/authentication.py | 6 +++---
test/integ/control/controller.py | 11 +++++------
test/integ/response/protocolinfo.py | 6 +++---
test/integ/socket/control_socket.py | 4 ++--
test/integ/version.py | 11 -----------
test/runner.py | 35 +++------------------------------
test/util.py | 26 +++++++++++++++++++++++-
7 files changed, 41 insertions(+), 58 deletions(-)
diff --git a/test/integ/connection/authentication.py b/test/integ/connection/authentication.py
index 3687af3..4289fac 100644
--- a/test/integ/connection/authentication.py
+++ b/test/integ/connection/authentication.py
@@ -12,6 +12,7 @@ import stem.version
import test.runner
from test.runner import require_controller
+from test.util import tor_version
# Responses given by tor for various authentication failures. These may change
# in the future and if they do then this test should be updated.
@@ -43,7 +44,7 @@ def _can_authenticate(auth_type):
tor_options = runner.get_options()
password_auth = test.runner.Torrc.PASSWORD in tor_options
cookie_auth = test.runner.Torrc.COOKIE in tor_options
- safecookie_auth = cookie_auth and runner.get_tor_version() >= stem.version.Requirement.AUTH_SAFECOOKIE
+ safecookie_auth = cookie_auth and tor_version() >= stem.version.Requirement.AUTH_SAFECOOKIE
if not password_auth and not cookie_auth:
# open socket, anything but safecookie will work
@@ -103,8 +104,7 @@ class TestAuthenticate(unittest.TestCase):
def setUp(self):
self.cookie_auth_methods = [stem.connection.AuthMethod.COOKIE]
- tor_version = test.runner.get_runner().get_tor_version()
- if tor_version >= stem.version.Requirement.AUTH_SAFECOOKIE:
+ if tor_version() >= stem.version.Requirement.AUTH_SAFECOOKIE:
self.cookie_auth_methods.append(stem.connection.AuthMethod.SAFECOOKIE)
@require_controller
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index f5c91d7..a0f9b99 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -27,7 +27,7 @@ from stem.control import EventType, Listener, State
from stem.exit_policy import ExitPolicy
from stem.version import Requirement
-from test.util import register_new_capability
+from test.util import register_new_capability, tor_version
from test.runner import (
require_controller,
@@ -273,7 +273,7 @@ class TestController(unittest.TestCase):
with runner.get_tor_controller() as controller:
version = controller.get_version()
self.assertTrue(isinstance(version, stem.version.Version))
- self.assertEqual(version, runner.get_tor_version())
+ self.assertEqual(version, tor_version())
@require_controller
def test_get_exit_policy(self):
@@ -344,13 +344,12 @@ class TestController(unittest.TestCase):
# Doing a sanity test on the ProtocolInfoResponse instance returned.
tor_options = runner.get_options()
- tor_version = runner.get_tor_version()
auth_methods = []
if test.runner.Torrc.COOKIE in tor_options:
auth_methods.append(stem.response.protocolinfo.AuthMethod.COOKIE)
- if tor_version >= stem.version.Requirement.AUTH_SAFECOOKIE:
+ if tor_version() >= stem.version.Requirement.AUTH_SAFECOOKIE:
auth_methods.append(stem.response.protocolinfo.AuthMethod.SAFECOOKIE)
if test.runner.Torrc.PASSWORD in tor_options:
@@ -1147,7 +1146,7 @@ class TestController(unittest.TestCase):
runner = test.runner.get_runner()
- if runner.get_tor_version() >= Requirement.MICRODESCRIPTOR_IS_DEFAULT:
+ if tor_version() >= Requirement.MICRODESCRIPTOR_IS_DEFAULT:
test.runner.skip(self, '(requires server descriptors)')
return
@@ -1177,7 +1176,7 @@ class TestController(unittest.TestCase):
runner = test.runner.get_runner()
- if runner.get_tor_version() >= Requirement.MICRODESCRIPTOR_IS_DEFAULT:
+ if tor_version() >= Requirement.MICRODESCRIPTOR_IS_DEFAULT:
test.runner.skip(self, '(requires server descriptors)')
return
diff --git a/test/integ/response/protocolinfo.py b/test/integ/response/protocolinfo.py
index b2ecd2c..5c2c092 100644
--- a/test/integ/response/protocolinfo.py
+++ b/test/integ/response/protocolinfo.py
@@ -11,8 +11,9 @@ import stem.util.system
import stem.version
import test.runner
-from test.runner import require_controller
from test.integ.util.system import filter_system_call
+from test.runner import require_controller
+from test.util import tor_version
try:
# added in python 3.3
@@ -126,13 +127,12 @@ class TestProtocolInfo(unittest.TestCase):
runner = test.runner.get_runner()
tor_options = runner.get_options()
- tor_version = runner.get_tor_version()
auth_methods, auth_cookie_path = [], None
if test.runner.Torrc.COOKIE in tor_options:
auth_methods.append(stem.response.protocolinfo.AuthMethod.COOKIE)
- if tor_version >= stem.version.Requirement.AUTH_SAFECOOKIE:
+ if tor_version() >= stem.version.Requirement.AUTH_SAFECOOKIE:
auth_methods.append(stem.response.protocolinfo.AuthMethod.SAFECOOKIE)
chroot_path = runner.get_chroot()
diff --git a/test/integ/socket/control_socket.py b/test/integ/socket/control_socket.py
index a1e603b..1a8b50a 100644
--- a/test/integ/socket/control_socket.py
+++ b/test/integ/socket/control_socket.py
@@ -17,6 +17,7 @@ import stem.socket
import test.runner
from test.runner import require_controller
+from test.util import tor_version
class TestControlSocket(unittest.TestCase):
@@ -61,7 +62,6 @@ class TestControlSocket(unittest.TestCase):
"""
runner = test.runner.get_runner()
- tor_version = runner.get_tor_version()
with runner.get_tor_socket() as control_socket:
for _ in range(100):
@@ -69,7 +69,7 @@ class TestControlSocket(unittest.TestCase):
for _ in range(100):
response = control_socket.recv()
- self.assertTrue(str(response).startswith('version=%s' % tor_version))
+ self.assertTrue(str(response).startswith('version=%s' % tor_version()))
self.assertTrue(str(response).endswith('\nOK'))
@require_controller
diff --git a/test/integ/version.py b/test/integ/version.py
index 7ba8e7a..57e469c 100644
--- a/test/integ/version.py
+++ b/test/integ/version.py
@@ -35,17 +35,6 @@ class TestVersion(unittest.TestCase):
self.assertRaises(IOError, stem.version.get_system_tor_version, 'blarg')
@require_controller
- def test_get_system_tor_version_value(self):
- """
- Checks that the get_system_tor_version() provides the same value as our
- test instance provides.
- """
-
- runner = test.runner.get_runner()
- system_tor_version = stem.version.get_system_tor_version(runner.get_tor_command())
- self.assertEqual(runner.get_tor_version(), system_tor_version)
-
- @require_controller
def test_getinfo_version_parsing(self):
"""
Issues a 'GETINFO version' query to our test instance and makes sure that
diff --git a/test/runner.py b/test/runner.py
index 8ab65f6..a5d39d6 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -35,7 +35,6 @@ about the tor test instance they're running against.
|- get_pid - process id of our tor process
|- get_tor_socket - provides a socket to our test instance
|- get_tor_controller - provides a controller for our test instance
- |- get_tor_version - provides the version of tor we're running against
+- get_tor_command - provides the command used to start tor
"""
@@ -57,7 +56,7 @@ import stem.util.enum
import stem.version
from test.output import println, STATUS, ERROR, SUBSTATUS, NO_NL
-from test.util import Target, STEM_BASE
+from test.util import Target, STEM_BASE, tor_version
CONFIG = stem.util.conf.config_dict('test', {
'integ.test_directory': './test/data',
@@ -139,7 +138,7 @@ def require_version(req_version):
def decorator(func):
def wrapped(self, *args, **kwargs):
- if get_runner().get_tor_version() >= req_version:
+ if tor_version() >= req_version:
return func(self, *args, **kwargs)
else:
skip(self, '(requires %s)' % req_version)
@@ -414,8 +413,7 @@ class Runner(object):
# If we're running a tor version where ptrace is disabled and we didn't
# set 'DisableDebuggerAttachment=1' then we can infer that it's disabled.
- tor_version = self.get_tor_version()
- has_option = tor_version >= stem.version.Requirement.TORRC_DISABLE_DEBUGGER_ATTACHMENT
+ has_option = tor_version() >= stem.version.Requirement.TORRC_DISABLE_DEBUGGER_ATTACHMENT
return not has_option or Torrc.PTRACE in self.get_options()
def get_options(self):
@@ -558,33 +556,6 @@ class Runner(object):
return controller
- def get_tor_version(self):
- """
- Queries our test instance for tor's version.
-
- :returns: :class:`stem.version.Version` for our test instance
- """
-
- try:
- # TODO: replace with higher level functions when we've completed a basic
- # controller class
-
- control_socket = self.get_tor_socket()
-
- control_socket.send('GETINFO version')
- version_response = control_socket.recv()
- control_socket.close()
-
- tor_version = list(version_response)[0]
- tor_version = tor_version[8:]
-
- if ' ' in tor_version:
- tor_version = tor_version.split(' ', 1)[0]
-
- return stem.version.Version(tor_version)
- except TorInaccessable:
- return stem.version.get_system_tor_version(self.get_tor_command())
-
def get_tor_command(self, base_cmd = False):
"""
Provides the command used to run our tor instance.
diff --git a/test/util.py b/test/util.py
index 092d8d6..2a58e2f 100644
--- a/test/util.py
+++ b/test/util.py
@@ -78,6 +78,8 @@ Target = stem.util.enum.UppercaseEnum(
'RUN_ALL',
)
+TOR_VERSION = None
+
# We make some paths relative to stem's base directory (the one above us)
# rather than the process' cwd. This doesn't end with a slash.
@@ -208,7 +210,12 @@ def check_stem_version():
def check_tor_version(tor_path):
- return str(stem.version.get_system_tor_version(tor_path)).split()[0]
+ global TOR_VERSION
+
+ if TOR_VERSION is None:
+ TOR_VERSION = stem.version.get_system_tor_version(tor_path)
+
+ return str(TOR_VERSION).split()[0]
def check_python_version():
@@ -354,6 +361,23 @@ def run_tasks(category, *tasks):
println()
+def tor_version():
+ """
+ Provides the version of tor we're testing against.
+
+ :returns: :class:`~stem.version.Version` of tor invoked by our integration
+ tests
+
+ :raise: **ValueError** if :func:`~test.util.check_tor_version` isn't called
+ first
+ """
+
+ if TOR_VERSION is None:
+ raise ValueError('BUG: check_tor_version() must be called before tor_version()')
+
+ return TOR_VERSION
+
+
class Task(object):
"""
Task we can process while running our tests. The runner can return either a