1 # 2 # Copyright (C) 2015 The Android Open Source Project 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 # 16 from __future__ import print_function 17 18 import util 19 20 21 def format_stats_str(num_tests, stats, use_color): 22 pass_label = util.color_string('PASS', 'green') if use_color else 'PASS' 23 fail_label = util.color_string('FAIL', 'red') if use_color else 'FAIL' 24 skip_label = util.color_string('SKIP', 'yellow') if use_color else 'SKIP' 25 return '{pl} {p}/{t} {fl} {f}/{t} {sl} {s}/{t}'.format( 26 pl=pass_label, p=stats['pass'], 27 fl=fail_label, f=stats['fail'], 28 sl=skip_label, s=stats['skip'], 29 t=num_tests) 30 31 32 class Printer(object): 33 def print_results(self, results, stats): 34 raise NotImplementedError 35 36 37 class StdoutPrinter(Printer): 38 def __init__(self, use_color=False, show_all=False): 39 self.use_color = use_color 40 self.show_all = show_all 41 42 def print_results(self, results, stats): 43 print() 44 formatted = format_stats_str(stats.num_tests, 45 stats.global_stats, self.use_color) 46 print(formatted) 47 for suite, test_results in results.items(): 48 stats_str = format_stats_str(len(test_results), 49 stats.suite_stats[suite], 50 self.use_color) 51 print() 52 print('{}: {}'.format(suite, stats_str)) 53 for result in test_results: 54 if self.show_all or result.failed(): 55 print(result.to_string(colored=self.use_color)) 56