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

[tor-commits] [stem/master] Supporting files in whitespace checks



commit 54e3970b674665d58b786b52af02b18bdb686136
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Wed Oct 31 08:46:55 2012 -0700

    Supporting files in whitespace checks
    
    We called os.walk() when determining the files for which we want to check
    whitespace. However, when presented with a file rather than a directory this
    causes us to not check anything...
    
    >>> list(os.walk("/tmp/foo"))
    []
    
    This broke our attempts to check 'run_tests.py', and let a couple whitespace
    issues slip in. Fixing get_issues()'s handling for individual files.
    
    Issue caught by Eoin on...
    https://trac.torproject.org/7263
---
 run_tests.py             |    4 ++--
 test/check_whitespace.py |   12 ++++++++----
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index 2e35beb..b4f0c06 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -286,7 +286,7 @@ if __name__ == '__main__':
   
   # count how many tests have been skipped.
   skipped_test_count = 0
-
+  
   # loads and validates our various configurations
   test_config = stem.util.conf.get_config("test")
   
@@ -484,7 +484,7 @@ if __name__ == '__main__':
   elif skipped_test_count > 0:
     test.output.print_line("%i TESTS WERE SKIPPED" % skipped_test_count, term.Color.BLUE, term.Attr.BOLD)
     test.output.print_line("ALL OTHER TESTS PASSED %s" % runtime_label, term.Color.GREEN, term.Attr.BOLD)
-    print    
+    print
   else:
     test.output.print_line("TESTING PASSED %s" % runtime_label, term.Color.GREEN, term.Attr.BOLD)
     print
diff --git a/test/check_whitespace.py b/test/check_whitespace.py
index 314230f..fa26a09 100644
--- a/test/check_whitespace.py
+++ b/test/check_whitespace.py
@@ -107,10 +107,14 @@ def _get_files_with_suffix(base_path, suffix = ".py"):
   :returns: iterator that yields the absolute path for files with the given suffix
   """
   
-  for root, _, files in os.walk(base_path):
-    for filename in files:
-      if filename.endswith(suffix):
-        yield os.path.join(root, filename)
+  if os.path.isfile(base_path):
+    if base_path.endswith(suffix):
+      yield base_path
+  else:
+    for root, _, files in os.walk(base_path):
+      for filename in files:
+        if filename.endswith(suffix):
+          yield os.path.join(root, filename)
 
 if __name__ == '__main__':
   issues = get_issues()

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