コード例 #1
0
def test_run_rule(capsys):
    with patch('thefuck.main.confirm', return_value=True):
        main.run_rule(main.Rule(None, lambda *_: 'new-command'),
                      None, None)
        assert capsys.readouterr() == ('new-command\n', '')
    with patch('thefuck.main.confirm', return_value=False):
        main.run_rule(main.Rule(None, lambda *_: 'new-command'),
                      None, None)
        assert capsys.readouterr() == ('', '')
コード例 #2
0
ファイル: test_main.py プロジェクト: ColeTownsend/cmon
def test_get_matched_rule():
    rules = [
        main.Rule(lambda x, _: x.script == 'cd ..', None),
        main.Rule(lambda *_: False, None)
    ]
    assert main.get_matched_rule(main.Command('ls', '', ''), rules,
                                 None) is None
    assert main.get_matched_rule(main.Command('cd ..', '', ''), rules,
                                 None) == rules[0]
コード例 #3
0
def test_get_matched_rule(capsys):
    rules = [
        main.Rule('', lambda x, _: x.script == 'cd ..', None),
        main.Rule('', lambda *_: False, None),
        main.Rule('rule', Mock(side_effect=OSError('Denied')), None)
    ]
    assert main.get_matched_rule(main.Command('ls', '', ''), rules,
                                 Mock(no_colors=True)) is None
    assert main.get_matched_rule(main.Command('cd ..', '', ''), rules,
                                 Mock(no_colors=True)) == rules[0]
    assert capsys.readouterr()[1].split('\n')[0]\
           == '[WARN] Rule rule:'
コード例 #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)) as load_source:
        assert main.load_rule(Path('/rules/bash.py')) == main.Rule(match, get_new_command)
        load_source.assert_called_once_with('bash', '/rules/bash.py')
コード例 #5
0
ファイル: test_main.py プロジェクト: vikstrous/thefuck
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)):
        glob.return_value = [PosixPath('bash.py'), PosixPath('lisp.py')]
        assert main.get_rules(Path('~'), Mock(rules=None)) == [
            main.Rule('bash', 'bash'),
            main.Rule('lisp', 'lisp'),
            main.Rule('bash', 'bash'),
            main.Rule('lisp', 'lisp')
        ]
        assert main.get_rules(Path('~'), Mock(rules=['bash'])) == [
            main.Rule('bash', 'bash'),
            main.Rule('bash', 'bash')
        ]