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

[tor-commits] [stem/master] Move remaining run_tests.py helpers



commit bb7975928a07893699b26528989d39bac941b82d
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun May 21 18:57:00 2017 -0700

    Move remaining run_tests.py helpers
    
    Most of the remaining helpers are solely used by run_tests.py. Might as well
    have them in there. I probably originally moved these out when run_tests.py was
    tiny but it's already a moderately sizable module so these don't account for
    much.
---
 run_tests.py      | 85 +++++++++++++++++++++++++++++++++++++++++++++++---
 test/settings.cfg |  2 +-
 test/util.py      | 92 +------------------------------------------------------
 3 files changed, 83 insertions(+), 96 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index f3eabf4..6beb659 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -37,8 +37,10 @@ from test.output import STATUS, SUCCESS, ERROR, NO_NL, STDERR, println
 from test.util import STEM_BASE
 
 CONFIG = stem.util.conf.config_dict('test', {
-  'integ.test_directory': './test/data',
+  'test.unit_tests': '',
+  'test.integ_tests': '',
   'target.prereq': {},
+  'target.torrc': {},
 })
 
 MOCK_UNAVAILABLE_MSG = """\
@@ -71,6 +73,81 @@ if stem.prereq._is_python_26():
   unittest.TestCase.assertItemsEqual = assertItemsEqual
 
 
+def get_unit_tests(module_prefix = None):
+  """
+  Provides the classes for our unit tests.
+
+  :param str module_prefix: only provide the test if the module starts with
+    this substring
+
+  :returns: an **iterator** for our unit tests
+  """
+
+  if module_prefix and not module_prefix.startswith('test.unit.'):
+    module_prefix = 'test.unit.' + module_prefix
+
+  return _get_tests(CONFIG['test.unit_tests'].splitlines(), module_prefix)
+
+
+def get_integ_tests(module_prefix = None):
+  """
+  Provides the classes for our integration tests.
+
+  :param str module_prefix: only provide the test if the module starts with
+    this substring
+
+  :returns: an **iterator** for our integration tests
+  """
+
+  if module_prefix and not module_prefix.startswith('test.integ.'):
+    module_prefix = 'test.integ.' + module_prefix
+
+  return _get_tests(CONFIG['test.integ_tests'].splitlines(), module_prefix)
+
+
+def _get_tests(modules, module_prefix):
+  for import_name in modules:
+    if import_name:
+      module, module_name = import_name.rsplit('.', 1)  # example: util.conf.TestConf
+
+      if not module_prefix or module.startswith(module_prefix):
+        yield import_name
+      elif module_prefix.startswith(module):
+        # single test for this module
+
+        test_module = module_prefix.rsplit('.', 1)[1]
+        yield '%s.%s' % (import_name, test_module)
+
+
+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()
 
@@ -173,7 +250,7 @@ def main():
     test.output.print_divider('UNIT TESTS', True)
     error_tracker.set_category('UNIT TEST')
 
-    for test_class in test.util.get_unit_tests(args.specific_test):
+    for test_class in get_unit_tests(args.specific_test):
       run_result = _run_test(args, test_class, output_filters, logging_buffer)
       skipped_tests += len(getattr(run_result, 'skipped', []))
 
@@ -205,7 +282,7 @@ def main():
       error_tracker.set_category(target)
 
       try:
-        integ_runner.start(args.attribute_targets, args.tor_path, extra_torrc_opts = test.util.get_torrc_entries(target))
+        integ_runner.start(args.attribute_targets, args.tor_path, extra_torrc_opts = get_torrc_entries(target))
 
         println('Running tests...\n', STATUS)
 
@@ -213,7 +290,7 @@ def main():
         if integ_runner.is_accessible():
           owner = integ_runner.get_tor_controller(True)  # controller to own our main Tor process
 
-        for test_class in test.util.get_integ_tests(args.specific_test):
+        for test_class in get_integ_tests(args.specific_test):
           run_result = _run_test(args, test_class, output_filters, logging_buffer)
           skipped_tests += len(getattr(run_result, 'skipped', []))
 
diff --git a/test/settings.cfg b/test/settings.cfg
index f11b1f5..2b5fafc 100644
--- a/test/settings.cfg
+++ b/test/settings.cfg
@@ -161,9 +161,9 @@ pyflakes.ignore stem/interpreter/__init__.py => undefined name 'raw_input'
 pyflakes.ignore stem/util/conf.py => undefined name 'unicode'
 pyflakes.ignore stem/util/test_tools.py => 'pyflakes' imported but unused
 pyflakes.ignore stem/util/test_tools.py => 'pycodestyle' imported but unused
-pyflakes.ignore test/mocking.py => undefined name 'test'
 pyflakes.ignore test/unit/response/events.py => 'from stem import *' used; unable to detect undefined names
 pyflakes.ignore test/unit/response/events.py => *may be undefined, or defined from star imports: stem
+pyflakes.ignore test/util.py => undefined name 'test'
 
 # Test modules we want to run. Modules are roughly ordered by the dependencies
 # so the lowest level tests come first. This is because a problem in say,
diff --git a/test/util.py b/test/util.py
index 2731f63..3decb89 100644
--- a/test/util.py
+++ b/test/util.py
@@ -6,10 +6,6 @@ Helper functions for our test framework.
 
 ::
 
-  get_unit_tests - provides our unit tests
-  get_integ_tests - provides our integration tests
-
-  get_torrc_entries - provides the torrc entries for a given target
   get_all_combinations - provides all combinations of attributes
   tor_version - provides the version of tor we're testing against
 """
