Browse Source

Merge pull request #1508 from TechEmpower/add-more-colors

Add more colors
Brittany Mazza 10 years ago
parent
commit
974c123a8f

+ 14 - 2
toolset/benchmark/framework_test.py

@@ -21,6 +21,8 @@ from threading import Event
 
 
 from utils import header
 from utils import header
 
 
+# Cross-platform colored text
+from colorama import Fore, Back, Style
 from datetime import datetime
 from datetime import datetime
 from datetime import timedelta
 from datetime import timedelta
 
 
@@ -382,12 +384,22 @@ class FrameworkTest:
       test.passed = all(result is 'pass' for (result, reason, url) in results)
       test.passed = all(result is 'pass' for (result, reason, url) in results)
       
       
       def output_result(result, reason, url):
       def output_result(result, reason, url):
-        out.write("   %s for %s\n" % (result.upper(), url))
-        print "   %s for %s" % (result.upper(), url)
+        specific_rules_url = "http://frameworkbenchmarks.readthedocs.org/en/latest/Project-Information/Framework-Tests/#specific-test-requirements"
+        color = Fore.GREEN
+        if result.upper() == "WARN":
+          color = Fore.YELLOW
+        elif result.upper() == "FAIL":
+          color = Fore.RED
+
+        out.write(("   " + color + "%s" + Style.RESET_ALL + " for %s\n") % (result.upper(), url))
+        print ("   " + color + "%s" + Style.RESET_ALL + " for %s\n") % (result.upper(), url)
         if reason is not None and len(reason) != 0:
         if reason is not None and len(reason) != 0:
           for line in reason.splitlines():
           for line in reason.splitlines():
             out.write("     " + line + '\n')
             out.write("     " + line + '\n')
             print "     " + line
             print "     " + line
+          if not test.passed:
+            out.write("     See %s\n" % specific_rules_url)
+            print "     See %s\n" % specific_rules_url
 
 
       [output_result(r1,r2,url) for (r1, r2, url) in results]
       [output_result(r1,r2,url) for (r1, r2, url) in results]
 
 

+ 3 - 3
toolset/benchmark/test_types/framework_test_type.py

@@ -63,13 +63,13 @@ class FrameworkTestType:
     # Use -i to output response with headers
     # Use -i to output response with headers
     # Don't use -f so that the HTTP response code is ignored.
     # Don't use -f so that the HTTP response code is ignored.
     # Use -sS to hide progress bar, but show errors.
     # Use -sS to hide progress bar, but show errors.
-    print "Accessing URL %s" % url
+    print "Accessing URL %s:" % url
     self.err.write("Accessing URL %s \n" % url)
     self.err.write("Accessing URL %s \n" % url)
     self.out.write("Accessing URL %s \n" % url)
     self.out.write("Accessing URL %s \n" % url)
     p = subprocess.Popen(["curl", "-m", "15", "-i", "-sS", url], stderr=PIPE, stdout=PIPE)
     p = subprocess.Popen(["curl", "-m", "15", "-i", "-sS", url], stderr=PIPE, stdout=PIPE)
     (out, err) = p.communicate()
     (out, err) = p.communicate()
     self.err.write(err+'\n')
     self.err.write(err+'\n')
-    self.out.write("Response: \n\"" + out+ "\"\n")
+    self.out.write("Response: \n\"" + out.strip() + "\"\n")
     if p.returncode != 0:
     if p.returncode != 0:
       return None
       return None
     return out
     return out
@@ -83,7 +83,7 @@ class FrameworkTestType:
     # Get response body
     # Get response body
     p = subprocess.Popen(["curl", "-m", "15", "-s", url], stdout=PIPE, stderr=PIPE)
     p = subprocess.Popen(["curl", "-m", "15", "-s", url], stdout=PIPE, stderr=PIPE)
     (out, err) = p.communicate()
     (out, err) = p.communicate()
-    print "  Response (trimmed to 40 bytes): \"%s\"" % out[:40]
+    print "  Response (trimmed to 40 bytes): \"%s\"" % out.strip()[:40]
     return out
     return out
   
   
   def verify(self, base_url):
   def verify(self, base_url):

+ 2 - 2
toolset/benchmark/test_types/plaintext_type.py

@@ -21,11 +21,11 @@ class PlaintextTestType(FrameworkTestType):
     body = body.lower()
     body = body.lower()
 
 
     if "hello, world!" not in body:
     if "hello, world!" not in body:
-      return [('fail', "Could not find 'Hello, World!' in response", url)]
+      return [('fail', """Could not find 'Hello, World!' in response.""", url)]
 
 
     if len("hello, world!") < len(body):
     if len("hello, world!") < len(body):
       return [('warn', """Server is returning %s more bytes than are required.
       return [('warn', """Server is returning %s more bytes than are required.
-        This may negatively affect benchmark performance""" % (len(body) - len("hello, world!")), url)]
+This may negatively affect benchmark performance.""" % (len(body) - len("hello, world!")), url)]
 
 
     # Ensure required response headers are present
     # Ensure required response headers are present
     if any(v.lower() not in full_response.lower() for v in ('Server','Date','Content-Type: text/plain')) \
     if any(v.lower() not in full_response.lower() for v in ('Server','Date','Content-Type: text/plain')) \