# -*- coding: utf-8 -*-
'''Contains the `VowsDefaultReporter` class, which handles output after tests
have been run.
'''
# pyvows testing engine
# https://github.com/heynemann/pyvows

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 Bernardo Heynemann heynemann@gmail.com
from __future__ import division

from pyvows.color import *
from pyvows.reporting.common import (
    VowsReporter,)



class VowsProfileReporter(VowsReporter):
    '''A VowsReporter which prints a profile of the 10 slowest topics.'''

    def print_profile(self, threshold):
        '''Prints the 10 slowest topics that took longer than `threshold`
        to test.
        '''

        MAX_PATH_SIZE = 30
        topics = self.result.get_worst_topics(number=10, threshold=threshold)

        if topics:
            print self.header('Slowest Topics')

            print yellow('       elapsed     Context File Path                 Context Name')
            for index, topic in enumerate(topics):
                name = self.under_split(topic['context'])
                name = self.camel_split(name)

                print Style.BRIGHT + ("%s#%02d%s    %.05fs    %s%s%" + str(MAX_PATH_SIZE) + "s%s%s    %s") % (
                        Fore.BLUE,
                        index + 1,
                        Fore.RESET,
                        topic['elapsed'],
                        Style.DIM,
                        Fore.WHITE,
                        topic['path'][-MAX_PATH_SIZE:],
                        Fore.RESET,
                        Style.BRIGHT,
                        name
                ) + Style.RESET_ALL

            print
@@ -351,16 +351,26 @@
 division
+%0Aimport os
 %0A%0Afrom p
@@ -706,24 +706,129 @@
        '''%0A%0A
+        '''Prints the 10 slowest topics that took longer than%0A        %60threshold%60 to test.%0A%0A        '''%0A%0A
         MAX_
@@ -843,9 +843,9 @@
 E = 
-3
+4
 0%0A  
@@ -1005,425 +1005,1029 @@
     
-print yellow('       elapsed     Context File Path                 Context Name')%0A            for index, topic in enumerate(topics):%0A                name = self.under_split(topic%5B'context'%5D)%0A                name = self.camel_split(name)%0A%0A                print Style.BRIGHT + (%22%25s#%2502d%25s    %25.05fs    %25s%25s%25%22 + str(MAX_PATH_SIZE) + %22s%25s%25s    %25s%22) %25 (%0A                        Fore.BLUE,%0A                        index + 1
+table_header =  yellow('  %7B0%7D'.format(dim('#')))%0A            table_header += yellow('  Elapsed     Context File Path                         ')%0A            table_header += yellow('  Context Name')%0A            print table_header%0A%0A            for index, topic in enumerate(topics):%0A                name = self.under_split(topic%5B'context'%5D)%0A                name = self.camel_split(name)%0A%0A                topic%5B'path'%5D = os.path.realpath(topic%5B'path'%5D)%0A                topic%5B'path'%5D = '%7B0!s%7D'.format(topic%5B'path'%5D)%0A                topic%5B'path'%5D = os.path.relpath(topic%5B'path'%5D, os.path.abspath(os.curdir))%0A%0A                data = %7B%0A                    'number': '%7Bnumber:#2%7D'.format(number   = index + 1),%0A                    'time'  : '%7Btime:.05f%7Ds'.format(time    = topic%5B'elapsed'%5D),%0A                    'path'  : '%7Bpath:%3C%7Bwidth%7D%7D'.format(path = topic%5B'path'%5D%5B-MAX_PATH_SIZE:%5D,%0A                                                       width=MAX_PATH_SIZE),%0A                    'name'  : '%7Bname%7D'.format(      name    = name)
 ,%0A  
@@ -2029,32 +2029,38 @@
 ),%0A             
+   %7D%0A%0A
            Fore.
@@ -2050,35 +2050,91 @@
 %0A           
-Fore.RESET,
+     for k,v in data.items():%0A                    if k == 'number':
 %0A           
@@ -2150,25 +2150,24 @@
     
-topic%5B'elapsed'%5D,
+colorized = blue
 %0A   
@@ -2187,22 +2187,23 @@
     
-    Style.DIM,
+if k == 'time':
 %0A   
@@ -2227,24 +2227,26 @@
     
-Fore.WHITE,%0A    
+colorized = green%0A
     
@@ -2265,178 +2265,348 @@
     
-topic%5B'path'%5D%5B-MAX_PATH_SIZE:%5D,%0A                        Fore.RESET,%0A                        Style.BRIGHT,%0A                        name%0A                ) + Style.RESET_ALL
+if k == 'path':%0A                        colorized = lambda x: dim(white(x))%0A                    if k == 'name':%0A                        colorized = green%0A%0A                    data%5Bk%5D = colorized(v)%0A%0A                print ' %7Bnumber%7D  %7Btime%7D%7B0%7D%7Bpath%7D%7B0%7D%7Bname%7D'.format(%0A                    4 * ' ',%0A                    **data%0A                )
 %0A%0A  

Update profile printing code