Пример #1
0
def test_match():
    assert match(
        Command('mkdir foo/bar/baz', '',
                'mkdir: foo/bar: No such file or directory'), None)
    assert not match(Command('mkdir foo/bar/baz', '', ''), None)
    assert not match(Command('mkdir foo/bar/baz', '', 'foo bar baz'), None)
    assert not match(Command('', '', ''), None)
Пример #2
0
def test_get_new_command(command_found):
    with patch('thefuck.rules.no_command._get_output',
               return_value=command_found.decode()):
        assert get_new_command(Command('aptget install vim', '', ''), settings)\
            == 'apt-get install vim'
        assert get_new_command(Command('sudo aptget install vim', '', ''), settings) \
            == 'sudo apt-get install vim'
Пример #3
0
def test_match(command_found, command_not_found, settings):
    with patch('thefuck.rules.no_command.Popen') as Popen:
        Popen.return_value.stderr.read.return_value = command_found
        assert match(Command('aptget install vim', '', ''), settings)
        Popen.assert_called_once_with('/usr/lib/command-not-found aptget',
                                      shell=True,
                                      stderr=PIPE)
        Popen.return_value.stderr.read.return_value = command_not_found
        assert not match(Command('ls', '', ''), settings)

    with patch('thefuck.rules.no_command.Popen') as Popen:
        Popen.return_value.stderr.read.return_value = command_found
        assert match(Command('sudo aptget install vim', '', ''),
                     Mock(command_not_found='test'))
        Popen.assert_called_once_with('test aptget', shell=True, stderr=PIPE)
Пример #4
0
def test_remove_offending_keys(ssh_error):
    errormsg, path, reset, known_hosts = ssh_error
    command = Command('ssh user@host', '', errormsg)
    remove_offending_keys(command, None)
    expected = [
        '123.234.567.890 asdjkasjdakjsd\n', '111.222.333.444 qwepoiwqepoiss\n'
    ]
    assert known_hosts(path) == expected
Пример #5
0
def test_get_new_command(ssh_error, monkeypatch):
    errormsg, _, _, _ = ssh_error

    method = Mock()
    monkeypatch.setattr('thefuck.rules.ssh_known_hosts.remove_offending_keys',
                        method)
    assert get_new_command(Command('ssh user@host', '', errormsg),
                           None) == 'ssh user@host'
    assert method.call_count
Пример #6
0
def test_match(ssh_error):
    errormsg, _, _, _ = ssh_error
    assert match(Command('ssh', '', errormsg), None)
    assert match(Command('ssh', '', errormsg), None)
    assert match(Command('scp something something', '', errormsg), None)
    assert match(Command('scp something something', '', errormsg), None)
    assert not match(Command('', '', errormsg), None)
    assert not match(Command('notssh', '', errormsg), None)
    assert not match(Command('ssh', '', ''), None)
def test_get_new_command(git_not_command):
    assert get_new_command(Command('git brnch', '', git_not_command), None)\
        == 'git branch'
def test_match(git_not_command, git_command):
    assert match(Command('git brnch', '', git_not_command), None)
    assert not match(Command('ls brnch', '', git_not_command), None)
    assert not match(Command('git branch', '', git_command), None)
Пример #9
0
def test_match():
    assert match(Command('cd..', '', 'cd..: command not found'), None)
    assert not match(Command('', '', ''), None)
Пример #10
0
def test_get_new_command():
    assert get_new_command(Command('cd..', '', ''), None) == 'cd ..'
Пример #11
0
def test_match():
    assert match(Command('', '', 'Permission denied'), None)
    assert match(Command('', '', 'permission denied'), None)
    assert match(Command('', '', "npm ERR! Error: EACCES, unlink"), None)
    assert not match(Command('', '', ''), None)
Пример #12
0
def test_get_new_command():
    assert get_new_command(Command('ls', '', ''), None) == 'sudo ls'
Пример #13
0
def test_get_new_command(git_not_command, git_not_command_one_of_this):
    assert get_new_command(Command('git brnch', '', git_not_command), None)\
        == 'git branch'
    assert get_new_command(
        Command('git st', '', git_not_command_one_of_this), None) == 'git status'
Пример #14
0
def test_match(git_not_command, git_command, git_not_command_one_of_this):
    assert match(Command('git brnch', '', git_not_command), None)
    assert match(Command('git st', '', git_not_command_one_of_this), None)
    assert not match(Command('ls brnch', '', git_not_command), None)
    assert not match(Command('git branch', '', git_command), None)
Пример #15
0
def test_match(stderr):
    assert match(Command('git push master', '', stderr), None)
    assert not match(Command('git push master', '', ''), None)
    assert not match(Command('ls', '', stderr), None)
Пример #16
0
def test_get_new_command():
    assert get_new_command(Command('rm foo', '', ''), None) == 'rm -rf foo'
Пример #17
0
def test_get_new_command():
    assert get_new_command(Command('./test_sudo.py', '', ''),
                           None) == 'python ./test_sudo.py'
Пример #18
0
def test_match():
    assert match(Command('temp.py', '', 'Permission denied'), None)
    assert not match(Command('', '', ''), None)
Пример #19
0
def test_get_new_command(stderr):
    assert get_new_command(Command('', '', stderr), None)\
        == "git push --set-upstream origin master"
Пример #20
0
def test_match():
    assert match(Command('rm foo', '', 'rm: foo: is a directory'), None)
    assert not match(Command('rm foo', '', ''), None)
    assert not match(Command('rm foo', '', 'foo bar baz'), None)
    assert not match(Command('', '', ''), None)
Пример #21
0
def test_get_new_command():
    assert get_new_command(Command('mkdir foo/bar/baz', '', ''),
                           None) == 'mkdir -p foo/bar/baz'