Example #1
0
def test_too_many_arguments():
    try:
        execute_module_command(version_command, command=version_command.commands[0],
            command_line=[version_command.commands[0], version_command.commands[0]])
        assert False
    except SystemExit as e:
        assert e.code != 0
Example #2
0
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)
Example #3
0
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)
Example #4
0
def execute(parsed_args=None, interactive=False, *args, **kwargs):
    """ Executes the help command. """
    
    if not parsed_args or not parsed_args.command:
        if not interactive:
            usage = '%(prog)s [command line]'
        else:
            usage = argparse.SUPPRESS

        parser = argparse.ArgumentParser(prog=get_program_name(), description=get_description(),
                usage=usage, add_help=False)

        # Recursively search through foe command modules and
        # add an argument to the parser for each command.
        group = parser.add_argument_group(title='commands')
        for loader, name, ispkg in walk_packages(foe_commands.__path__):
            module = loader.find_module(name).load_module(name)
            module_commands = getattr(module, 'commands', [])
            module_description = getattr(module, 'description', '')
            non_dash_commands = list(filter(lambda c: not c.startswith('-'), module_commands))
            if non_dash_commands:
                group.add_argument(*non_dash_commands, help=module_description)
            dash_commands = list(filter(lambda c: c.startswith('-'), module_commands))
            if dash_commands and not interactive:
                group.add_argument(*dash_commands, help=module_description, action='store_true')

        parser.print_help()
        return True
    else:
        # Recursively search through foe command modules.
        for loader, name, ispkg in walk_packages(foe_commands.__path__):
            module = loader.find_module(name).load_module(name)
            module_commands = getattr(module, 'commands', [])
            
            # If the command can be handled by the module,
            # and execute the command's help function.
            if parsed_args.command in module_commands:
                return execute_module_command(module, command=parsed_args.command, command_line=['-h'])

        print_invalid_command(parsed_args.command)
        return False
Example #5
0
def test_exit():
    assert execute_module_command(exit_command, command=exit_command.commands[0])
Example #6
0
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_invalid_command():
    assert execute_module_command(help_command, command='thisisaninvalidcommand') is None
Example #8
0
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)
Example #9
0
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_help():
    assert execute_module_command(help_command, command=help_command.commands[0])
Example #11
0
def test_edit_no_cfg():
    assert not execute_module_command(edit_command, command=edit_command.commands[0],
            command_line=['1'])
Example #12
0
def test_version():
    assert execute_module_command(version_command, command=version_command.commands[0])
def test_module_only():
    assert execute_module_command(help_command) is None
Example #14
0
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)
Example #15
0
def test_foe_pattern_match():
    assert execute_module_command(find_command, command=find_command.commands[0],
            command_line=['test', '-f', __file__], cfg=load_config())
Example #16
0
def test_foe_pattern_no_cfg():
    assert not execute_module_command(find_command, command=find_command.commands[0],
            command_line=['test', '-f', __file__])
Example #17
0
def test_foe_no_pattern():
    assert execute_module_command(find_command, command=find_command.commands[0])
def test_module_is_none():
    assert execute_module_command(None) is None
Example #19
0
def test_show_no_cfg():
    assert not execute_module_command(show_command, command=show_command.commands[0],
            command_line=['1'])
def test_module_is_not_a_command():
    assert execute_module_command(sys.modules[__name__]) is None