def test_printer_with_disalbed_colored(): report_stream = StringIO() printer = Printer(report_stream, enable_color=True) printer(_colorized('A', _style_1)) printer(_colorized('B', _style_2)) printer('C') assert report_stream.getvalue().splitlines() == ['A', 'B', 'C']
def slash_list_plugins(args, report_stream=sys.stdout): parser = _get_parser() parsed_args = parser.parse_args(args) _print = Printer(report_stream, force_color=parsed_args.force_color, enable_color=parsed_args.enable_color) site.load() active = manager.get_future_active_plugins() for plugin in sorted( manager.get_installed_plugins(include_internals=False).values(), key=lambda p: p.get_name()): name = plugin.get_name() _print(_title_style(name), end=' ') if name in active: _print( _enabled_style( 'active (use --without-{} to deactivate'.format(name))) else: _print( _disabled_style( 'inactive (use --with-{} to activate)'.format(name))) if plugin.__doc__: for line in plugin.__doc__.splitlines(): if line.strip(): _print('\t', line.strip()) return 0
def test_printer_with_forced_colored(): report_stream = StringIO() printer = Printer(report_stream, force_color=True) expected_lines = [] for string, style in [('A', _style_1), ('B', _style_2), ('C', None)]: colored_string = _colorized(string, style) printer(colored_string) expected_lines.append( colored_string.colorize() if style else str(colored_string)) # pylint: disable=no-member assert report_stream.getvalue().splitlines() == expected_lines
def test_printer_with_output_disabled(force_color, enable_color): report_stream = StringIO() printer = Printer(report_stream, enable_output=False, force_color=force_color, enable_color=enable_color) printer(_colorized('A', _style_1)) printer(_colorized('B', _style_2)) printer('C') assert not report_stream.getvalue()
def slash_list(args, report_stream=sys.stdout, error_stream=sys.stderr): _print = partial(print, file=report_stream) parser = _get_parser() parsed_args = parser.parse_args(args) if parsed_args.filter_strings: config.root.run.filter_strings.extend(parsed_args.filter_strings) _print = Printer(report_stream, enable_output=parsed_args.show_output, force_color=parsed_args.force_color, enable_color=parsed_args.enable_color, error_stream=error_stream) try: slash.site.load() with slash.Session() as session: if not parsed_args.paths and not parsed_args.suite_files: parsed_args.paths = config.root.run.default_sources if not parsed_args.paths and not parsed_args.suite_files: parser.error( 'Neither test paths nor suite files were specified') loader = slash.loader.Loader() runnables = loader.get_runnables( itertools.chain(parsed_args.paths, iter_suite_file_paths( parsed_args.suite_files))) used_fixtures = set() for test in runnables: used_fixtures.update(test.get_required_fixture_objects()) if parsed_args.only in (None, 'fixtures'): _report_fixtures(parsed_args, session, _print, used_fixtures) if parsed_args.only in (None, 'tests'): _report_tests(parsed_args, runnables, _print) if bool(session.warnings.warnings) and parsed_args.warnings_as_errors: return -1 if len(runnables): # pylint: disable=len-as-condition return 0 except CannotLoadTests as e: _print(_error_style('Could not load tests ({})'.format(e)), error=True) return -1 print('No tests were found!', file=sys.stderr) return int(not parsed_args.allow_empty)
def list_config(args, report_stream=sys.stdout): args = _parse_args(args) _print = Printer(report_stream, force_color=args.force_color, enable_color=args.enable_color) filters = _parse_filters(args.paths) with slash.Session(): slash.site.load() for name, value in sorted(slash.config.traverse_leaves()): if not _is_included(name, filters): continue _print(_config_name_style(name), '--') _print(_INDENT, 'default:', _default_style(value.get_value())) if value.metadata and 'doc' in value.metadata: _print(_INDENT, value.metadata['doc']) return 0