def test_load_config_env_var_empty(): os.environ['FOE_CONFIG'] = '' cfg = load_config() for section, options in _defaults.items(): assert cfg.has_section(section) for option in options.keys(): assert cfg.has_option(section, option) assert cfg.get(section, option) == os.path.expanduser(os.path.expandvars(options[option]))
def test_show_all_matches(): cfg = load_config() find_settings = load_settings() find_settings['dirs'] = [os.path.dirname(__file__)] find_settings['file_patterns'] = '*{file}'.format(file=os.path.basename(__file__)) find_settings['pattern'] = 'test' assert execute_module_command(show_command, command=show_command.commands[0], command_line=[], cfg=cfg, find_settings=find_settings)
def test_edit_at_least_one_match(): cfg = load_config() cfg.set('edit', 'editor', 'echo') find_settings = load_settings() find_settings['dirs'] = [os.path.dirname(__file__)] find_settings['file_patterns'] = '*{file}'.format(file=os.path.basename(__file__)) find_settings['pattern'] = 'test' assert execute_module_command(edit_command, command=edit_command.commands[0], command_line=['1'], cfg=cfg, find_settings=find_settings)
def test_edit_current_dir(): cfg = load_config() find_settings = load_settings() find_settings['dirs'] = [os.path.dirname(__file__)] assert not execute_module_command(edit_command, command=edit_command.commands[0], command_line=['1'], cfg=cfg, find_settings=find_settings)
def test_edit_no_settings(): cfg = load_config() assert not execute_module_command(edit_command, command=edit_command.commands[0], command_line=['1'], cfg=cfg)
def test_edit_number_invalid(): cfg = load_config() assert not execute_module_command(edit_command, command=edit_command.commands[0], command_line=['0'], cfg=cfg)
def test_print_match_interactive_mode(): cfg = load_config() m = re.search(r'test', 'test') match = {'match': m, 'filename': 'test', 'line': '1337'} assert find_command.print_match(match, 1337, cfg=cfg, interactive=True) is None
def test_foe_pattern_print_format_unknown_key(): cfg = load_config() cfg.set('match', 'PRINT_FORMAT', '{asdf}') assert not execute_module_command(find_command, command=find_command.commands[0], command_line=['test', '-f', __file__], cfg=cfg)
def test_foe_pattern_match(): assert execute_module_command(find_command, command=find_command.commands[0], command_line=['test', '-f', __file__], cfg=load_config())
def test_history_file(): with tempfile.NamedTemporaryFile() as f: cfg = load_config() cfg.set('interactive', 'HISTORY_FILE', f.name) assert _setup_readline(cfg=cfg)
def test_no_history_file(): cfg = load_config() cfg.set('interactive', 'HISTORY_FILE', '') assert _setup_readline(cfg=cfg)