def test_show_bears(self): with retrieve_stdout() as stdout: bears = {SomelocalBear: ['default', 'test'], SomeglobalBear: ['default', 'test']} print_bears(self.log_printer.printer, bears, False) expected_string = stdout.getvalue() self.maxDiff = None with retrieve_stdout() as stdout: show_bears(self.local_bears, self.global_bears, False, self.log_printer.printer) self.assertEqual(expected_string, stdout.getvalue()) with retrieve_stdout() as stdout: show_bears(self.local_bears, self.global_bears, True, self.log_printer.printer) self.assertEqual("SomeglobalBear\n" "==============\n" "Some global-bear Description.\n" "\n" "SomelocalBear\n" "=============\n" "Some local-bear Description.\n\n", stdout.getvalue())
def test_show_bears_with_json(self): args = default_arg_parser().parse_args(['--json']) with retrieve_stdout() as stdout: show_bears({}, {}, True, True, self.console_printer, args) self.assertEqual('{\n "bears": []\n}\n', stdout.getvalue()) self.logs.check(*self.deprecation_messages)
def main(): try: console_printer = ConsolePrinter() log_printer = LogPrinter(console_printer) # Note: We parse the args here once to check whether to show bears or # not. args = default_arg_parser().parse_args() if args.show_bears: local_bears, global_bears = get_filtered_bears(args.filter_by_language, log_printer) show_bears( local_bears, global_bears, args.show_description or args.show_details, args.show_details, console_printer, ) return 0 except BaseException as exception: # pylint: disable=broad-except return get_exitcode(exception, log_printer) partial_print_sec_beg = functools.partial(print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results, acquire_settings=acquire_settings, print_section_beginning=partial_print_sec_beg, nothing_done=nothing_done, ) return exitcode
def main(): configure_logging() try: console_printer = ConsolePrinter() log_printer = LogPrinter(console_printer) # Note: We parse the args here once to check whether to show bears or # not. args = default_arg_parser().parse_args() # Defer imports so if e.g. --help is called they won't be run from coalib.coala_modes import ( mode_format, mode_json, mode_non_interactive, mode_normal) from coalib.output.ConsoleInteraction import ( show_bears, show_language_bears_capabilities) console_printer = ConsolePrinter(print_colored=not args.no_color) configure_logging(not args.no_color) if args.json: # needs to be checked in order to display bears in json return mode_json(args) if args.show_bears: from coalib.settings.ConfigurationGathering import ( get_filtered_bears) local_bears, global_bears = get_filtered_bears( args.filter_by_language, log_printer) show_bears(local_bears, global_bears, args.show_description or args.show_details, args.show_details, console_printer) return 0 elif args.show_capabilities: from coalib.collecting.Collectors import ( filter_capabilities_by_languages) from coalib.settings.ConfigurationGathering import ( get_filtered_bears) local_bears, global_bears = get_filtered_bears( args.filter_by_language, log_printer) capabilities = filter_capabilities_by_languages( local_bears, args.show_capabilities) show_language_bears_capabilities(capabilities, console_printer) return 0 except BaseException as exception: # pylint: disable=broad-except return get_exitcode(exception, log_printer) if args.format: return mode_format() if args.non_interactive: return mode_non_interactive(console_printer, args) return mode_normal(console_printer, log_printer)
def main(): # Note: We parse the args here once to check whether to show bears or not. arg_parser = default_arg_parser() args = arg_parser.parse_args() console_printer = ConsolePrinter() if args.show_bears or args.show_all_bears: log_printer = LogPrinter(console_printer) sections, _ = load_configuration(arg_list=None, log_printer=log_printer) if args.show_all_bears: local_bears, global_bears = collect_all_bears_from_sections( sections, log_printer) else: # We ignore missing settings as it's not important. local_bears, global_bears = fill_settings( sections, acquire_settings=lambda *args, **kwargs: {}, log_printer=log_printer) show_bears(local_bears, global_bears, args.show_all_bears, console_printer) return 0 partial_print_sec_beg = functools.partial( print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results, acquire_settings=acquire_settings, print_section_beginning=partial_print_sec_beg, nothing_done=nothing_done) return exitcode
def main(): try: console_printer = ConsolePrinter() log_printer = LogPrinter(console_printer) # Note: We parse the args here once to check whether to show bears or # not. args = default_arg_parser().parse_args() if args.show_bears: sections, _ = load_configuration(arg_list=None, log_printer=log_printer) local_bears, global_bears = collect_all_bears_from_sections( sections, log_printer) if args.filter_by_language: local_bears = filter_section_bears_by_languages( local_bears, args.filter_by_language) global_bears = filter_section_bears_by_languages( global_bears, args.filter_by_language) show_bears(local_bears, global_bears, args.show_description or args.show_details, args.show_details, console_printer) return 0 except BaseException as exception: # pylint: disable=broad-except return get_exitcode(exception, log_printer) partial_print_sec_beg = functools.partial(print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results, acquire_settings=acquire_settings, print_section_beginning=partial_print_sec_beg, nothing_done=nothing_done) return exitcode
def test_show_bears(self, show_bear): local_bears = OrderedDict([('default', [SomelocalBear]), ('test', [SomelocalBear])]) show_bears(local_bears, {}, True, True, self.console_printer) show_bear.assert_called_once_with(SomelocalBear, True, True, self.console_printer, None) self.logs.check(*self.deprecation_messages)
def test_show_bears(self, show_bear): local_bears = OrderedDict([('default', [SomelocalBear]), ('test', [SomelocalBear])]) show_bears(local_bears, {}, True, True, self.console_printer) show_bear.assert_called_once_with(SomelocalBear, True, True, self.console_printer)
def main(): configure_logging() try: console_printer = ConsolePrinter() log_printer = LogPrinter(console_printer) # Note: We parse the args here once to check whether to show bears or # not. args = default_arg_parser().parse_args() # Defer imports so if e.g. --help is called they won't be run from coalib.coala_modes import (mode_format, mode_json, mode_non_interactive, mode_normal) from coalib.output.ConsoleInteraction import ( show_bears, show_language_bears_capabilities) console_printer = ConsolePrinter(print_colored=not args.no_color) configure_logging(not args.no_color) if args.json: # needs to be checked in order to display bears in json return mode_json(args) if args.show_bears: from coalib.settings.ConfigurationGathering import ( get_filtered_bears) local_bears, global_bears = get_filtered_bears( args.filter_by_language, log_printer) show_bears(local_bears, global_bears, args.show_description or args.show_details, args.show_details, console_printer) return 0 elif args.show_capabilities: from coalib.collecting.Collectors import ( filter_capabilities_by_languages) from coalib.settings.ConfigurationGathering import ( get_filtered_bears) local_bears, global_bears = get_filtered_bears( args.filter_by_language, log_printer) capabilities = filter_capabilities_by_languages( local_bears, args.show_capabilities) show_language_bears_capabilities(capabilities, console_printer) return 0 except BaseException as exception: # pylint: disable=broad-except return get_exitcode(exception, log_printer) if args.format: return mode_format() if args.non_interactive: return mode_non_interactive(console_printer, args) return mode_normal(console_printer, log_printer)
def main(): configure_logging() try: console_printer = ConsolePrinter() log_printer = LogPrinter(console_printer) # Note: We parse the args here once to check whether to show bears or # not. args = default_arg_parser().parse_args() console_printer = ConsolePrinter(print_colored=not args.no_color) if args.show_bears: from coalib.settings.ConfigurationGathering import ( get_filtered_bears) local_bears, global_bears = get_filtered_bears( args.filter_by_language, log_printer) show_bears(local_bears, global_bears, args.show_description or args.show_details, args.show_details, console_printer) return 0 elif args.show_capabilities: from coalib.collecting.Collectors import ( filter_capabilities_by_languages) from coalib.settings.ConfigurationGathering import ( get_filtered_bears) local_bears, global_bears = get_filtered_bears( args.filter_by_language, log_printer) capabilities = filter_capabilities_by_languages( local_bears, args.show_capabilities) show_language_bears_capabilities(capabilities, console_printer) return 0 except BaseException as exception: # pylint: disable=broad-except return get_exitcode(exception, log_printer) import functools from coalib.coala_main import run_coala partial_print_sec_beg = functools.partial(print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results, acquire_settings=acquire_settings, print_section_beginning=partial_print_sec_beg, nothing_done=nothing_done, console_printer=console_printer) return exitcode
def test_show_bears(self): with retrieve_stdout() as stdout: bears = {KeywordBear: ['default', 'test'], LineLengthBear: ['test'], SomeglobalBear: ['default', 'test']} print_bears(self.log_printer.printer, bears) expected_string = stdout.getvalue() self.maxDiff = None with retrieve_stdout() as stdout: show_bears(self.local_bears, self.global_bears, self.log_printer.printer) self.assertEqual(expected_string, stdout.getvalue())
def test_show_bears(self): with retrieve_stdout() as stdout: bears = {KeywordBear: ["default", "test"], LineLengthBear: ["test"], SomeglobalBear: ["default", "test"]} print_bears(self.log_printer.printer, bears, False) expected_string = stdout.getvalue() self.maxDiff = None with retrieve_stdout() as stdout: show_bears(self.local_bears, self.global_bears, False, self.log_printer.printer) self.assertEqual(expected_string, stdout.getvalue()) with retrieve_stdout() as stdout: show_bears(self.local_bears, self.global_bears, True, self.log_printer.printer) self.assertEqual(" * KeywordBear\n" " * LineLengthBear\n" " * SomeglobalBear\n", stdout.getvalue())
def test_show_bears_sorted(self): local_bears = OrderedDict([('default', [SomelocalBear]), ('test', [aSomelocalBear])]) global_bears = OrderedDict([('default', [SomeglobalBear]), ('test', [BSomeglobalBear])]) with retrieve_stdout() as stdout: show_bears(local_bears, global_bears, False, False, self.console_printer) self.assertEqual( stdout.getvalue(), 'aSomelocalBear\n' 'BSomeglobalBear\n' 'SomeglobalBear\n' 'SomelocalBear\n')
def test_show_bears_sorted(self): local_bears = OrderedDict([('default', [SomelocalBear]), ('test', [aSomelocalBear])]) global_bears = OrderedDict([('default', [SomeglobalBear]), ('test', [BSomeglobalBear])]) with retrieve_stdout() as stdout: show_bears(local_bears, global_bears, False, False, self.console_printer) self.assertEqual(stdout.getvalue(), 'aSomelocalBear\n' 'BSomeglobalBear\n' 'SomeglobalBear\n' 'SomelocalBear\n')
def main(): log_printer = LogPrinter(ConsolePrinter()) console_printer = ConsolePrinter() exitcode = 0 try: did_nothing = True yielded_results = False (sections, local_bears, global_bears, targets) = gather_configuration(acquire_settings, log_printer) if bool(sections["default"].get("show_bears", "False")): show_bears(local_bears, global_bears, console_printer) did_nothing = False else: for section_name in sections: section = sections[section_name] if not section.is_enabled(targets): continue file_diff_dict = {} print_section_beginning(console_printer, section) results = execute_section( section=section, global_bear_list=global_bears[section_name], local_bear_list=local_bears[section_name], print_results=print_results, log_printer=log_printer, file_diff_dict=file_diff_dict) yielded_results = yielded_results or results[0] finalize(file_diff_dict, results[3], log_printer) did_nothing = False if did_nothing: nothing_done(console_printer) if yielded_results: exitcode = 1 except BaseException as exception: # pylint: disable=broad-except exitcode = exitcode or get_exitcode(exception, log_printer) return exitcode
def test_show_bears(self): with retrieve_stdout() as stdout: bears = { KeywordBear: ['default', 'test'], LineLengthBear: ['test'], SomeglobalBear: ['default', 'test'] } print_bears(self.log_printer.printer, bears, False) expected_string = stdout.getvalue() self.maxDiff = None with retrieve_stdout() as stdout: show_bears(self.local_bears, self.global_bears, False, self.log_printer.printer) self.assertEqual(expected_string, stdout.getvalue()) with retrieve_stdout() as stdout: show_bears(self.local_bears, self.global_bears, True, self.log_printer.printer) self.assertEqual( " * KeywordBear\n" " * LineLengthBear\n" " * SomeglobalBear\n", stdout.getvalue())
def main(): try: console_printer = ConsolePrinter() log_printer = LogPrinter(console_printer) # Note: We parse the args here once to check whether to show bears or # not. args = default_arg_parser().parse_args() if args.show_bears: local_bears, global_bears = get_filtered_bears( args.filter_by_language, log_printer) show_bears(local_bears, global_bears, args.show_description or args.show_details, args.show_details, console_printer) return 0 elif args.show_capabilities: local_bears, global_bears = get_filtered_bears( args.filter_by_language, log_printer) capabilities = filter_capabilities_by_languages( local_bears, args.show_capabilities) show_language_bears_capabilities(capabilities, console_printer) return 0 except BaseException as exception: # pylint: disable=broad-except return get_exitcode(exception, log_printer) partial_print_sec_beg = functools.partial(print_section_beginning, console_printer) results, exitcode, _ = run_coala( print_results=print_results, acquire_settings=acquire_settings, print_section_beginning=partial_print_sec_beg, nothing_done=nothing_done) return exitcode
def main(debug=False): configure_logging() args = None # to have args variable in except block when parse_args fails try: # Note: We parse the args here once to check whether to show bears or # not. args = default_arg_parser().parse_args() if args.debug: req_ipdb = PipRequirement('ipdb') if not req_ipdb.is_installed(): logging.error( '--debug flag requires ipdb. ' 'You can install it with:\n%s', ' '.join(req_ipdb.install_command())) sys.exit(13) if debug or args.debug: args.log_level = 'DEBUG' # Defer imports so if e.g. --help is called they won't be run from coalib.coala_modes import (mode_format, mode_json, mode_non_interactive, mode_normal) from coalib.output.ConsoleInteraction import ( show_bears, show_language_bears_capabilities) console_printer = ConsolePrinter(print_colored=not args.no_color) configure_logging(not args.no_color) if args.show_bears: from coalib.settings.ConfigurationGathering import get_all_bears kwargs = {} if args.bears: kwargs['bear_globs'] = args.bears filtered_bears = get_all_bears(**kwargs) if args.filter_by_language: logging.warning("'--filter-by-language ...' is deprecated. " "Use '--filter-by language ...' instead.") if args.filter_by is None: args.filter_by = [] args.filter_by.append(['language'] + args.filter_by_language) if args.filter_by: # Each iteration of the following loop applies # filters one by one provided as arguments try: filtered_bears = apply_filters(args.filter_by, filtered_bears) except (InvalidFilterException, NotImplementedError) as ex: # If filter is not available or is unusable console_printer.print(ex) return 2 local_bears, global_bears = filtered_bears show_bears(local_bears, global_bears, args.show_description or args.show_details, args.show_details, console_printer, args) return 0 elif args.show_capabilities: from coalib.collecting.Collectors import ( filter_capabilities_by_languages) local_bears, _ = apply_filter('language', args.show_capabilities) capabilities = filter_capabilities_by_languages( local_bears, args.show_capabilities) show_language_bears_capabilities(capabilities, console_printer) return 0 if args.json: return mode_json(args, debug=debug) except BaseException as exception: # pylint: disable=broad-except if not isinstance(exception, SystemExit): if args and args.debug: import ipdb with ipdb.launch_ipdb_on_exception(): raise if debug: raise return get_exitcode(exception) if args.format: return mode_format(args, debug=debug) if args.non_interactive: return mode_non_interactive(console_printer, args, debug=debug) return mode_normal(console_printer, None, args, debug=debug)
def test_show_bears_empty(self): with retrieve_stdout() as stdout: show_bears({}, {}, True, True, self.console_printer) self.assertIn("No bears to show.", stdout.getvalue())
def test_show_bears_empty(self): with retrieve_stdout() as stdout: show_bears({}, {}, True, True, self.console_printer) self.assertIn('No bears to show.', stdout.getvalue())
def main(debug=False): configure_logging() args = None # to have args variable in except block when parse_args fails try: # Note: We parse the args here once to check whether to show bears or # not. args = default_arg_parser().parse_args() if args.debug: req_ipdb = PipRequirement('ipdb') if not req_ipdb.is_installed(): logging.error('--debug flag requires ipdb. ' 'You can install it with:\n%s', ' '.join(req_ipdb.install_command())) sys.exit(13) if debug or args.debug: args.log_level = 'DEBUG' # Defer imports so if e.g. --help is called they won't be run from coalib.coala_modes import ( mode_format, mode_json, mode_non_interactive, mode_normal) from coalib.output.ConsoleInteraction import ( show_bears, show_language_bears_capabilities) console_printer = ConsolePrinter(print_colored=not args.no_color) configure_logging(not args.no_color) if args.show_bears: from coalib.settings.ConfigurationGathering import get_all_bears kwargs = {} if args.bears: kwargs['bear_globs'] = args.bears filtered_bears = get_all_bears(**kwargs) if args.filter_by_language: logging.warning( "'--filter-by-language ...' is deprecated. " "Use '--filter-by language ...' instead.") if args.filter_by is None: args.filter_by = [] args.filter_by.append(['language'] + args.filter_by_language) if args.filter_by: # Each iteration of the following loop applies # filters one by one provided as arguments try: args.filter_by = filter_vector_to_dict(args.filter_by) filtered_bears = apply_filters( args.filter_by, filtered_bears) except (InvalidFilterException, NotImplementedError) as ex: # If filter is not available or is unusable console_printer.print(ex) return 2 local_bears, global_bears = filtered_bears show_bears(local_bears, global_bears, args.show_description or args.show_details, args.show_details, console_printer, args) return 0 elif args.show_capabilities: from coalib.collecting.Collectors import ( filter_capabilities_by_languages) local_bears, _ = apply_filter('language', args.show_capabilities) capabilities = filter_capabilities_by_languages( local_bears, args.show_capabilities) show_language_bears_capabilities(capabilities, console_printer) return 0 if args.json: return mode_json(args, debug=debug) except BaseException as exception: # pylint: disable=broad-except if not isinstance(exception, SystemExit): if args and args.debug: import ipdb with ipdb.launch_ipdb_on_exception(): raise if debug: raise return get_exitcode(exception) if args.format: return mode_format(args, debug=debug) if args.non_interactive: return mode_non_interactive(console_printer, args, debug=debug) return mode_normal(console_printer, None, args, debug=debug)
def test_show_bears_empty(self): with retrieve_stdout() as stdout: show_bears({}, {}, True, True, self.console_printer) self.assertIn('No bears to show.', stdout.getvalue()) self.logs.check(*self.deprecation_messages)