[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Helper for getting torrc of a target



commit c7ed4c84b30c8555ba8e2e63c158b74876d08db2
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Wed Apr 24 09:27:07 2013 -0700

    Helper for getting torrc of a target
    
    Breaking a chunk of run_tests.py into a get_torrc_entries() helper function to
    improve readability. The runner could use an overhaul, and might later take on
    this functionality.
---
 run_tests.py |   21 ++++++---------------
 test/util.py |   31 +++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index 17c9145..41fa2b3 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -181,21 +181,7 @@ def main():
       error_tracker.set_category(target)
 
       try:
-        # converts the 'target.torrc' csv into a list of test.runner.Torrc enums
-        config_csv = CONFIG["target.torrc"].get(target)
-        torrc_opts = []
-
-        if config_csv:
-          for opt in config_csv.split(','):
-            opt = opt.strip()
-
-            if opt in test.runner.Torrc.keys():
-              torrc_opts.append(test.runner.Torrc[opt])
-            else:
-              println("'%s' isn't a test.runner.Torrc enumeration" % opt)
-              sys.exit(1)
-
-        integ_runner.start(target, args.attribute_targets, args.tor_path, extra_torrc_opts = torrc_opts)
+        integ_runner.start(target, args.attribute_targets, args.tor_path, extra_torrc_opts = test.util.get_torrc_entries(target))
 
         println("Running tests...\n", STATUS)
 
@@ -219,6 +205,11 @@ def main():
       except KeyboardInterrupt:
         println("  aborted starting tor: keyboard interrupt\n", ERROR)
         break
+      except ValueError, exc:
+        # can arise if get_torrc_entries() runs into a bad settings.cfg data
+
+        println(exc, ERROR)
+        break
       except OSError:
         error_tracker.register_error()
       finally:
diff --git a/test/util.py b/test/util.py
index 12effd0..309851b 100644
--- a/test/util.py
+++ b/test/util.py
@@ -10,6 +10,7 @@ Helper functions for our test framework.
   get_integ_tests - provides our integration tests
 
   get_prereq - provides the tor version required to run the given target
+  get_torrc_entries - provides the torrc entries for a given target
   get_help_message - provides usage information for running our tests
   get_python3_destination - location where a python3 copy of stem is exported to
   get_stylistic_issues - checks for PEP8 and other stylistic issues
@@ -56,6 +57,7 @@ CONFIG = stem.util.conf.config_dict("test", {
   "msg.help": "",
   "target.description": {},
   "target.prereq": {},
+  "target.torrc": {},
   "pep8.ignore": [],
   "pyflakes.ignore": [],
   "integ.test_directory": "./test/data",
@@ -174,6 +176,35 @@ def get_prereq(target):
     return None
 
 
+def get_torrc_entries(target):
+  """
+  Provides the torrc entries used to run the given target.
+
+  :param Target target: target to provide the custom torrc contents of
+
+  :returns: list of :class:`~test.runner.Torrc` entries for the given target
+
+  :raises: **ValueError** if the target.torrc config has entries that don't map
+    to test.runner.Torrc
+  """
+
+  # converts the 'target.torrc' csv into a list of test.runner.Torrc enums
+
+  config_csv = CONFIG["target.torrc"].get(target)
+  torrc_opts = []
+
+  if config_csv:
+    for opt in config_csv.split(','):
+      opt = opt.strip()
+
+      if opt in test.runner.Torrc.keys():
+        torrc_opts.append(test.runner.Torrc[opt])
+      else:
+        raise ValueError("'%s' isn't a test.runner.Torrc enumeration" % opt)
+
+  return torrc_opts
+
+
 def get_python3_destination():
   """
   Provides the location where a python 3 copy of stem is exported to for



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits