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

[tor-commits] [stem/master] Supporting list of paths in static checker functions



commit f141a007655ae4d667942745b1acafa77391e0d0
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Fri Apr 12 08:31:49 2013 -0700

    Supporting list of paths in static checker functions
    
    Reudcing a bit of redundancy by having the static_checks module support list of
    paths.
---
 run_tests.py          |   18 +++++++-----------
 test/runner.py        |    1 -
 test/static_checks.py |   42 +++++++++++++++++++++++++++++++++---------
 3 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index ab35592..65c3444 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -41,13 +41,16 @@ CONFIG = stem.util.conf.config_dict("test", {
 
 DEFAULT_RUN_TARGET = Target.RUN_OPEN
 
+base = os.path.sep.join(__file__.split(os.path.sep)[:-1]).lstrip("./")
+SOURCE_BASE_PATHS = [os.path.join(base, path) for path in ('stem', 'test', 'run_tests.py')]
+
 
 def _clean_orphaned_pyc():
   test.output.print_noline("  checking for orphaned .pyc files... ", *test.runner.STATUS_ATTR)
 
   orphaned_pyc = []
 
-  for base_dir in ('stem', 'test', 'run_tests.py'):
+  for base_dir in SOURCE_BASE_PATHS:
     for pyc_path in test.static_checks._get_files_with_suffix(base_dir, ".pyc"):
       # If we're running python 3 then the *.pyc files are no longer bundled
       # with the *.py. Rather, they're in a __pycache__ directory.
@@ -121,10 +124,7 @@ def _python3_setup(python3_destination, clean):
 
 
 def _print_style_issues(run_unit, run_integ, run_style):
-  base_path = os.path.sep.join(__file__.split(os.path.sep)[:-1]).lstrip("./")
-  style_issues = test.static_checks.get_issues(os.path.join(base_path, "stem"))
-  style_issues.update(test.static_checks.get_issues(os.path.join(base_path, "test")))
-  style_issues.update(test.static_checks.get_issues(os.path.join(base_path, "run_tests.py")))
+  style_issues = test.static_checks.get_issues(SOURCE_BASE_PATHS)
 
   # 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
@@ -132,17 +132,13 @@ def _print_style_issues(run_unit, run_integ, run_style):
 
   if run_unit or run_integ:
     if system.is_available("pyflakes"):
-      style_issues.update(test.static_checks.pyflakes_issues(os.path.join(base_path, "stem")))
-      style_issues.update(test.static_checks.pyflakes_issues(os.path.join(base_path, "test")))
-      style_issues.update(test.static_checks.pyflakes_issues(os.path.join(base_path, "run_tests.py")))
+      style_issues.update(test.static_checks.pyflakes_issues(SOURCE_BASE_PATHS))
     else:
       test.output.print_error("Static error checking requires pyflakes. Please install it from ...\n  http://pypi.python.org/pypi/pyflakes\n";)
 
   if run_style:
     if system.is_available("pep8"):
-      style_issues.update(test.static_checks.pep8_issues(os.path.join(base_path, "stem")))
-      style_issues.update(test.static_checks.pep8_issues(os.path.join(base_path, "test")))
-      style_issues.update(test.static_checks.pep8_issues(os.path.join(base_path, "run_tests.py")))
+      style_issues.update(test.static_checks.pep8_issues(SOURCE_BASE_PATHS))
     else:
       test.output.print_error("Style checks require pep8. Please install it from...\n  http://pypi.python.org/pypi/pep8\n";)
 
diff --git a/test/runner.py b/test/runner.py
index 2787795..fb30c9f 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -227,7 +227,6 @@ def exercise_controller(test_case, controller):
   test_case.assertEquals("config-file=%s\nOK" % torrc_path, str(config_file_response))
 
 
-
 def get_unit_tests(prefix = None):
   """
   Provides the classes for our unit tests.
diff --git a/test/static_checks.py b/test/static_checks.py
index b8cc664..6d0a508 100644
--- a/test/static_checks.py
+++ b/test/static_checks.py
@@ -27,16 +27,24 @@ CONFIG = conf.config_dict("test", {
 })
 
 
-def pep8_issues(base_path = DEFAULT_TARGET):
+def pep8_issues(base_paths = DEFAULT_TARGET):
   """
   Checks for stylistic issues that are an issue according to the parts of PEP8
   we conform to.
 
-  :param str base_path: directory to be iterated over
+  :param str,list base_paths: directory to be iterated over
 
   :returns: dict of the form ``path => [(line_number, message)...]``
   """
 
+  if isinstance(base_paths, (tuple, list)):
+    results = {}
+
+    for path in base_paths:
+      results.update(pep8_issues(path))
+
+    return results
+
   # The pep8 command give output of the form...
   #
   #   FILE:LINE:CHARACTER ISSUE
@@ -76,7 +84,7 @@ def pep8_issues(base_path = DEFAULT_TARGET):
   ignored_issues = "E111,E121,E501,E251,E127"
 
   issues = {}
-  pep8_output = system.call("pep8 --ignore %s %s" % (ignored_issues, base_path))
+  pep8_output = system.call("pep8 --ignore %s %s" % (ignored_issues, base_paths))
 
   for line in pep8_output:
     line_match = re.match("^(.*):(\d+):(\d+): (.*)$", line)
@@ -90,16 +98,24 @@ def pep8_issues(base_path = DEFAULT_TARGET):
   return issues
 
 
-def pyflakes_issues(base_path = DEFAULT_TARGET):
+def pyflakes_issues(base_paths = DEFAULT_TARGET):
   """
   Checks for issues via pyflakes. False positives can be whitelisted via our
   test configuration.
 
-  :param str base_path: directory to be iterated over
+  :param str,list base_paths: directory to be iterated over
 
   :returns: dict of the form ``path => [(line_number, message)...]``
   """
 
+  if isinstance(base_paths, (tuple, list)):
+    results = {}
+
+    for path in base_paths:
+      results.update(pyflakes_issues(path))
+
+    return results
+
   global PYFLAKES_IGNORE
 
   if PYFLAKES_IGNORE is None:
@@ -121,7 +137,7 @@ def pyflakes_issues(base_path = DEFAULT_TARGET):
   #   stem/control.py:957: undefined name 'entry'
 
   issues = {}
-  pyflakes_output = system.call("pyflakes %s" % base_path)
+  pyflakes_output = system.call("pyflakes %s" % base_paths)
 
   for line in pyflakes_output:
     line_match = re.match("^(.*):(\d+): (.*)$", line)
@@ -135,22 +151,30 @@ def pyflakes_issues(base_path = DEFAULT_TARGET):
   return issues
 
 
-def get_issues(base_path = DEFAULT_TARGET):
+def get_issues(base_paths = DEFAULT_TARGET):
   """
   Checks python source code in the given directory for whitespace issues.
 
-  :param str base_path: directory to be iterated over
+  :param str,list base_paths: directory to be iterated over
 
   :returns: dict of the form ``path => [(line_number, message)...]``
   """
 
+  if isinstance(base_paths, (tuple, list)):
+    results = {}
+
+    for path in base_paths:
+      results.update(get_issues(path))
+
+    return results
+
   # TODO: This does not check that block indentations are two spaces because
   # differentiating source from string blocks ("""foo""") is more of a pita
   # than I want to deal with right now.
 
   issues = {}
 
-  for file_path in _get_files_with_suffix(base_path):
+  for file_path in _get_files_with_suffix(base_paths):
     if _is_test_data(file_path):
       continue
 



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