def to_terminal(self): '''Yield lines to be printed in a terminal.''' average_cc = 0.0 analyzed = 0 for name, blocks in self.results: if 'error' in blocks: yield name, (blocks['error'], ), {'error': True} continue res, cc, n = cc_to_terminal( blocks, self.config.show_complexity, self.config.min, self.config.max, self.config.total_average, ) average_cc += cc analyzed += n if res: yield name, (), {} yield res, (), {'indent': 1} if (self.config.average or self.config.total_average) and analyzed: cc = average_cc / analyzed ranked_cc = cc_rank(cc) yield ( '\n{0} blocks (classes, functions, methods) analyzed.', (analyzed, ), {}, ) yield ( 'Average complexity: {0}{1} ({2}){3}', (RANKS_COLORS[ranked_cc], ranked_cc, cc, RESET), {}, )
def test_cc_to_terminal(self): # do the patching tools.LETTERS_COLORS = dict((l, '<!{0}!>'.format(l)) for l in 'FMC') tools.RANKS_COLORS = dict((r, '<|{0}|>'.format(r)) for r in 'ABCDEF') tools.BRIGHT = '@' tools.RESET = '__R__' results = CC_TO_TERMINAL_CASES res = [ '@<!C!>C __R__17:0 Classname - <|A|>A (4)__R__', '@<!M!>M __R__19:4 Classname.meth - <|B|>B (7)__R__', '@<!F!>F __R__12:0 f1 - <|C|>C (14)__R__', '@<!F!>F __R__12:0 f2 - <|D|>D (22)__R__', '@<!F!>F __R__12:0 f3 - <|E|>E (32)__R__', '@<!F!>F __R__12:0 f4 - <|F|>F (41)__R__', ] res_noshow = ['{0}__R__'.format(r[:r.index('(') - 1]) for r in res] self.assertEqual(tools.cc_to_terminal(results, False, 'A', 'F', False), (res_noshow, 120, 6)) self.assertEqual(tools.cc_to_terminal(results, True, 'A', 'F', False), (res, 120, 6)) self.assertEqual(tools.cc_to_terminal(results, True, 'A', 'D', False), (res[:-2], 47, 4)) self.assertEqual(tools.cc_to_terminal(results, False, 'A', 'D', False), (res_noshow[:-2], 47, 4)) self.assertEqual(tools.cc_to_terminal(results, True, 'C', 'F', False), (res[2:], 109, 4)) self.assertEqual(tools.cc_to_terminal(results, True, 'B', 'E', False), (res[1:-1], 75, 4)) self.assertEqual(tools.cc_to_terminal(results, True, 'B', 'F', True), (res[1:], 120, 6))
def to_terminal(self): '''Yield lines to be printed in a terminal.''' average_cc = .0 analyzed = 0 for name, blocks in self.results: if 'error' in blocks: yield name, (blocks['error'],), {'error': True} continue res, cc, n = cc_to_terminal(blocks, self.config.show_complexity, self.config.min, self.config.max, self.config.total_average) average_cc += cc analyzed += n if res: yield name, (), {} yield res, (), {'indent': 1} if (self.config.average or self.config.total_average) and analyzed: cc = average_cc / analyzed ranked_cc = cc_rank(cc) yield ('\n{0} blocks (classes, functions, methods) analyzed.', (analyzed,), {}) yield ('Average complexity: {0}{1} ({2}){3}', (RANKS_COLORS[ranked_cc], ranked_cc, cc, RESET), {})