def test_allow_complete_section_mode_with_ignore_globs(self): project_dir = "/repo" project_files = ['/repo/hello.html'] ignore_globs = ["/repo/style.css"] used_languages = list(get_used_languages(project_files)) relevant_bears = filter_relevant_bears( used_languages, self.printer, self.arg_parser, {}) res = generate_settings( project_dir, project_files, ignore_globs, relevant_bears, {}, True) bears_list = res["all.HTML"]["bears"].value.replace(" ", "").split(",") files_list = res["all.HTML"]["files"].value.replace(" ", "").split(",") self.assertEqual( ['HTMLLintBear', 'coalaBear', 'BootLintBear', 'LicenseCheckBear', 'SpaceConsistencyBear', 'KeywordBear', 'LineLengthBear', 'DuplicateFileBear'].sort(), bears_list.sort()) ignore_file = str(os.path.normpath(self.path_leaf( str(res["all"]["ignore"])))) self.assertEqual(['**.html'], files_list) self.assertEqual('style.css', ignore_file)
def main(): arg_parser = _get_arg_parser() args = arg_parser.parse_args() printer = ConsolePrinter() log_printer = LogPrinter(printer) project_dir = os.getcwd() if not args.non_interactive: print_welcome_message(printer) project_dir = ask_question("What is your project directory?", default=project_dir, typecast=valid_path) project_files, ignore_globs = get_project_files(log_printer, printer, project_dir) used_languages = list(get_used_languages(project_files)) print_used_languages(printer, used_languages) relevant_bears = filter_relevant_bears(used_languages, arg_parser) print_relevant_bears(printer, relevant_bears) if args.non_interactive: unusable_bears = get_non_optional_settings_bears(relevant_bears) remove_unusable_bears(relevant_bears, unusable_bears) print_relevant_bears(printer, relevant_bears, 'usable') settings = generate_settings(project_dir, project_files, ignore_globs, relevant_bears) write_coafile(printer, project_dir, settings)
def test_get_used_languages(self): file_lists = [["/tmp/file.py", "/tmp/file.py"], ["/tmp/file.py", "/tmp/test.cpp"], ["/tmp/file.py"], ["/tmp/file.py", "/tmp/unknown.extension"], ["/tmp/unknown.extension"], []] results = [[('Python', 100)], [('Python', 50), ('C++', 50)], [('Python', 100)], [('Python', 50)], [], []] for file_list, expected_result in zip(file_lists, results): result = get_used_languages(file_list) self.assertEqual(sorted(result), sorted(expected_result))
def main(): arg_parser = _get_arg_parser() args = arg_parser.parse_args() logging.basicConfig(stream=sys.stdout) printer = ConsolePrinter() logging.getLogger(__name__) fpc = None project_dir = os.getcwd() if args.green_mode: args.non_interactive = None args.no_filter_by_capabilities = None args.incomplete_sections = None if not args.non_interactive and not args.green_mode: fpc = FilePathCompleter() fpc.activate() print_welcome_message(printer) printer.print(PROJECT_DIR_HELP) project_dir = ask_question('What is your project directory?', default=project_dir, typecast=valid_path) fpc.deactivate() project_files, ignore_globs = get_project_files(None, printer, project_dir, fpc, args.non_interactive) used_languages = list(get_used_languages(project_files)) print_used_languages(printer, used_languages) extracted_information = collect_info(project_dir) relevant_bears = filter_relevant_bears(used_languages, printer, arg_parser, extracted_information) if args.green_mode: collect_bear_settings(relevant_bears) print_relevant_bears(printer, relevant_bears) if args.non_interactive and not args.incomplete_sections: unusable_bears = get_non_optional_settings_bears(relevant_bears) remove_unusable_bears(relevant_bears, unusable_bears) print_relevant_bears(printer, relevant_bears, 'usable') settings = generate_settings(project_dir, project_files, ignore_globs, relevant_bears, extracted_information, args.incomplete_sections) write_coafile(printer, project_dir, settings)
def test_get_used_languages(self): file_lists = [["/tmp/file.py", "/tmp/file.py"], ["/tmp/file.py", "/tmp/test.cpp"], ["/tmp/file.py"], ["/tmp/file.py", "/tmp/unknown.extension"], ["/tmp/unknown.extension"], []] results = [[('Python', 100)], [('Python', 50), ('C++', 50)], [('Python', 100)], [('Python', 50)], [], []] for file_list, expected_result in zip(file_lists, results): result = get_used_languages(file_list) self.assertEqual(sorted(result), sorted(expected_result))
def main(): printer = ConsolePrinter() log_printer = LogPrinter(printer) print_welcome_message(printer) project_dir = ask_question("What is your project directory?", default=os.getcwd(), typecast=valid_path) project_files, ignore_globs = get_project_files(log_printer, printer, project_dir) used_languages = list(get_used_languages(project_files)) print_used_languages(printer, used_languages) relevant_bears = filter_relevant_bears(used_languages) print_relevant_bears(printer, relevant_bears) settings = generate_settings(project_dir, project_files, ignore_globs, relevant_bears) write_coafile(printer, project_dir, settings)
def test_allow_complete_section_mode(self): project_dir = "/repo" project_files = ['/repo/hello.html'] ignore_globs = [] used_languages = list(get_used_languages(project_files)) relevant_bears = filter_relevant_bears(used_languages) res = generate_settings(project_dir, project_files, ignore_globs, relevant_bears, True) bears_list = res["HTML"]["bears"].value.replace(" ", "").split(",") files_list = res["HTML"]["files"].value.replace(" ", "").split(",") self.assertEqual([ 'HTMLLintBear', 'coalaBear', 'BootLintBear', 'LicenseCheckBear', 'SpaceConsistencyBear', 'KeywordBear', 'LineLengthBear', 'DuplicateFileBear' ].sort(), bears_list.sort()) self.assertEqual(['**.html'], files_list)
def main(): global MAX_ARGS_GREEN_MODE, MAX_VALUES_GREEN_MODE arg_parser = _get_arg_parser() args = arg_parser.parse_args() logging.basicConfig(stream=sys.stdout) printer = ConsolePrinter() logging.getLogger(__name__) fpc = None project_dir = os.getcwd() if args.green_mode: args.no_filter_by_capabilities = None args.incomplete_sections = None if args.max_args: MAX_ARGS_GREEN_MODE = args.max_args if args.max_values: MAX_VALUES_GREEN_MODE = args.max_values if not args.green_mode and (args.max_args or args.max_values): logging.warning(' --max-args and --max-values can be used ' 'only with --green-mode. The arguments will ' 'be ignored.') if not args.non_interactive and not args.green_mode: fpc = FilePathCompleter() fpc.activate() print_welcome_message(printer) printer.print(PROJECT_DIR_HELP) project_dir = ask_question( 'What is your project directory?', default=project_dir, typecast=valid_path) fpc.deactivate() project_files, ignore_globs = get_project_files( None, printer, project_dir, fpc, args.non_interactive) used_languages = list(get_used_languages(project_files)) used_languages = ask_to_select_languages(used_languages, printer, args.non_interactive) extracted_information = collect_info(project_dir) relevant_bears = filter_relevant_bears( used_languages, printer, arg_parser, extracted_information) if args.green_mode: bear_settings_obj = collect_bear_settings(relevant_bears) green_mode( project_dir, ignore_globs, relevant_bears, bear_settings_obj, MAX_ARGS_GREEN_MODE, MAX_VALUES_GREEN_MODE, project_files, printer, ) exit() print_relevant_bears(printer, relevant_bears) if args.non_interactive and not args.incomplete_sections: unusable_bears = get_non_optional_settings_bears(relevant_bears) remove_unusable_bears(relevant_bears, unusable_bears) print_relevant_bears(printer, relevant_bears, 'usable') settings = generate_settings( project_dir, project_files, ignore_globs, relevant_bears, extracted_information, args.incomplete_sections) write_coafile(printer, project_dir, settings)
def main(): global MAX_ARGS_GREEN_MODE, MAX_VALUES_GREEN_MODE arg_parser = _get_arg_parser() args = arg_parser.parse_args() logging.basicConfig(stream=sys.stdout) printer = ConsolePrinter() logging.getLogger(__name__) fpc = None project_dir = os.getcwd() if args.green_mode: args.no_filter_by_capabilities = None args.incomplete_sections = None if args.max_args: MAX_ARGS_GREEN_MODE = args.max_args if args.max_values: MAX_VALUES_GREEN_MODE = args.max_values if not args.green_mode and (args.max_args or args.max_values): logging.warning(' --max-args and --max-values can be used ' 'only with --green-mode. The arguments will ' 'be ignored.') if not args.non_interactive and not args.green_mode: fpc = FilePathCompleter() fpc.activate() print_welcome_message(printer) printer.print(PROJECT_DIR_HELP) project_dir = ask_question('What is your project directory?', default=project_dir, typecast=valid_path) fpc.deactivate() project_files, ignore_globs = get_project_files(None, printer, project_dir, fpc, args.non_interactive) used_languages = list(get_used_languages(project_files)) used_languages = ask_to_select_languages(used_languages, printer, args.non_interactive) extracted_information = collect_info(project_dir) relevant_bears = filter_relevant_bears(used_languages, printer, arg_parser, extracted_information) if args.green_mode: bear_settings_obj = collect_bear_settings(relevant_bears) green_mode( project_dir, ignore_globs, relevant_bears, bear_settings_obj, MAX_ARGS_GREEN_MODE, MAX_VALUES_GREEN_MODE, project_files, printer, ) exit() print_relevant_bears(printer, relevant_bears) if args.non_interactive and not args.incomplete_sections: unusable_bears = get_non_optional_settings_bears(relevant_bears) remove_unusable_bears(relevant_bears, unusable_bears) print_relevant_bears(printer, relevant_bears, 'usable') settings = generate_settings(project_dir, project_files, ignore_globs, relevant_bears, extracted_information, args.incomplete_sections) write_coafile(printer, project_dir, settings)