[tor-commits] [stem/master] Moving ERROR_ATTR to output module

atagar at torproject.org atagar at torproject.org
Sun Apr 14 04:33:47 UTC 2013


commit 90cb6e347fc02dd60e19011a13e9947e0eed7381
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Apr 12 08:10:56 2013 -0700

    Moving ERROR_ATTR to output module
    
    The ERROR_ATTR was defined in both run_tests.py and the runner. Making both
    modules a little cleaner by moving it to the output module.
---
 run_tests.py   |   26 ++++++++++++--------------
 test/output.py |    5 +++++
 test/runner.py |   13 ++++++-------
 3 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index 66e7fc2..ab35592 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -41,8 +41,6 @@ CONFIG = stem.util.conf.config_dict("test", {
 
 DEFAULT_RUN_TARGET = Target.RUN_OPEN
 
-ERROR_ATTR = (term.Color.RED, term.Attr.BOLD)
-
 
 def _clean_orphaned_pyc():
   test.output.print_noline("  checking for orphaned .pyc files... ", *test.runner.STATUS_ATTR)
@@ -70,7 +68,7 @@ def _clean_orphaned_pyc():
   else:
     print
     for pyc_file in orphaned_pyc:
-      test.output.print_line("    removing %s" % pyc_file, *test.runner.ERROR_ATTR)
+      test.output.print_error("    removing %s" % pyc_file)
       os.remove(pyc_file)
 
 
@@ -88,7 +86,7 @@ def _python3_setup(python3_destination, clean):
     shutil.rmtree(python3_destination, ignore_errors = True)
 
   if os.path.exists(python3_destination):
-    test.output.print_line("Reusing '%s'. Run again with '--clean' if you want to recreate the python3 export." % python3_destination, *test.runner.ERROR_ATTR)
+    test.output.print_error("Reusing '%s'. Run again with '--clean' if you want to recreate the python3 export." % python3_destination)
     print
     return True
 
@@ -108,7 +106,7 @@ def _python3_setup(python3_destination, clean):
     shutil.copy('run_tests.py', os.path.join(python3_destination, 'run_tests.py'))
     test.output.print_line("done", *test.runner.STATUS_ATTR)
   except OSError, exc:
-    test.output.print_line("failed\n%s" % exc, *test.runner.ERROR_ATTR)
+    test.output.print_error("failed\n%s" % exc)
     return False
 
   try:
@@ -116,7 +114,7 @@ def _python3_setup(python3_destination, clean):
     system.call("2to3 --write --nobackups --no-diffs %s" % python3_destination)
     test.output.print_line("done", *test.runner.STATUS_ATTR)
   except OSError, exc:
-    test.output.print_line("failed\n%s" % exc, *test.runner.ERROR_ATTR)
+    test.output.print_error("failed\n%s" % exc)
     return False
 
   return True
@@ -138,7 +136,7 @@ def _print_style_issues(run_unit, run_integ, run_style):
       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")))
     else:
-      test.output.print_line("Static error checking requires pyflakes. Please install it from ...\n  http://pypi.python.org/pypi/pyflakes\n", *ERROR_ATTR)
+      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"):
@@ -146,7 +144,7 @@ def _print_style_issues(run_unit, run_integ, run_style):
       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")))
     else:
-      test.output.print_line("Style checks require pep8. Please install it from...\n  http://pypi.python.org/pypi/pep8\n", *ERROR_ATTR)
+      test.output.print_error("Style checks require pep8. Please install it from...\n  http://pypi.python.org/pypi/pep8\n")
 
   if style_issues:
     test.output.print_line("STYLE ISSUES", term.Color.BLUE, term.Attr.BOLD)
@@ -287,7 +285,7 @@ if __name__ == '__main__':
   if run_python3:
     for required_cmd in ("2to3", "python3"):
       if not system.is_available(required_cmd):
-        test.output.print_line("Unable to test python 3 because %s isn't in your path" % required_cmd, *test.runner.ERROR_ATTR)
+        test.output.print_error("Unable to test python 3 because %s isn't in your path" % required_cmd)
         sys.exit(1)
 
   if run_python3 and sys.version_info[0] != 3:
@@ -409,15 +407,15 @@ if __name__ == '__main__':
         active_threads = threading.enumerate()
 
         if len(active_threads) > 1:
-          test.output.print_line("Threads lingering after test run:", *ERROR_ATTR)
+          test.output.print_error("Threads lingering after test run:")
 
           for lingering_thread in active_threads:
-            test.output.print_line("  %s" % lingering_thread, *ERROR_ATTR)
+            test.output.print_error("  %s" % lingering_thread)
 
           testing_failed = True
           break
       except KeyboardInterrupt:
-        test.output.print_line("  aborted starting tor: keyboard interrupt\n", *ERROR_ATTR)
+        test.output.print_error("  aborted starting tor: keyboard interrupt\n")
         break
       except OSError:
         testing_failed = True
@@ -448,10 +446,10 @@ if __name__ == '__main__':
   has_error = testing_failed or error_tracker.has_error_occured()
 
   if has_error:
-    test.output.print_line("TESTING FAILED %s" % runtime_label, *ERROR_ATTR)
+    test.output.print_error("TESTING FAILED %s" % runtime_label)
 
     for line in error_tracker:
-      test.output.print_line("  %s" % line, *ERROR_ATTR)
+      test.output.print_error("  %s" % line)
   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)
diff --git a/test/output.py b/test/output.py
index 66e19c6..22f3605 100644
--- a/test/output.py
+++ b/test/output.py
@@ -18,6 +18,7 @@ COLOR_SUPPORT = sys.stdout.isatty() and not system.is_windows()
 DIVIDER = "=" * 70
 HEADER_ATTR = (term.Color.CYAN, term.Attr.BOLD)
 CATEGORY_ATTR = (term.Color.GREEN, term.Attr.BOLD)
+ERROR_ATTR = (term.Color.RED, term.Attr.BOLD)
 
 LineType = stem.util.enum.Enum("OK", "FAIL", "ERROR", "SKIPPED", "CONTENT")
 
@@ -52,6 +53,10 @@ def print_noline(msg, *attr):
   sys.stdout.flush()
 
 
+def print_error(msg):
+  print_line(msg, *ERROR_ATTR)
+
+
 def print_divider(msg, is_header = False):
   attr = HEADER_ATTR if is_header else CATEGORY_ATTR
   print_line("%s\n%s\n%s\n" % (DIVIDER, msg.center(70), DIVIDER), *attr)
diff --git a/test/runner.py b/test/runner.py
index d869d6a..2787795 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -86,7 +86,6 @@ Target = stem.util.enum.UppercaseEnum(
 
 STATUS_ATTR = (term.Color.BLUE, term.Attr.BOLD)
 SUBSTATUS_ATTR = (term.Color.BLUE, )
-ERROR_ATTR = (term.Color.RED, term.Attr.BOLD)
 
 SOCKS_HOST = "127.0.0.1"
 SOCKS_PORT = 1112
@@ -432,7 +431,7 @@ class Runner(object):
           elif not stem.util.system.is_windows():
             os.kill(self._tor_process.pid, signal.SIGTERM)
           else:
-            test.output.print_line("failed (unable to call kill() in python 2.5)", *ERROR_ATTR)
+            test.output.print_error("failed (unable to call kill() in python 2.5)")
         except OSError:
           pass
 
@@ -470,7 +469,7 @@ class Runner(object):
       if self._tor_process and self._tor_process.poll() is not None:
         # clean up the temporary resources and note the unexpected shutdown
         self.stop()
-        test.output.print_line("tor shut down unexpectedly", *ERROR_ATTR)
+        test.output.print_error("tor shut down unexpectedly")
 
       return bool(self._tor_process)
 
@@ -707,7 +706,7 @@ class Runner(object):
         os.makedirs(self._test_dir)
         test.output.print_line("done", *STATUS_ATTR)
     except OSError, exc:
-      test.output.print_line("failed (%s)" % exc, *ERROR_ATTR)
+      test.output.print_error("failed (%s)" % exc)
       raise exc
 
     # Tor checks during startup that the directory a control socket resides in
@@ -728,7 +727,7 @@ class Runner(object):
           os.chmod(socket_dir, 0700)
           test.output.print_line("done", *STATUS_ATTR)
       except OSError, exc:
-        test.output.print_line("failed (%s)" % exc, *ERROR_ATTR)
+        test.output.print_error("failed (%s)" % exc)
         raise exc
 
     # configures logging
@@ -769,7 +768,7 @@ class Runner(object):
 
       print
     except Exception, exc:
-      test.output.print_line("failed (%s)\n" % exc, *ERROR_ATTR)
+      test.output.print_error("failed (%s)\n" % exc)
       raise OSError(exc)
 
   def _start_tor(self, tor_cmd):
@@ -799,5 +798,5 @@ class Runner(object):
       runtime = time.time() - start_time
       test.output.print_line("  done (%i seconds)\n" % runtime, *STATUS_ATTR)
     except OSError, exc:
-      test.output.print_line("  failed to start tor: %s\n" % exc, *ERROR_ATTR)
+      test.output.print_error("  failed to start tor: %s\n" % exc)
       raise exc





More information about the tor-commits mailing list