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

[tor-commits] [stem/master] Moving static checks to the start



commit eaa7a9253ba8d8955a6d4ee911269bf94ed4f2aa
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Jan 4 12:14:17 2014 -0800

    Moving static checks to the start
    
    Rearranging our test run so the static checks (pyflakes and pep8) occure at the
    start and are listed among the initialization tasks. This makes it clearer that
    they're running and the runtime dedicated to them. It also gets rid of a silent
    pause at the end of the test run I've always disliked.
---
 run_tests.py      |   60 ++++++++++++++++++++++++++++++++++++-----------------
 test/settings.cfg |    1 -
 test/util.py      |   22 +++++++++++++-------
 3 files changed, 56 insertions(+), 27 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index 0d0e6d0..b0b3171 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -87,6 +87,22 @@ version 0.8.0 or later...
 https://pypi.python.org/pypi/mock/
 """
 
+PYFLAKES_TASK = Task(
+  "running pyflakes",
+  test.util.get_pyflakes_issues,
+  args = (SRC_PATHS,),
+  is_required = False,
+  print_result = False,
+)
+
+PEP8_TASK = Task(
+  "running pep8",
+  test.util.get_stylistic_issues,
+  args = (SRC_PATHS,),
+  is_required = False,
+  print_result = False,
+)
+
 
 def main():
   start_time = time.time()
@@ -134,6 +150,15 @@ def main():
 
     sys.exit(1)
 
+  pyflakes_task, pep8_task = None, None
+
+  if not stem.prereq.is_python_3():
+    if test.util.is_pyflakes_available():
+      pyflakes_task = PYFLAKES_TASK
+
+    if test.util.is_pep8_available():
+      pep8_task = PEP8_TASK
+
   test.util.run_tasks(
     "INITIALISING",
     Task("checking stem version", test.util.check_stem_version),
@@ -144,6 +169,8 @@ def main():
     Task("checking pep8 version", test.util.check_pep8_version),
     Task("checking for orphaned .pyc files", test.util.clean_orphaned_pyc, (SRC_PATHS,)),
     Task("checking for unused tests", test.util.check_for_unused_tests, ((os.path.join(STEM_BASE, 'test'),),)),
+    pyflakes_task,
+    pep8_task,
   )
 
   if args.run_python3 and sys.version_info[0] != 3:
@@ -262,7 +289,19 @@ def main():
       println()
 
   if not stem.prereq.is_python_3():
-    _print_static_issues(args)
+    static_check_issues = {}
+
+    if pyflakes_task and pyflakes_task.is_successful:
+      static_check_issues.update(pyflakes_task.result)
+    elif not test.util.is_pyflakes_available():
+      println("Static error checking requires pyflakes. Please install it from ...\n  http://pypi.python.org/pypi/pyflakes\n";, ERROR)
+
+    if pep8_task and pep8_task.is_successful:
+      static_check_issues.update(pep8_task.result)
+    elif not test.util.is_pep8_available():
+      println("Style checks require pep8. Please install it from...\n  http://pypi.python.org/pypi/pep8\n";, ERROR)
+
+    _print_static_issues(static_check_issues)
 
   runtime_label = "(%i seconds)" % (time.time() - start_time)
 
@@ -354,24 +393,7 @@ def _get_args(argv):
   return Args(**args)
 
 
-def _print_static_issues(args):
-  static_check_issues = {}
-
-  # If we're doing some sort of testing (unit or integ) and pyflakes is
-  # available then use it. Its static checks are pretty quick so there's not
-  # much overhead in including it with all tests.
-
-  if args.run_unit or args.run_integ:
-    if test.util.is_pyflakes_available():
-      static_check_issues.update(test.util.get_pyflakes_issues(SRC_PATHS))
-    else:
-      println("Static error checking requires pyflakes. Please install it from ...\n  http://pypi.python.org/pypi/pyflakes\n";, ERROR)
-
-    if test.util.is_pep8_available():
-      static_check_issues.update(test.util.get_stylistic_issues(SRC_PATHS))
-    else:
-      println("Style checks require pep8. Please install it from...\n  http://pypi.python.org/pypi/pep8\n";, ERROR)
-
+def _print_static_issues(static_check_issues):
   if static_check_issues:
     println("STATIC CHECKS", STATUS)
 
diff --git a/test/settings.cfg b/test/settings.cfg
index 0515476..6fd436a 100644
--- a/test/settings.cfg
+++ b/test/settings.cfg
@@ -35,7 +35,6 @@ msg.help
 |  -a, --all             runs unit, integ, and style checks (same as '-uis')
 |  -u, --unit            runs unit tests
 |  -i, --integ           runs integration tests
-|  -s, --style           runs style checker
 |  -t, --target TARGET   comma separated list of extra targets for integ tests
 |      --test TEST_NAME  only run tests modules matching the given name prefix
 |      --python3         runs tests against a 2to3 conversion of the codebase
diff --git a/test/util.py b/test/util.py
index a889b92..d510d6f 100644
--- a/test/util.py
+++ b/test/util.py
@@ -554,6 +554,9 @@ def run_tasks(category, *tasks):
   test.output.print_divider(category, True)
 
   for task in tasks:
+    if task is None:
+      continue
+
     task.run()
 
     if task.is_required and task.error:
@@ -576,15 +579,19 @@ class Task(object):
   message or list of strings for its results.
   """
 
-  def __init__(self, label, runner, args = None, is_required = True):
+  def __init__(self, label, runner, args = None, is_required = True, print_result = True):
     super(Task, self).__init__()
 
     self.label = label
     self.runner = runner
     self.args = args
     self.is_required = is_required
+    self.print_result = print_result
     self.error = None
 
+    self.is_successful = False
+    self.result = None
+
   def run(self):
     println("  %s..." % self.label, STATUS, NO_NL)
 
@@ -593,19 +600,20 @@ class Task(object):
 
     try:
       if self.args:
-        result = self.runner(*self.args)
+        self.result = self.runner(*self.args)
       else:
-        result = self.runner()
+        self.result = self.runner()
 
+      self.is_successful = True
       output_msg = "done"
 
-      if isinstance(result, str):
-        output_msg = result
+      if self.print_result and isinstance(self.result, str):
+        output_msg = self.result
 
       println(output_msg, STATUS)
 
-      if isinstance(result, (list, tuple)):
-        for line in result:
+      if self.print_result and isinstance(self.result, (list, tuple)):
+        for line in self.result:
           println("    %s" % line, STATUS)
     except Exception as exc:
       output_msg = str(exc)



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