<commit_before>import pytest
from thefuck.rules.apt_get import match, get_new_command
from tests.utils import Command


@pytest.mark.parametrize('command, packages', [
    (Command(script='vim', stderr='vim: command not found'),
     [('vim', 'main'), ('vim-tiny', 'main')]),
    (Command(script='sudo vim', stderr='vim: command not found'),
     [('vim', 'main'), ('vim-tiny', 'main')])])
def test_match(mocker, command, packages):
    mocker.patch('thefuck.rules.apt_get.which', return_value=None)
    mock = mocker.patch('thefuck.rules.apt_get.command_not_found')
    mock.getPackages.return_value = packages

    assert match(command)


@pytest.mark.parametrize('command, packages, which', [
    (Command(script='a_bad_cmd', stderr='a_bad_cmd: command not found'),
     [], None),
    (Command(script='vim', stderr=''), [], None),
    (Command(), [], None),
    (Command(script='vim', stderr='vim: command not found'),
     ['vim'], '/usr/bin/vim'),
    (Command(script='sudo vim', stderr='vim: command not found'),
     ['vim'], '/usr/bin/vim')])
def test_not_match(mocker, command, packages, which):
    mocker.patch('thefuck.rules.apt_get.which', return_value=which)
    mock = mocker.patch('thefuck.rules.apt_get.command_not_found')
    mock.getPackages.return_value = packages

    assert not match(command)


@pytest.mark.parametrize('command, new_command, packages', [
    (Command('vim'), 'sudo apt-get install vim && vim',
     [('vim', 'main'), ('vim-tiny', 'main')]),
    (Command('convert'), 'sudo apt-get install imagemagick && convert',
     [('imagemagick', 'main'),
      ('graphicsmagick-imagemagick-compat', 'universe')]),
    (Command('sudo vim'), 'sudo apt-get install vim && sudo vim',
     [('vim', 'main'), ('vim-tiny', 'main')]),
    (Command('sudo convert'), 'sudo apt-get install imagemagick && sudo convert',
     [('imagemagick', 'main'),
      ('graphicsmagick-imagemagick-compat', 'universe')])])
def test_get_new_command(mocker, command, new_command, packages):
    mock = mocker.patch('thefuck.rules.apt_get.command_not_found')
    mock.getPackages.return_value = packages
    assert get_new_command(command) == new_command
<commit_msg>#N/A: Fix tests without `CommandNotFound`<commit_after>import pytest
from thefuck.rules.apt_get import match, get_new_command
from tests.utils import Command


@pytest.mark.parametrize('command, packages', [
    (Command(script='vim', stderr='vim: command not found'),
     [('vim', 'main'), ('vim-tiny', 'main')]),
    (Command(script='sudo vim', stderr='vim: command not found'),
     [('vim', 'main'), ('vim-tiny', 'main')])])
def test_match(mocker, command, packages):
    mocker.patch('thefuck.rules.apt_get.which', return_value=None)
    mock = mocker.patch('thefuck.rules.apt_get.command_not_found',
                        create=True)
    mock.getPackages.return_value = packages

    assert match(command)


@pytest.mark.parametrize('command, packages, which', [
    (Command(script='a_bad_cmd', stderr='a_bad_cmd: command not found'),
     [], None),
    (Command(script='vim', stderr=''), [], None),
    (Command(), [], None),
    (Command(script='vim', stderr='vim: command not found'),
     ['vim'], '/usr/bin/vim'),
    (Command(script='sudo vim', stderr='vim: command not found'),
     ['vim'], '/usr/bin/vim')])
def test_not_match(mocker, command, packages, which):
    mocker.patch('thefuck.rules.apt_get.which', return_value=which)
    mock = mocker.patch('thefuck.rules.apt_get.command_not_found',
                        create=True)
    mock.getPackages.return_value = packages

    assert not match(command)


@pytest.mark.parametrize('command, new_command, packages', [
    (Command('vim'), 'sudo apt-get install vim && vim',
     [('vim', 'main'), ('vim-tiny', 'main')]),
    (Command('convert'), 'sudo apt-get install imagemagick && convert',
     [('imagemagick', 'main'),
      ('graphicsmagick-imagemagick-compat', 'universe')]),
    (Command('sudo vim'), 'sudo apt-get install vim && sudo vim',
     [('vim', 'main'), ('vim-tiny', 'main')]),
    (Command('sudo convert'), 'sudo apt-get install imagemagick && sudo convert',
     [('imagemagick', 'main'),
      ('graphicsmagick-imagemagick-compat', 'universe')])])
def test_get_new_command(mocker, command, new_command, packages):
    mock = mocker.patch('thefuck.rules.apt_get.command_not_found',
                        create=True)
    mock.getPackages.return_value = packages
    assert get_new_command(command) == new_command

{'fraction_non_alphanumeric': 0.18269016283738568, 'fraction_numerical': 0.0, 'mean_word_length': 4.474969474969475, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7121343', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1475, 'n_words': 299}