def format_class_coverage(self, cover_character, klass, space1, progress, coverage, space2, lines, cover_threshold): '''Accepts coverage data for a class and returns a formatted string (intended for humans). ''' # FIXME: # Doesn't this *actually* print coverage for a module, and not a class? # preprocess raw data... klass = klass.lstrip('.') klass = blue(klass) MET_THRESHOLD = coverage >= cover_threshold coverage = '{prefix}{coverage:.1%}'.format( prefix=' ' if (coverage > 0.000) else '', coverage=coverage ) if MET_THRESHOLD: coverage = bold(coverage) coverage = white(coverage) # ...then format return ' {0} {klass}{space1}\t{progress}{coverage}{space2} {lines}'.format( # TODO: # * remove manual spacing, use .format() alignment cover_character, klass=klass, space1=space1, progress=dim('•' * progress), coverage=coverage, space2=space2, lines=lines )
def format_class_coverage(self, cover_character, klass, space1, progress, coverage, space2, lines, cover_threshold): '''Accepts coverage data for a class and returns a formatted string (intended for humans). ''' # FIXME: # Doesn't this *actually* print coverage for a module, and not a class? # preprocess raw data... klass = klass.lstrip('.') klass = blue(klass) MET_THRESHOLD = coverage >= cover_threshold coverage = '{prefix}{coverage:.1%}'.format(prefix=' ' if (coverage > 0.000) else '', coverage=coverage) if MET_THRESHOLD: coverage = bold(coverage) coverage = white(coverage) # ...then format return ' {0} {klass}{space1}\t{progress}{coverage}{space2} {lines}'.format( # TODO: # * remove manual spacing, use .format() alignment cover_character, klass=klass, space1=space1, progress=dim('•' * progress), coverage=coverage, space2=space2, lines=lines)
def format_overall_coverage(self, cover_character, max_length, progress, total_coverage): """Accepts overall coverage data and returns a formatted string (intended for humans). """ # preprocess raw data overall = blue("OVERALL") overall = bold(overall) space = " " * (max_length - len("OVERALL")) total = "{total_coverage:.1%}".format(total_coverage=total_coverage) total = white(bold(total)) # then format return " {0} {overall}{space}\t{progress} {total}".format( cover_character, overall=overall, space=space, progress="•" * progress, total=total )
def format_overall_coverage(self, cover_character, max_length, progress, total_coverage): '''Accepts overall coverage data and returns a formatted string (intended for humans). ''' # preprocess raw data overall = blue('OVERALL') overall = bold(overall) space = ' ' * (max_length - len('OVERALL')) total = '{total_coverage:.1%}'.format(total_coverage=total_coverage) total = white(bold(total)) # then format return ' {0} {overall}{space}\t{progress} {total}'.format( cover_character, overall=overall, space=space, progress='•' * progress, total=total)
def _print_traceback(): self.indent += 2 ### NOTE: ### Commented out try/except; potential debugging hinderance #try: traceback_args = None if (hasattr(test, 'topic') and hasattr(test['topic'], 'error') and test['topic']['error'] is not None): print '\n' + self.indent_msg(blue('Topic Error:')) traceback_args = tuple(*test['topic'].error) else: traceback_args = (test['error']['type'], test['error']['value'], test['error']['traceback']) self.print_traceback(*traceback_args) # except Exception: # # should never occur! # err_msg = '''Unexpected error in PyVows! # PyVows error occurred in: ({0!s}) # Context was: {1!r} # # ''' # # from os.path import abspath # raise VowsInternalError(err_msg, 'pyvows.reporting.test', ctx) # print file and line number if 'file' in test: file_msg = 'found in {test[file]} at line {test[lineno]}'.format( test=test) print print self.indent_msg(red(file_msg)) print self.indent -= 2
def _print_traceback(): self.indent += 2 ### NOTE: ### Commented out try/except; potential debugging hinderance #try: traceback_args = None if (hasattr(test, 'topic') and hasattr(test['topic'], 'error') and test['topic']['error'] is not None): print '\n' + self.indent_msg(blue('Topic Error:')) traceback_args = tuple(*test['topic'].error) else: traceback_args = (test['error']['type'], test['error']['value'], test['error']['traceback']) self.print_traceback(*traceback_args) # except Exception: # # should never occur! # err_msg = '''Unexpected error in PyVows! # PyVows error occurred in: ({0!s}) # Context was: {1!r} # # ''' # # from os.path import abspath # raise VowsInternalError(err_msg, 'pyvows.reporting.test', ctx) # print file and line number if 'file' in test: file_msg = 'found in {test[file]} at line {test[lineno]}'.format(test=test) print print self.indent_msg(red(file_msg)) print self.indent -= 2
def _print_traceback(): self.indent += 2 try: traceback_args = None if hasattr(test, 'topic') \ and hasattr(test['topic'], 'error') \ and test['topic']['error'] is not None: print '\n' + self.indent_msg(blue('Topic Error:')) traceback_args = tuple(*test['topic'].error) else: traceback_args = (test['error']['type'], test['error']['value'], test['error']['traceback']) self.print_traceback(*traceback_args) except Exception: # should never occur! err_msg = '''Unexpected error in PyVows! PyVows error occurred in: ({0!s}) Context was: {1!r} ''' # from os.path import abspath raise VowsInternalError(err_msg, 'pyvows.reporting.test', ctx) # print file and line number if 'file' in test: file_msg = 'found in {test[file]} at line {test[lineno]}'.format(test=test) print print self.indent_msg(red(file_msg)) print self.indent -= 2
def print_context(self, name, context, file=sys.stdout): # FIXME: Add Docstring # # * Is this only used in certain cases? # * If so, which? self.indent += 1 if (self.verbosity >= V_VERBOSE or not self.result.eval_context(context)): contextName = StringIO() self.humanized_print(name, file=contextName) contextName = contextName.getvalue().replace('\n', '') if context.get('skip', None): contextName += ' (SKIPPED: {0})'.format(str(context['skip'])) print(contextName, file=file) def _print_successful_test(): honored = ensure_encoded(VowsReporter.HONORED) topic = ensure_encoded(test['topic']) name = ensure_encoded(test['name']) if self.verbosity == V_VERBOSE: self.humanized_print('{0} {1}'.format(honored, name), file=file) elif self.verbosity >= V_EXTRA_VERBOSE: if test['enumerated']: self.humanized_print('{0} {1} - {2}'.format( honored, topic, name), file=file) else: self.humanized_print('{0} {1}'.format(honored, name), file=file) def _print_skipped_test(): if self.verbosity >= V_VERBOSE: message = StringIO() self.humanized_print('{0} {1}'.format(VowsReporter.SKIPPED, test['name']), file=message) message = message.getvalue().replace('\n', '') if test['skip'] != context['skip']: message = '{0} (SKIPPED: {1})'.format( message, str(test['skip'])) print(message, file=file) def _print_failed_test(): ctx = test['context_instance'] def _print_traceback(): self.indent += 2 ### NOTE: ### Commented out try/except; potential debugging hinderance #try: traceback_args = (test['error']['type'], test['error']['value'], test['error']['traceback']) self.print_traceback(*traceback_args, file=file) # except Exception: # # should never occur! # err_msg = '''Unexpected error in PyVows! # PyVows error occurred in: ({0!s}) # Context was: {1!r} # # ''' # # from os.path import abspath # raise VowsInternalError(err_msg, 'pyvows.reporting.test', ctx) # print file and line number if 'file' in test: file_msg = 'found in {test[file]} at line {test[lineno]}'.format( test=test) print('\n', self.indent_msg(red(file_msg)), '\n', file=file) self.indent -= 2 self.humanized_print('{0} {test}'.format(VowsReporter.BROKEN, test=test['name']), file=file) # print generated topic (if applicable) if ctx.generated_topic: value = yellow(test['topic']) self.humanized_print('', file=file) self.humanized_print('\tTopic value:', file=file) self.humanized_print('\t{value}'.format(value=value), file=file) self.humanized_print('\n' * 2, file=file) # print traceback _print_traceback() # Show any error raised by the setup, topic or teardown functions if context.get('error', None): e = context['error'] print('\n', self.indent_msg(blue("Error in {0!s}:".format(e.source))), file=file) self.print_traceback(*e.exc_info, file=file) else: for test in context['tests']: if VowsResult.test_is_successful(test): _print_successful_test() elif test['skip']: _print_skipped_test() else: _print_failed_test() # I hereby (re)curse you...! for context in context['contexts']: self.print_context(context['name'], context, file=file) self.indent -= 1
def print_context(self, name, context): # FIXME: Add Docstring # # * Is this only used in certain cases? # * If so, which? self.indent += 1 if (self.verbosity >= V_VERBOSE or not self.result.eval_context(context)): self.humanized_print(name) def _print_successful_context(): honored = ensure_encoded(VowsReporter.HONORED) topic = ensure_encoded(test['topic']) name = ensure_encoded(test['name']) if self.verbosity == V_VERBOSE: self.humanized_print('{0} {1}'.format(honored, name)) elif self.verbosity >= V_EXTRA_VERBOSE: if test['enumerated']: self.humanized_print('{0} {1} - {2}'.format(honored, topic, name)) else: self.humanized_print('{0} {1}'.format(honored, name)) def _print_failed_context(): ctx = test['context_instance'] def _print_traceback(): self.indent += 2 ### NOTE: ### Commented out try/except; potential debugging hinderance #try: traceback_args = (test['error']['type'], test['error']['value'], test['error']['traceback']) self.print_traceback(*traceback_args) # except Exception: # # should never occur! # err_msg = '''Unexpected error in PyVows! # PyVows error occurred in: ({0!s}) # Context was: {1!r} # # ''' # # from os.path import abspath # raise VowsInternalError(err_msg, 'pyvows.reporting.test', ctx) # print file and line number if 'file' in test: file_msg = 'found in {test[file]} at line {test[lineno]}'.format(test=test) print('\n', self.indent_msg(red(file_msg)), '\n') self.indent -= 2 self.humanized_print('{0} {test}'.format( VowsReporter.BROKEN, test=test['name'])) # print generated topic (if applicable) if ctx.generated_topic: value = yellow(test['topic']) self.humanized_print('') self.humanized_print('\tTopic value:') self.humanized_print('\t{value}'.format(value=value)) self.humanized_print('\n' * 2) # print traceback _print_traceback() # Show any error raised by the setup, topic or teardown functions if context.get('error', None): e = context['error'] print('\n', self.indent_msg(blue("Error in {0!s}:".format(e.source)))) self.print_traceback(*e.exc_info) print(self.indent_msg(red("Nested tests following this error have not been run."))) else: for test in context['tests']: if test['succeeded']: _print_successful_context() else: _print_failed_context() # I hereby (re)curse you...! for context in context['contexts']: self.print_context(context['name'], context) self.indent -= 1
def print_context(self, name, context, file=sys.stdout): # FIXME: Add Docstring # # * Is this only used in certain cases? # * If so, which? self.indent += 1 if (self.verbosity >= V_VERBOSE or not self.result.eval_context(context)): contextName = StringIO() self.humanized_print(name, file=contextName) contextName = contextName.getvalue().replace('\n', '') if context.get('skip', None): contextName += ' (SKIPPED: {0})'.format(str(context['skip'])) print(contextName, file=file) def _print_successful_test(): honored = ensure_encoded(VowsReporter.HONORED) topic = ensure_encoded(test['topic']) name = ensure_encoded(test['name']) if self.verbosity == V_VERBOSE: self.humanized_print('{0} {1}'.format(honored, name), file=file) elif self.verbosity >= V_EXTRA_VERBOSE: if test['enumerated']: self.humanized_print('{0} {1} - {2}'.format(honored, topic, name), file=file) else: self.humanized_print('{0} {1}'.format(honored, name), file=file) def _print_pending_test(): pending = ensure_encoded(VowsReporter.PENDING) topic = ensure_encoded(test['topic']) name = ensure_encoded(test['name']) if self.verbosity == V_VERBOSE: self.humanized_print('{0} {1}'.format(pending, name), file=file, color=cyan) elif self.verbosity >= V_EXTRA_VERBOSE: if test['enumerated']: self.humanized_print('{0} {1} - {2}'.format(pending, topic, name), file=file, color=cyan) else: self.humanized_print('{0} {1}'.format(pending, name), file=file, color=cyan) def _print_skipped_test(): if self.verbosity >= V_VERBOSE: message = StringIO() self.humanized_print('{0} {1}'.format(VowsReporter.SKIPPED, test['name']), file=message) message = message.getvalue().replace('\n', '') if test['skip'] != context['skip']: message = '{0} (SKIPPED: {1})'.format(message, str(test['skip'])) print(message, file=file) def _print_failed_test(): ctx = test['context_instance'] def _print_traceback(): self.indent += 2 ### NOTE: ### Commented out try/except; potential debugging hinderance #try: traceback_args = (test['error']['type'], test['error']['value'], test['error']['traceback']) self.print_traceback(*traceback_args, file=file) # except Exception: # # should never occur! # err_msg = '''Unexpected error in PyVows! # PyVows error occurred in: ({0!s}) # Context was: {1!r} # # ''' # # from os.path import abspath # raise VowsInternalError(err_msg, 'pyvows.reporting.test', ctx) # print file and line number if 'file' in test: file_msg = 'found in {test[file]} at line {test[lineno]}'.format(test=test) print('\n', self.indent_msg(red(file_msg)), '\n', file=file) self.indent -= 2 self.humanized_print('{0} {test}'.format(VowsReporter.BROKEN, test=test['name']), file=file) # print generated topic (if applicable) if ctx.generated_topic: value = yellow(test['topic']) self.humanized_print('', file=file) self.humanized_print('\tTopic value:', file=file) self.humanized_print('\t{value}'.format(value=value), file=file) self.humanized_print('\n' * 2, file=file) # print traceback _print_traceback() # Show any error raised by the setup, topic or teardown functions if context.get('error', None): e = context['error'] print('\n', self.indent_msg(blue("Error in {0!s}:".format(e.source))), file=file) self.print_traceback(*e.exc_info, file=file) else: for test in context['tests']: if VowsResult.test_is_successful(test): _print_successful_test() elif test['pending']: _print_pending_test() elif test['skip']: _print_skipped_test() else: _print_failed_test() # I hereby (re)curse you...! for context in context['contexts']: self.print_context(context['name'], context, file=file) self.indent -= 1