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

[tor-commits] [stem/master] Increase --test scope to be any module substring



commit b1081d4abb56439a7d4b8dfd254d079d32d9b976
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Jan 5 21:44:19 2014 -0800

    Increase --test scope to be any module substring
    
    Our --test argument only ran tests matching a given prefix but this was silly
    for a couple reasons...
    
    1. That's unintuitive. If I give 'util.conf' I expect it to run tests with
       'util.conf', not starting with that. There's no advantage to a prefix match.
    
    2. Now that we're displaying less verbose test output we strip off the
       'test.unit.' or 'test.integ.' prefix that all the module names have. With
       this change the user can copy-and-paste what we show them to just run that
       test.
---
 run_tests.py      |   10 +++++-----
 test/settings.cfg |    2 +-
 test/util.py      |   16 ++++++++--------
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index 00cf381..5450dea 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -45,7 +45,7 @@ ARGS = {
   'run_integ': False,
   'run_python3': False,
   'run_python3_clean': False,
-  'test_prefix': None,
+  'specific_test': None,
   'logging_runlevel': None,
   'tor_path': 'tor',
   'run_targets': [Target.RUN_OPEN],
@@ -153,7 +153,7 @@ def main():
 
   pyflakes_task, pep8_task = None, None
 
-  if not stem.prereq.is_python_3() and not args.test_prefix:
+  if not stem.prereq.is_python_3() and not args.specific_test:
     if test.util.is_pyflakes_available():
       pyflakes_task = PYFLAKES_TASK
 
@@ -212,7 +212,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.test_prefix):
+    for test_class in test.util.get_unit_tests(args.specific_test):
       run_result = _run_test(args, test_class, output_filters, logging_buffer)
       skipped_tests += len(getattr(run_result, 'skipped', []))
 
@@ -248,7 +248,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.test_prefix):
+        for test_class in test.util.get_integ_tests(args.specific_test):
           run_result = _run_test(args, test_class, output_filters, logging_buffer)
           skipped_tests += len(getattr(run_result, 'skipped', []))
 
@@ -379,7 +379,7 @@ def _get_args(argv):
       args['run_targets'] = run_targets
       args['attribute_targets'] = attribute_targets
     elif opt in ("-l", "--test"):
-      args['test_prefix'] = arg
+      args['specific_test'] = arg
     elif opt in ("-l", "--log"):
       arg = arg.upper()
 
diff --git a/test/settings.cfg b/test/settings.cfg
index e78ddb4..fd960a1 100644
--- a/test/settings.cfg
+++ b/test/settings.cfg
@@ -36,7 +36,7 @@ msg.help
 |  -u, --unit            runs unit tests
 |  -i, --integ           runs integration tests
 |  -t, --target TARGET   comma separated list of extra targets for integ tests
-|      --test TEST_NAME  only run tests modules matching the given name prefix
+|      --test TEST_NAME  only run tests modules containing the given name
 |      --python3         runs tests against a 2to3 conversion of the codebase
 |  -l, --log RUNLEVEL    includes logging output with test results, runlevels:
 |                          TRACE, DEBUG, INFO, NOTICE, WARN, ERROR
diff --git a/test/util.py b/test/util.py
index cfa0b95..f4fb9fb 100644
--- a/test/util.py
+++ b/test/util.py
@@ -89,34 +89,34 @@ Target = stem.util.enum.UppercaseEnum(
 STEM_BASE = os.path.sep.join(__file__.split(os.path.sep)[:-2])
 
 
-def get_unit_tests(prefix = None):
+def get_unit_tests(module_substring = None):
   """
   Provides the classes for our unit tests.
 
-  :param str prefix: only provide the test if the module starts with this prefix
+  :param str module_substring: only provide the test if the module includes this substring
 
   :returns: an **iterator** for our unit tests
   """
 
-  return _get_tests(CONFIG["test.unit_tests"].splitlines(), prefix)
+  return _get_tests(CONFIG["test.unit_tests"].splitlines(), module_substring)
 
 
-def get_integ_tests(prefix = None):
+def get_integ_tests(module_substring = None):
   """
   Provides the classes for our integration tests.
 
-  :param str prefix: only provide the test if the module starts with this prefix
+  :param str module_substring: only provide the test if the module includes this substring
 
   :returns: an **iterator** for our integration tests
   """
 
-  return _get_tests(CONFIG["test.integ_tests"].splitlines(), prefix)
+  return _get_tests(CONFIG["test.integ_tests"].splitlines(), module_substring)
 
 
-def _get_tests(modules, prefix):
+def _get_tests(modules, module_substring):
   for import_name in modules:
     if import_name:
-      if prefix and not import_name.startswith(prefix):
+      if module_substring and module_substring not in import_name:
         continue
 
       # Dynamically imports test modules. The __import__() call has a couple



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