def test_get_config_path( custom_path_provided, custom_path_exists, custom_path_matches, default_path_provided, default_path_exists, default_path_matches, fake_custom_path_config_file, fake_base_directory, fake_default_config_name, ): custom_path = get_temp_file_path( remove_file=not custom_path_exists, return_empty=not custom_path_provided, temp_file=fake_custom_path_config_file, ) base_path = get_temp_file_path( remove_file=not default_path_exists, return_empty=not default_path_provided, temp_file=fake_base_directory, ) with patch('rozental_as_a_service.files_utils.DEFAULT_CONFIG_FILENAME', fake_default_config_name): result_path = get_config_path(base_path, custom_path) assert (result_path is None) == (custom_path_matches is False and default_path_matches is False) assert (result_path == custom_path) == (custom_path_matches is True) if result_path and base_path: assert (result_path.startswith(base_path)) == (default_path_matches is True)
def prepare_arguments(argparse_args: argparse.Namespace) -> RozentalOptions: config_path = get_config_path(argparse_args.path, argparse_args.config) config: Mapping[str, Any] = {} if config_path: config = get_params_from_config(config_path) default_processors_amount = multiprocessing.cpu_count() if os.path.isdir( argparse_args.path) else 1 processes_amount = argparse_args.processes or config.get( 'processes') or default_processors_amount if not os.path.exists(argparse_args.path): base_path = '.' else: base_path = (argparse_args.path if os.path.isdir(argparse_args.path) else os.path.dirname(os.path.abspath(argparse_args.path))) vocabulary_path = (argparse_args.vocabulary_path or config.get('vocabulary_path') or os.path.join(base_path, DEFAULT_VOCABULARY_FILENAME)) db_path = (argparse_args.db_path or config.get('db_path') or os.path.join(base_path, DEFAULT_SQLITE_DB_FILENAME)) exclude = argparse_args.exclude.split( ',') if argparse_args.exclude else config.get('exclude', []) exit_zero = argparse_args.exit_zero or config.get('exit_zero') or False verbosity = argparse_args.verbose or config.get('verbosity') or 0 process_dots = argparse_args.process_dots or config.get( 'process_dots') or False reorder_vocabulary = argparse_args.reorder_vocabulary or config.get( 'reorder_vocabulary') or False ban_obscene_words = argparse_args.ban_obscene_words or config.get( 'ban_obscene_words') or False return { 'path': argparse_args.path, 'vocabulary_path': vocabulary_path, 'exclude': exclude, 'db_path': db_path, 'exit_zero': exit_zero, 'reorder_vocabulary': reorder_vocabulary, 'process_dots': process_dots, 'processes_amount': processes_amount, 'verbosity': verbosity, 'ban_obscene_words': ban_obscene_words, }