def _prepare_matrix_for_display(matrix, verbose=False): try: type_label_mapping = loader.loader.get_type_label_mapping() decorator_mapping = loader.loader.get_decorator_mapping() except RuntimeError: # When running with --resolver this will fall here, and should use # the default mapping pass colored_matrix = [] for item in matrix: cls = item[0] try: decorator = decorator_mapping[cls] type_label = decorator(type_label_mapping[cls]) except (KeyError, UnboundLocalError): # In this case nrunner will not be available on decorator_map, # so we are using the default "healthy_str" type_label = TERM_SUPPORT.healthy_str(cls) if verbose: colored_matrix.append( (type_label, item[1], _get_tags_as_string(item[2] or {}))) else: colored_matrix.append((type_label, item[1])) return colored_matrix
def _display(self, suite, matrix): header = None verbose = suite.config.get('core.verbose') if verbose: header = (TERM_SUPPORT.header_str('Type'), TERM_SUPPORT.header_str('Test'), TERM_SUPPORT.header_str('Tag(s)')) # Any kind of color, string format and term specific should be applied # only during output/display phase. So this seems to be a better place # for this: matrix = self._prepare_matrix_for_display(matrix, verbose) for line in iter_tabular_output(matrix, header=header, strip=True): LOG_UI.debug(line) self._display_extra(suite, verbose)
def _display_extra(suite, verbose=True): """Display extra data when in verbose mode.""" if not verbose: return if suite.resolutions: resolution_header = ( TERM_SUPPORT.header_str("Resolver"), TERM_SUPPORT.header_str("Reference"), TERM_SUPPORT.header_str("Info"), ) LOG_UI.info("") mapping = { ReferenceResolutionResult.SUCCESS: TERM_SUPPORT.healthy_str, ReferenceResolutionResult.NOTFOUND: TERM_SUPPORT.fail_header_str, ReferenceResolutionResult.ERROR: TERM_SUPPORT.fail_header_str, } resolution_matrix = [] for r in suite.resolutions: decorator = mapping.get(r.result, TERM_SUPPORT.warn_header_str) if r.result == ReferenceResolutionResult.SUCCESS: continue resolution_matrix.append( (decorator(r.origin), r.reference, r.info or "") ) for line in iter_tabular_output( resolution_matrix, header=resolution_header, strip=True ): LOG_UI.info(line) LOG_UI.info("") LOG_UI.info("TEST TYPES SUMMARY") LOG_UI.info("==================") for key in sorted(suite.stats): LOG_UI.info("%s: %s", key, suite.stats[key]) if suite.tags_stats: LOG_UI.info("") LOG_UI.info("TEST TAGS SUMMARY") LOG_UI.info("=================") for key in sorted(suite.tags_stats): LOG_UI.info("%s: %s", key, suite.tags_stats[key])
def download_assets(): all_assets = asset.get_all_assets() all_assets_sorted = [] if all_assets: logging.info("Available download assets:") title_list = [a['title'] for a in all_assets] for index, title in enumerate(sorted(title_list)): asset_info = [a for a in all_assets if a['title'] == title][0] all_assets_sorted.append(asset_info) asset_present_str = TERM_SUPPORT.partial_str('Missing') if asset_info['asset_exists']: asset_present_str = TERM_SUPPORT.healthy_str('Present') asset_msg = ("%s - [%s] %s (%s)" % (index + 1, asset_present_str, TERM_SUPPORT.header_str(asset_info['title']), asset_info['destination'])) logging.info(asset_msg) indexes = raw_input("Type the index for the assets you want to " "download (comma separated, leave empty to abort): ") index_list = [] for idx in indexes.split(","): try: assert int(idx) > 0 index = int(idx) - 1 index_list.append(index) all_assets_sorted[index] except (ValueError, IndexError, AssertionError): logging.error("Invalid index(es), aborting...") sys.exit(1) for idx in index_list: asset_info = all_assets_sorted[idx] try: asset.download_file(asset_info, interactive=True) except urllib2.HTTPError, http_error: logging.error("HTTP Error %s: URL %s", http_error.code, asset_info['url']) os.remove(asset_info['destination'])
def _prepare_matrix_for_display(matrix, verbose=False): colored_matrix = [] for item in matrix: cls = item[0] type_label = TERM_SUPPORT.healthy_str(cls) if verbose: colored_matrix.append( (type_label, item[1], _get_tags_as_string(item[2] or {}))) else: colored_matrix.append((type_label, item[1])) return colored_matrix
def download_assets(): all_assets = asset.get_all_assets() all_assets_sorted = [] if all_assets: logging.info("Available download assets:") title_list = [a['title'] for a in all_assets] for index, title in enumerate(sorted(title_list)): asset_info = [a for a in all_assets if a['title'] == title][0] all_assets_sorted.append(asset_info) asset_present_str = TERM_SUPPORT.partial_str('Missing') if asset_info['asset_exists']: asset_present_str = TERM_SUPPORT.healthy_str('Present') asset_msg = ("%s - [%s] %s (%s)" % (index + 1, asset_present_str, TERM_SUPPORT.header_str( asset_info['title']), asset_info['destination'])) logging.info(asset_msg) indexes = input("Type the index for the assets you want to " "download (comma separated, leave empty to abort): ") index_list = [] for idx in indexes.split(","): try: assert int(idx) > 0 index = int(idx) - 1 index_list.append(index) all_assets_sorted[index] except (ValueError, IndexError, AssertionError): logging.error("Invalid index(es), aborting...") sys.exit(1) for idx in index_list: asset_info = all_assets_sorted[idx] try: asset.download_file(asset_info, interactive=True) except urllib.error.HTTPError as http_error: logging.error("HTTP Error %s: URL %s", http_error.code, asset_info['url']) os.remove(asset_info['destination'])
def _display(self, suite, matrix, resolution=None): header = None verbose = suite.config.get('core.verbose') if verbose: header = (TERM_SUPPORT.header_str('Type'), TERM_SUPPORT.header_str('Test'), TERM_SUPPORT.header_str('Tag(s)')) for line in iter_tabular_output(matrix, header=header, strip=True): LOG_UI.debug(line) if verbose: LOG_UI.info("") LOG_UI.info("TEST TYPES SUMMARY") LOG_UI.info("==================") for key in sorted(suite.stats): LOG_UI.info("%s: %s", key, suite.stats[key]) if suite.tags_stats: LOG_UI.info("") LOG_UI.info("TEST TAGS SUMMARY") LOG_UI.info("=================") for key in sorted(suite.tags_stats): LOG_UI.info("%s: %s", key, suite.tags_stats[key]) if resolution: resolution_header = (TERM_SUPPORT.header_str('Resolver'), TERM_SUPPORT.header_str('Reference'), TERM_SUPPORT.header_str('Info')) LOG_UI.info("") for line in iter_tabular_output(resolution, header=resolution_header, strip=True): LOG_UI.info(line)
def _display(self, suite, matrix): header = None verbose = suite.config.get('core.verbose') if verbose: header = (TERM_SUPPORT.header_str('Type'), TERM_SUPPORT.header_str('Test'), TERM_SUPPORT.header_str('Tag(s)')) for line in iter_tabular_output(matrix, header=header, strip=True): LOG_UI.debug(line) if verbose: if suite.resolutions: resolution_header = (TERM_SUPPORT.header_str('Resolver'), TERM_SUPPORT.header_str('Reference'), TERM_SUPPORT.header_str('Info')) LOG_UI.info("") mapping = { ReferenceResolutionResult.SUCCESS: TERM_SUPPORT.healthy_str, ReferenceResolutionResult.NOTFOUND: TERM_SUPPORT.fail_header_str, ReferenceResolutionResult.ERROR: TERM_SUPPORT.fail_header_str } resolution_matrix = [] for r in suite.resolutions: decorator = mapping.get(r.result, TERM_SUPPORT.warn_header_str) if r.result == ReferenceResolutionResult.SUCCESS: continue resolution_matrix.append( (decorator(r.origin), r.reference, r.info or '')) for line in iter_tabular_output(resolution_matrix, header=resolution_header, strip=True): LOG_UI.info(line) LOG_UI.info("") LOG_UI.info("TEST TYPES SUMMARY") LOG_UI.info("==================") for key in sorted(suite.stats): LOG_UI.info("%s: %s", key, suite.stats[key]) if suite.tags_stats: LOG_UI.info("") LOG_UI.info("TEST TAGS SUMMARY") LOG_UI.info("=================") for key in sorted(suite.tags_stats): LOG_UI.info("%s: %s", key, suite.tags_stats[key])
def _get_resolution_matrix(suite): """Used for resolver.""" test_matrix = [] verbose = suite.config.get('core.verbose') for runnable in suite.tests: type_label = TERM_SUPPORT.healthy_str(runnable.kind) if verbose: tags_repr = [] tags = runnable.tags or {} for tag, vals in tags.items(): if vals: tags_repr.append("%s(%s)" % (tag, ",".join(vals))) else: tags_repr.append(tag) tags_repr = ",".join(tags_repr) test_matrix.append((type_label, runnable.uri, tags_repr)) else: test_matrix.append((type_label, runnable.uri)) return test_matrix