[tor-commits] [stem/master] Making test results right aligned and bold

atagar at torproject.org atagar at torproject.org
Fri Dec 30 18:15:42 UTC 2011


commit 8795873a50c722419700dec1fff56d289799a1c0
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Dec 28 10:24:58 2011 -0800

    Making test results right aligned and bold
    
    Instead of showing test results as...
    test.foo ... ok
    test.hello_world ... ok
    
    I'm now showing them like...
    test.foo           [OK]
    test.hello_world   [OK]
    
    with the result text bolded. Thanks to Josh Barr for the idea.
---
 run_tests.py      |    7 ++++++-
 stem/util/term.py |    5 +++++
 test/output.py    |   17 +++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index 2b9e412..fbed159 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -176,7 +176,12 @@ if __name__ == '__main__':
     print
   
   error_tracker = test.output.ErrorTracker()
-  output_filters = (error_tracker.get_filter(), test.output.strip_module, test.output.colorize)
+  output_filters = (
+    error_tracker.get_filter(),
+    test.output.strip_module,
+    test.output.align_results,
+    test.output.colorize,
+  )
   
   if run_unit_tests:
     print_divider("UNIT TESTS", True)
diff --git a/stem/util/term.py b/stem/util/term.py
index ef8d1b6..dd1a34e 100644
--- a/stem/util/term.py
+++ b/stem/util/term.py
@@ -43,6 +43,11 @@ def format(msg, *attr):
     attributes and ending with a reset
   """
   
+  # if we have reset sequences in the message then apply our attributes
+  # after each of them
+  if RESET in msg:
+    return "".join([format(comp, *attr) for comp in msg.split(RESET)])
+  
   encodings = []
   for text_attr in attr:
     text_attr, encoding = stem.util.enum.to_camel_case(text_attr), None
diff --git a/test/output.py b/test/output.py
index 9df9088..971aab9 100644
--- a/test/output.py
+++ b/test/output.py
@@ -79,6 +79,23 @@ def strip_module(line_type, line_content):
   if m: line_content = line_content.replace(m.groups()[0], "", 1)
   return line_content
 
+def align_results(line_type, line_content):
+  """
+  Strips the normal test results, and adds a right aligned variant instead with
+  a bold attribute.
+  """
+  
+  if line_type == LineType.CONTENT: return line_content
+  
+  # strip our current ending
+  for ending in LINE_ENDINGS:
+    if LINE_ENDINGS[ending] == line_type:
+      line_content = line_content.rstrip(ending).rstrip()
+      break
+  
+  new_ending = term.format(line_type.upper(), term.Attr.BOLD)
+  return "%-65s[%s]" % (line_content, new_ending)
+
 class ErrorTracker:
   """
   Stores any failure or error results we've encountered.





More information about the tor-commits mailing list