예제 #1
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:'
예제 #2
0
def test_get_command():
    with patch('thefuck.main.Popen') as Popen, \
            patch('thefuck.main.os.environ',
                  new_callable=lambda: {}), \
            patch('thefuck.main.wait_output',
                  return_value=True):
        Popen.return_value.stdout.read.return_value = b'stdout'
        Popen.return_value.stderr.read.return_value = b'stderr'
        assert main.get_command(Mock(), ['thefuck', 'apt-get',
                                         'search', 'vim']) \
               == types.Command('apt-get search vim', 'stdout', 'stderr')
        Popen.assert_called_once_with('apt-get search vim',
                                      shell=True,
                                      stdout=PIPE,
                                      stderr=PIPE,
                                      env={'LANG': 'C'})
        assert main.get_command(Mock(), ['']) is None
예제 #3
0
def Command(script='', stdout='', stderr=''):
    return types.Command(script, stdout, stderr)