commit 29652d978ce7465f288575061c819e77a7e67013 Author: Damian Johnson atagar@torproject.org Date: Mon Jan 2 16:42:14 2012 -0800
Dropping get_system_tor_version() usage from tests
At one point our integ tests was using the get_system_tor_version() function to determine our test instance's version. This is fine for now since we run against whatever tor binary is first in our path, but in the future tor devs will want to be able to select the binary so that won't work.
Adding a test runner method for querying our version from tor instead. --- test/integ/socket/control_message.py | 13 ++++--------- test/runner.py | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/test/integ/socket/control_message.py b/test/integ/socket/control_message.py index b939c87..90ac623 100644 --- a/test/integ/socket/control_message.py +++ b/test/integ/socket/control_message.py @@ -120,16 +120,12 @@ class TestControlMessage(unittest.TestCase): Parses the 'GETINFO config-text' response. """
+ runner = test.runner.get_runner() req_version = stem.version.Requirement.GETINFO_CONFIG_TEXT + our_version = runner.get_tor_version()
- try: - if stem.version.get_system_tor_version() < req_version: - self.skipTest("(requires %s)" % req_version) - except IOError: - # This is a best-effot lookup to avoid showing a valid failure. If the - # version lookup fails then running the test. - - pass + if our_version and our_version < req_version: + self.skipTest("(requires %s)" % req_version)
# We can't be certain of the order, and there may be extra config-text # entries as per... @@ -137,7 +133,6 @@ class TestControlMessage(unittest.TestCase): # # so we'll just check that the response is a superset of our config
- runner = test.runner.get_runner() torrc_contents = []
for line in runner.get_torrc_contents().split("\n"): diff --git a/test/runner.py b/test/runner.py index ed92126..581f95a 100644 --- a/test/runner.py +++ b/test/runner.py @@ -15,7 +15,8 @@ Runner - Runtime context for our integration tests. |- get_torrc_contents - contents of our tor instance's torrc |- get_connection_type - method by which controllers can connect to tor |- get_pid - process id of our tor process - +- get_tor_socket - provides a socket to the tor instance + |- get_tor_socket - provides a socket to the tor instance + +- get_tor_version - provides the version of tor we're running against """
import os @@ -30,6 +31,7 @@ import threading
import stem.socket import stem.process +import stem.version import stem.util.conf import stem.util.enum import stem.util.term as term @@ -365,6 +367,28 @@ class Runner:
return control_socket
+ def get_tor_version(self): + """ + Queries our test instance for tor's version. + + Returns: + stem.version.Version for our test instance, None if we're unable to + connect to it + """ + + # TODO: replace with higher level functions when we've completed a basic + # controller class + + control_socket = self.get_tor_socket() + if not control_socket: return None + + control_socket.send("GETINFO version") + version_response = control_socket.recv() + control_socket.close() + + tor_version = list(version_response)[0][8:] + return stem.version.Version(tor_version) + def _get(self, attr): """ Fetches one of our attributes in a thread safe manner, raising if we aren't
tor-commits@lists.torproject.org