Exemplo n.º 1
0
def test_run_rule(capsys):
    with patch('thefuck.main.confirm', return_value=True):
        main.run_rule(types.Rule('', None, lambda *_: 'new-command', True),
                      None, None)
        assert capsys.readouterr() == ('new-command\n', '')
    with patch('thefuck.main.confirm', return_value=False):
        main.run_rule(types.Rule('', None, lambda *_: 'new-command', True),
                      None, None)
        assert capsys.readouterr() == ('', '')
Exemplo n.º 2
0
def test_get_matched_rule(capsys):
    rules = [types.Rule('', lambda x, _: x.script == 'cd ..', None, True),
             types.Rule('', lambda *_: False, None, True),
             types.Rule('rule', Mock(side_effect=OSError('Denied')), None, True)]
    assert main.get_matched_rule(types.Command('ls', '', ''),
                                 rules, Mock(no_colors=True)) is None
    assert main.get_matched_rule(types.Command('cd ..', '', ''),
                                 rules, Mock(no_colors=True)) == rules[0]
    assert capsys.readouterr()[1].split('\n')[0] \
           == '[WARN] Rule rule:'
Exemplo n.º 3
0
def Rule(name='',
         match=lambda *_: True,
         get_new_command=lambda *_: '',
         enabled_by_default=True,
         side_effect=None,
         priority=DEFAULT_PRIORITY):
    return types.Rule(name, match, get_new_command, enabled_by_default,
                      side_effect, priority)
Exemplo n.º 4
0
def test_load_rule():
    match = object()
    get_new_command = object()
    with patch('thefuck.main.load_source',
               return_value=Mock(
                   match=match,
                   get_new_command=get_new_command,
                   enabled_by_default=True)) as load_source:
        assert main.load_rule(Path('/rules/bash.py')) \
               == types.Rule('bash', match, get_new_command, True)
        load_source.assert_called_once_with('bash', '/rules/bash.py')
Exemplo n.º 5
0
def test_get_rules():
    with patch('thefuck.main.Path.glob') as glob, \
            patch('thefuck.main.load_source',
                  lambda x, _: Mock(match=x, get_new_command=x,
                                    enabled_by_default=True)):
        glob.return_value = [PosixPath('bash.py'), PosixPath('lisp.py')]
        assert list(main.get_rules(
            Path('~'),
            Mock(rules=conf.DEFAULT_RULES))) \
               == [types.Rule('bash', 'bash', 'bash', True),
                   types.Rule('lisp', 'lisp', 'lisp', True),
                   types.Rule('bash', 'bash', 'bash', True),
                   types.Rule('lisp', 'lisp', 'lisp', True)]
        assert list(main.get_rules(
            Path('~'),
            Mock(rules=types.RulesNamesList(['bash'])))) \
               == [types.Rule('bash', 'bash', 'bash', True),
                   types.Rule('bash', 'bash', 'bash', True)]
Exemplo n.º 6
0
def Rule(name='', match=lambda *_: True,
         get_new_command=lambda *_: '',
         enabled_by_default=True):
    return types.Rule(name, match, get_new_command, enabled_by_default)