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

[tor-commits] [stem/master] Move get_torrc_entries() into runner



commit 448a5e96ba423b8bc4be33f29e3af64e07e46b82
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Tue Jul 25 11:03:45 2017 -0700

    Move get_torrc_entries() into runner
    
    This helper is only used to translate targets into their extra torrc options.
    Rest of the torrc stuff resides in the runner so might as well put this there
    too.
    
    Not really settled on this yet but presently trying to make our run_tests.py
    easier to follow. I'll circle back to do the same for runner.py afterward.
---
 run_tests.py   | 45 +++++++--------------------------------------
 test/runner.py | 17 +++++++++++++++--
 2 files changed, 22 insertions(+), 40 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index b9adf31c..e2bc19ad 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -38,7 +38,6 @@ CONFIG = stem.util.conf.config_dict('test', {
   'integ.test_directory': './test/data',
   'test.unit_tests': '',
   'test.integ_tests': '',
-  'target.torrc': {},
 })
 
 MOCK_UNAVAILABLE_MSG = """\
@@ -109,35 +108,6 @@ def _get_tests(modules, module_prefix):
       yield '%s.%s' % (import_name, test_name)
 
 
-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 main():
   start_time = time.time()
 
@@ -239,7 +209,8 @@ def main():
     error_tracker.set_category('UNIT TEST')
 
     for test_class in get_unit_tests(args.specific_test):
-      run_result = _run_test(args, test_class, output_filters, logging_buffer)
+      run_result = _run_test(args, test_class, output_filters)
+      test.output.print_logging(logging_buffer)
       skipped_tests += len(getattr(run_result, 'skipped', []))
 
     println()
@@ -252,20 +223,19 @@ def main():
       error_tracker.set_category(target)
 
       try:
-        integ_runner.start(args.attribute_targets, args.tor_path, extra_torrc_opts = get_torrc_entries(target))
+        integ_runner.start(target, args.attribute_targets, args.tor_path)
 
         println('Running tests...\n', STATUS)
 
         for test_class in get_integ_tests(args.specific_test):
-          run_result = _run_test(args, test_class, output_filters, logging_buffer)
+          run_result = _run_test(args, test_class, output_filters)
+          test.output.print_logging(logging_buffer)
           skipped_tests += len(getattr(run_result, 'skipped', []))
       except KeyboardInterrupt:
         println('  aborted starting tor: keyboard interrupt\n', ERROR)
         break
       except ValueError as exc:
-        # can arise if get_torrc_entries() runs into a bad settings.cfg data
-
-        println(str(exc), ERROR)
+        println(str(exc), ERROR)  # can arise if there's bad settings.cfg data
         break
       except OSError:
         error_tracker.register_error()
@@ -356,7 +326,7 @@ def _print_static_issues(static_check_issues):
       println()
 
 
-def _run_test(args, test_class, output_filters, logging_buffer):
+def _run_test(args, test_class, output_filters):
   start_time = time.time()
 
   # Test classes look like...
@@ -407,7 +377,6 @@ def _run_test(args, test_class, output_filters, logging_buffer):
       println(' failed (%0.2fs)' % (time.time() - start_time), ERROR)
       println(test.output.apply_filters(test_results.getvalue(), *output_filters), NO_NL)
 
-  test.output.print_logging(logging_buffer)
   return run_result
 
 
diff --git a/test/runner.py b/test/runner.py
index 14795ce8..0a307c87 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -54,6 +54,7 @@ from test.output import println, STATUS, ERROR, SUBSTATUS, NO_NL
 CONFIG = stem.util.conf.config_dict('test', {
   'integ.test_directory': './test/data',
   'integ.log': './test/data/log',
+  'target.torrc': {},
 })
 
 SOCKS_PORT = 1112
@@ -169,14 +170,14 @@ class Runner(object):
 
     self._owner_controller = None
 
-  def start(self, attribute_targets, tor_cmd, extra_torrc_opts):
+  def start(self, config_target, attribute_targets, tor_cmd):
     """
     Makes temporary testing resources and starts tor, blocking until it
     completes.
 
+    :param str config_target: **Target** for this test run's torrc settings
     :param list attribute_targets: **Targets** for our non-configuration attributes
     :param str tor_cmd: command to start tor with
-    :param list extra_torrc_opts: additional torrc options for our test instance
 
     :raises: OSError if unable to run test preparations or start tor
     """
@@ -214,6 +215,18 @@ class Runner(object):
         os.chdir(tor_cwd)
         data_dir_path = './%s' % os.path.basename(self._test_dir)
 
+      config_csv = CONFIG['target.torrc'].get(config_target)
+      extra_torrc_opts = []
+
+      if config_csv:
+        for opt in config_csv.split(','):
+          opt = opt.strip()
+
+          if opt in Torrc.keys():
+            extra_torrc_opts.append(Torrc[opt])
+          else:
+            raise ValueError("'%s' isn't a test.runner.Torrc enumeration" % opt)
+
       self._custom_opts = extra_torrc_opts
       self._torrc_contents = BASE_TORRC % (data_dir_path, data_dir_path)
 



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