def test_known(self): self.assertEqual(tu.colorize_ansi('hello', 'blue', 'strike'), '\x1b[9;34mhello\x1b[0m') self.assertEqual(tu.colorize_ansi('hello', style='strike, inverse'), '\x1b[9;7mhello\x1b[0m') self.assertEqual(tu.colorize_ansi('hello', None, None), 'hello') self.assertEqual(tu.colorize_ansi('hello', '', ''), 'hello')
def add_message(self, msg_id, location, msg): """manage message of different types, and colorize output using ansi escape codes """ module, obj, line, _ = location[1:] if module not in self._modules: color, style = self._get_decoration('S') if module: modsep = colorize_ansi('************* Module %s' % module, color, style) else: modsep = colorize_ansi('************* %s' % module, color, style) self.writeln(modsep) self._modules[module] = 1 if obj: obj = ':%s' % obj if self.include_ids: sigle = msg_id else: sigle = msg_id[0] color, style = self._get_decoration(sigle) msg = colorize_ansi(msg, color, style) sigle = colorize_ansi(sigle, color, style) self.writeln('%s:%3s%s: %s' % (sigle, line, obj, msg))
def add_message(self, msg_id, location, msg): """manage message of different types, and colorize output using ansi escape codes """ module, obj, line, _ = location[1:] if module not in self._modules: color, style = self._get_decoration('S') if module: modsep = colorize_ansi('************* Module %s' % module, color, style) else: modsep = colorize_ansi('************* %s' % module, color, style) self.writeln(modsep) self._modules[module] = 1 if obj: obj = ':%s' % obj if self.include_ids: sigle = msg_id else: sigle = msg_id[0] color, style = self._get_decoration(sigle) msg = colorize_ansi(msg, color, style) sigle = colorize_ansi(sigle, color, style) self.writeln('%s:%3s%s: %s' % (sigle, line, obj, msg))
def format(self, record): msg = logging.Formatter.format(self, record) if record.levelname in self.colors: color = self.colors[record.levelname] return colorize_ansi(msg, color) else: for cf in self.colorfilters: color = cf(record) if color: return colorize_ansi(msg, color) return msg
def format(self, record): msg = logging.Formatter.format(self, record) if record.levelname in self.colors: color = self.colors[record.levelname] return colorize_ansi(msg, color) else: for cf in self.colorfilters: color = cf(record) if color: return colorize_ansi(msg, color) return msg
def add_message(self, msg_id, location, msg): """manage message of different types, and colorize output using ansi escape codes """ msg = Message(self, msg_id, location, msg) if msg.module not in self._modules: color, style = self._get_decoration("S") if msg.module: modsep = colorize_ansi("************* Module %s" % msg.module, color, style) else: modsep = colorize_ansi("************* %s" % msg.module, color, style) self.writeln(modsep) self._modules[msg.module] = 1 color, style = self._get_decoration(msg.C) for attr in ("msg", "symbol", "category", "C"): setattr(msg, attr, colorize_ansi(getattr(msg, attr), color, style)) self.write_message(msg)
def add_message(self, msg_id, location, msg): """manage message of different types, and colorize output using ansi escape codes """ msg = Message(self, msg_id, location, msg) if msg.module not in self._modules: color, style = self._get_decoration('S') if msg.module: modsep = colorize_ansi('************* Module %s' % msg.module, color, style) else: modsep = colorize_ansi('************* %s' % msg.module, color, style) self.writeln(modsep) self._modules[msg.module] = 1 color, style = self._get_decoration(msg.C) for attr in ('msg', 'symbol', 'category', 'C'): setattr(msg, attr, colorize_ansi(getattr(msg, attr), color, style)) self.write_message(msg)
def add_message(self, msg_id, location, msg): """manage message of different types, and colorize output using ansi escape codes """ msg = Message(self, msg_id, location, msg) if msg.module not in self._modules: color, style = self._get_decoration('S') if msg.module: modsep = colorize_ansi('************* Module %s' % msg.module, color, style) else: modsep = colorize_ansi('************* %s' % msg.module, color, style) self.writeln(modsep) self._modules.add(msg.module) color, style = self._get_decoration(msg.C) for attr in ('msg', 'symbol', 'category', 'C'): setattr(msg, attr, colorize_ansi(getattr(msg, attr), color, style)) self.write_message(msg)
def handle_message(self, msg): """manage message of different types, and colorize output using ansi escape codes """ if msg.module not in self._modules: color, style = self._get_decoration('S') if msg.module: modsep = colorize_ansi('************* Module %s' % msg.module, color, style) else: modsep = colorize_ansi('************* %s' % msg.module, color, style) self.writeln(modsep) self._modules.add(msg.module) color, style = self._get_decoration(msg.C) msg = msg._replace( **{attr: colorize_ansi(getattr(msg, attr), color, style) for attr in ('msg', 'symbol', 'category', 'C')}) self.write_message(msg)
def log(self, severity, path, line, msg): """log a message of a given severity line may be None if unknown """ self.counts[severity] += 1 severity_name = REVERSE_SEVERITIES[severity] msg = '%s:%s:%s:%s\n' % (severity_name[0], path, line or '', msg) if self.term_color: msg = colorize_ansi(msg, SEVERITIES_COLORS[severity_name]) self.out.write(msg)
def add_message(self, msg_id, location, msg): """manage message of different types, and colorize output using ansi escape codes """ module, obj, line, _ = location[1:] if module not in self._modules: color, style = self._get_decoration("S") if module: modsep = colorize_ansi("************* Module %s" % module, color, style) else: modsep = colorize_ansi("************* %s" % module, color, style) self.writeln(modsep) self._modules[module] = 1 if obj: obj = ":%s" % obj sigle = self.make_sigle(msg_id) color, style = self._get_decoration(sigle) msg = colorize_ansi(msg, color, style) sigle = colorize_ansi(sigle, color, style) self.writeln("%s:%3s%s: %s" % (sigle, line, obj, msg))
def fromTree(self, tree, filename="input_stream", base_uri=''): self._base_uris.append(base_uri) checker = ProjectChecker() if not checker.validate(tree, filename): raise MalformedProjectFile(str(checker)) sched = self.get_file(tree, "schedule") tasks = self.get_file(tree, "tasks") rsrc = self.get_file(tree, "resources") act = self.get_file(tree, "activities") self.project.root_task = self.read_tasks(tasks) self.read_resources_file(rsrc) self.project.add_activities( self.read_activities(act) ) if sched and not self.skip_schedule: try: file(sched,"r") except IOError, exc: print colorize_ansi("WARNING!", "red"), print (" %s. Proceeding without scheduling information." % exc) else: self.read_schedule(sched)
def run(self, test): "Run the given test case or test suite." result = self._makeResult() startTime = time() test(result, runcondition=self._runcondition, options=self.options) stopTime = time() timeTaken = stopTime - startTime result.printErrors() if not self.batchmode: self.stream.writeln(result.separator2) run = result.testsRun self.stream.writeln("Ran %d test%s in %.3fs" % (run, run != 1 and "s" or "", timeTaken)) self.stream.writeln() if not result.wasSuccessful(): if self.colorize: self.stream.write( textutils.colorize_ansi("FAILED", color='red')) else: self.stream.write("FAILED") else: if self.colorize: self.stream.write( textutils.colorize_ansi("OK", color='green')) else: self.stream.write("OK") failed, errored, skipped = list( map(len, (result.failures, result.errors, result.skipped))) det_results = [] for name, value in (("failures", result.failures), ("errors", result.errors), ("skipped", result.skipped)): if value: det_results.append("%s=%i" % (name, len(value))) if det_results: self.stream.write(" (") self.stream.write(', '.join(det_results)) self.stream.write(")") self.stream.writeln("") return result
def run(self, test): "Run the given test case or test suite." result = self._makeResult() startTime = time() test(result, runcondition=self._runcondition, options=self.options) stopTime = time() timeTaken = stopTime - startTime result.printErrors() if not self.batchmode: self.stream.writeln(result.separator2) run = result.testsRun self.stream.writeln("Ran %d test%s in %.3fs" % (run, run != 1 and "s" or "", timeTaken)) self.stream.writeln() if not result.wasSuccessful(): if self.colorize: self.stream.write(textutils.colorize_ansi("FAILED", color='red')) else: self.stream.write("FAILED") else: if self.colorize: self.stream.write(textutils.colorize_ansi("OK", color='green')) else: self.stream.write("OK") failed, errored, skipped = map(len, (result.failures, result.errors, result.skipped)) det_results = [] for name, value in (("failures", result.failures), ("errors",result.errors), ("skipped", result.skipped)): if value: det_results.append("%s=%i" % (name, len(value))) if det_results: self.stream.write(" (") self.stream.write(', '.join(det_results)) self.stream.write(")") self.stream.writeln("") return result
def _exc_info_to_string(self, err, test): """Converts a sys.exc_info()-style tuple of values into a string. This method is overridden here because we want to colorize lines if --color is passed, and display local variables if --verbose is passed """ exctype, exc, tb = err output = ['Traceback (most recent call last)'] frames = inspect.getinnerframes(tb) colorize = self.colorize frames = enumerate(self._iter_valid_frames(frames)) for index, (frame, filename, lineno, funcname, ctx, ctxindex) in frames: filename = osp.abspath(filename) if ctx is None: # pyc files or C extensions for instance source = '<no source available>' else: source = ''.join(ctx) if colorize: filename = textutils.colorize_ansi(filename, 'magenta') source = colorize_source(source) output.append(' File "%s", line %s, in %s' % (filename, lineno, funcname)) output.append(' %s' % source.strip()) if self.verbose: output.append('%r == %r' % (dir(frame), test.__module__)) output.append('') output.append(' ' + ' local variables '.center(66, '-')) for varname, value in sorted(frame.f_locals.items()): output.append(' %s: %r' % (varname, value)) if varname == 'self': # special handy processing for self for varname, value in sorted(vars(value).items()): output.append(' self.%s: %r' % (varname, value)) output.append(' ' + '-' * 66) output.append('') output.append(''.join(traceback.format_exception_only(exctype, exc))) return '\n'.join(output)
def test_known(self): self.assertEqual(tu.colorize_ansi('hello', 'blue', 'strike'), '\x1b[9;34mhello\x1b[0m') self.assertEqual(tu.colorize_ansi('hello', style='strike, inverse'), '\x1b[9;7mhello\x1b[0m') self.assertEqual(tu.colorize_ansi('hello', None, None), 'hello') self.assertEqual(tu.colorize_ansi('hello', '', ''), 'hello')