@@ -18,17 +14,9 @@ import itertools
 import os
 
 import stem
-import stem.util.conf
 import stem.util.enum
 import stem.version
 
-CONFIG = stem.util.conf.config_dict('test', {
-  'target.torrc': {},
-  'integ.test_directory': './test/data',
-  'test.unit_tests': '',
-  'test.integ_tests': '',
-})
-
 # Integration targets fall into two categories:
 #
 # * Run Targets (like RUN_COOKIE and RUN_PTRACE) which customize our torrc.
@@ -75,81 +63,6 @@ with open(os.path.join(STEM_BASE, '.gitignore')) as ignore_file:
       IGNORED_FILE_TYPES.append(line[2:].strip())
 
 
-def get_unit_tests(module_prefix = None):
-  """
-  Provides the classes for our unit tests.
-
-  :param str module_prefix: only provide the test if the module starts with
-    this substring
-
-  :returns: an **iterator** for our unit tests
-  """
-
-  if module_prefix and not module_prefix.startswith('test.unit.'):
-    module_prefix = 'test.unit.' + module_prefix
-
-  return _get_tests(CONFIG['test.unit_tests'].splitlines(), module_prefix)
-
-
-def get_integ_tests(module_prefix = None):
-  """
-  Provides the classes for our integration tests.
-
-  :param str module_prefix: only provide the test if the module starts with
-    this substring
-
-  :returns: an **iterator** for our integration tests
-  """
-
-  if module_prefix and not module_prefix.startswith('test.integ.'):
-    module_prefix = 'test.integ.' + module_prefix
-
-  return _get_tests(CONFIG['test.integ_tests'].splitlines(), module_prefix)
-
-
-def _get_tests(modules, module_prefix):
-  for import_name in modules:
-    if import_name:
-      module, module_name = import_name.rsplit('.', 1)  # example: util.conf.TestConf
-
-      if not module_prefix or module.startswith(module_prefix):
-        yield import_name
-      elif module_prefix.startswith(module):
-        # single test for this module
-
-        test_module = module_prefix.rsplit('.', 1)[1]
-        yield '%s.%s' % (import_name, test_module)
-
-
-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_new_capabilities():
   """
   Provides a list of capabilities tor supports but stem doesn't, as discovered
@@ -185,7 +98,7 @@ def get_all_combinations(attr, include_empty = False):
 
   ::
 
-    >>> list(test.mocking.get_all_combinations(['a', 'b', 'c']))
+    >>> list(test.util.get_all_combinations(['a', 'b', 'c']))
     [('a',), ('b',), ('c',), ('a', 'b'), ('a', 'c'), ('b', 'c'), ('a', 'b', 'c')]
 
   :param list attr: attributes to provide combinations for
@@ -231,6 +144,3 @@ def tor_version(tor_path = None):
     TOR_VERSION = stem.version.get_system_tor_version(tor_path)
 
   return TOR_VERSION
-
-
-import test.runner  # needs to be imported at the end to avoid a circular dependency



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