[tor-commits] [stem/master] Minor runner refactoring

atagar at torproject.org atagar at torproject.org
Sun Jan 22 08:06:28 UTC 2012


commit fa934a0c842b86788203199e7dff57a85d7c5387
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Jan 21 23:07:04 2012 -0800

    Minor runner refactoring
    
    Messing with the order, dropping the get_torrc function, and using STEM_BASE
    rather than figuring this out again in 'run_tests.py'.
---
 run_tests.py   |    7 +++----
 test/runner.py |   51 +++++++++++++++++++++++----------------------------
 2 files changed, 26 insertions(+), 32 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index 22b0488..be0080b 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -115,9 +115,7 @@ def print_logging(logging_buffer):
 
 if __name__ == '__main__':
   # loads the builtin testing configuration
-  stem_path = os.path.join(*os.path.split(__file__)[:-1])
-  stem_path = stem.util.system.expand_path(stem_path)
-  settings_path = os.path.join(stem_path, "test", "settings.cfg")
+  settings_path = os.path.join(test.runner.STEM_BASE, "test", "settings.cfg")
   
   test_config = stem.util.conf.get_config("test")
   test_config.load(settings_path)
@@ -323,7 +321,8 @@ if __name__ == '__main__':
       print
       
       for target in skip_targets:
-        print term.format("Unable to run target %s, this requires tor version %s" % (target, CONFIG["target.prereq"][target]), term.Color.RED, term.Attr.BOLD)
+        req_version = stem.version.Requirement[CONFIG["target.prereq"][target]]
+        print term.format("Unable to run target %s, this requires tor version %s" % (target, req_version), term.Color.RED, term.Attr.BOLD)
       
       print
     
diff --git a/test/runner.py b/test/runner.py
index 5719e67..f78bbc9 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -3,8 +3,10 @@ Runtime context for the integration tests. This is used both by the test runner
 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.
+RunnerStopped - Runner doesn't have an active tor instance
+TorInaccessable - Tor can't be queried for the information
+
+exercise_socket - Does a basic sanity check that a control socket can be used
 
 get_runner - Singleton for fetching our runtime context.
 Runner - Runtime context for our integration tests.
@@ -56,7 +58,7 @@ SocksPort 0
 
 # 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.
-STEM_BASE = "/".join(__file__.split("/")[:-2])
+STEM_BASE = os.path.sep.join(__file__.split(os.path.sep)[:-2])
 
 # singleton Runner instance
 INTEG_RUNNER = None
@@ -74,24 +76,13 @@ Torrc = stem.util.enum.Enum(
   ("PTRACE", "DisableDebuggerAttachment 0"),
 )
 
-def get_runner():
-  """
-  Singleton for the runtime context of integration tests.
-  """
-  
-  global INTEG_RUNNER
-  if not INTEG_RUNNER: INTEG_RUNNER = Runner()
-  return INTEG_RUNNER
+class RunnerStopped(Exception):
+  "Raised when we try to use a Runner that doesn't have an active tor instance"
+  pass
 
-def get_torrc(extra_torrc_opts):
-  """
-  Provides a basic torrc with the given connection method. Hashed passwords are
-  for "pw".
-  """
-  
-  if extra_torrc_opts:
-    return BASE_TORRC + "\n".join(extra_torrc_opts) + "\n"
-  else: return BASE_TORRC
+class TorInaccessable(Exception):
+  "Raised when information is needed from tor but the instance we have is inaccessable"
+  pass
 
 def exercise_socket(test_case, control_socket):
   """
@@ -108,13 +99,14 @@ def exercise_socket(test_case, control_socket):
   config_file_response = control_socket.recv()
   test_case.assertEquals("config-file=%s\nOK" % torrc_path, str(config_file_response))
 
-class RunnerStopped(Exception):
-  "Raised when we try to use a Runner that doesn't have an active tor instance"
-  pass
-
-class TorInaccessable(Exception):
-  "Raised when information is needed from tor but the instance we have is inaccessable"
-  pass
+def get_runner():
+  """
+  Singleton for the runtime context of integration tests.
+  """
+  
+  global INTEG_RUNNER
+  if not INTEG_RUNNER: INTEG_RUNNER = Runner()
+  return INTEG_RUNNER
 
 class Runner:
   def __init__(self):
@@ -174,7 +166,10 @@ class Runner:
       data_dir_path = "./%s" % os.path.basename(self._test_dir)
     
     self._custom_opts = extra_torrc_opts
-    self._torrc_contents = get_torrc(extra_torrc_opts) % data_dir_path
+    self._torrc_contents = BASE_TORRC % data_dir_path
+    
+    if extra_torrc_opts:
+      self._torrc_contents += "\n".join(extra_torrc_opts) + "\n"
     
     try:
       self._tor_cwd = os.getcwd()



More information about the tor-commits mailing list