1import time 2 3 4class term_color: 5 BLUE = '\033[94m' 6 GREEN = '\033[92m' 7 YELLOW = '\033[93m' 8 RED = '\033[91m' 9 RESET = '\033[0m' 10 11 12ROBOT_LISTENER_API_VERSION = 3 13 14_x_start_time = {} 15 16 17def decorate(text): 18 indent_level = 6 19 box_length = 1 20 21 box_upper_corner = u'\u2554'.encode() 22 box_horizontal_element = u'\u2550' 23 box_vertical_element = u'\u2551'.encode() 24 box_lower_corner = u'\u255a'.encode() 25 26 initial_spacing = (" " * indent_level).encode() 27 line_prefix = u"\n".encode() + initial_spacing + box_vertical_element + u" ".encode() 28 horizontal_line = (box_horizontal_element * box_length).encode() 29 30 return (initial_spacing + box_upper_corner + horizontal_line \ 31 + line_prefix \ 32 + line_prefix.join([x.encode() for x in text.split("\n")]) \ 33 + u"\n".encode() + initial_spacing + box_lower_corner + horizontal_line).decode() 34 35def start_test(data, result): 36 # we have to flush manually, as the '-u' switch that should guarantee unbuffered output does not work on Windows 37 print("+++++ Starting test '{}'".format(data.longname), flush=True) 38 _x_start_time[data.longname] = time.time() 39 40 41def end_test(data, result): 42 status = "" 43 if result.passed: 44 status = term_color.GREEN + 'OK' + term_color.RESET 45 else: 46 if result.skipped: 47 status = term_color.BLUE + 'skipped' + term_color.RESET 48 elif 'non_critical' in result.tags: 49 status = term_color.YELLOW + 'failed (non critical)' + term_color.RESET 50 else: 51 status = term_color.RED + 'failed' + term_color.RESET 52 53 duration = time.time() - _x_start_time[data.longname] 54 del _x_start_time[data.longname] 55 56 print("+++++ Finished test '{0}' in {1:.2f} seconds with status {2}".format(data.longname, duration, status), flush=True) 57 58 if not result.passed: 59 print(decorate(result.message)) 60