repo stringlengths 7 90 | file_url stringlengths 81 315 | file_path stringlengths 4 228 | content stringlengths 0 32.8k | language stringclasses 1 value | license stringclasses 7 values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 14:38:15 2026-01-05 02:33:18 | truncated bool 2 classes |
|---|---|---|---|---|---|---|---|---|
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_tag_force.py | tests/rules/test_git_tag_force.py | import pytest
from thefuck.rules.git_tag_force import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def output():
return '''fatal: tag 'alert' already exists'''
def test_match(output):
assert match(Command('git tag alert', output))
assert not match(Command('git tag alert', ''))
def test_get_new_command(output):
assert (get_new_command(Command('git tag alert', output))
== "git tag --force alert")
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_mkdir_p.py | tests/rules/test_mkdir_p.py | import pytest
from thefuck.rules.mkdir_p import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('command', [
Command('mkdir foo/bar/baz', 'mkdir: foo/bar: No such file or directory'),
Command('./bin/hdfs dfs -mkdir foo/bar/baz', 'mkdir: `foo/bar/baz\': No such file or directory'),
Command('hdfs dfs -mkdir foo/bar/baz', 'mkdir: `foo/bar/baz\': No such file or directory')
])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('mkdir foo/bar/baz', ''),
Command('mkdir foo/bar/baz', 'foo bar baz'),
Command('hdfs dfs -mkdir foo/bar/baz', ''),
Command('./bin/hdfs dfs -mkdir foo/bar/baz', ''),
Command('', ''),
])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('mkdir foo/bar/baz', ''), 'mkdir -p foo/bar/baz'),
(Command('hdfs dfs -mkdir foo/bar/baz', ''), 'hdfs dfs -mkdir -p foo/bar/baz'),
(Command('./bin/hdfs dfs -mkdir foo/bar/baz', ''), './bin/hdfs dfs -mkdir -p foo/bar/baz'),
])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_branch_list.py | tests/rules/test_git_branch_list.py | from thefuck.rules.git_branch_list import match, get_new_command
from thefuck.shells import shell
from thefuck.types import Command
def test_match():
assert match(Command('git branch list', ''))
def test_not_match():
assert not match(Command('', ''))
assert not match(Command('git commit', ''))
assert not match(Command('git branch', ''))
assert not match(Command('git stash list', ''))
def test_get_new_command():
assert (get_new_command(Command('git branch list', '')) ==
shell.and_('git branch --delete list', 'git branch'))
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_ls_all.py | tests/rules/test_ls_all.py | from thefuck.rules.ls_all import match, get_new_command
from thefuck.types import Command
def test_match():
assert match(Command('ls', ''))
assert not match(Command('ls', 'file.py\n'))
def test_get_new_command():
assert get_new_command(Command('ls empty_dir', '')) == 'ls -A empty_dir'
assert get_new_command(Command('ls', '')) == 'ls -A'
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_ln_s_order.py | tests/rules/test_ln_s_order.py | import pytest
from thefuck.rules.ln_s_order import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def file_exists(mocker):
return mocker.patch('os.path.exists', return_value=True)
get_output = "ln: failed to create symbolic link '{}': File exists".format
@pytest.mark.parametrize('script, output, exists', [
('ln dest source', get_output('source'), True),
('ls -s dest source', get_output('source'), True),
('ln -s dest source', '', True),
('ln -s dest source', get_output('source'), False)])
def test_not_match(file_exists, script, output, exists):
file_exists.return_value = exists
assert not match(Command(script, output))
@pytest.mark.usefixtures('file_exists')
@pytest.mark.parametrize('script, result', [
('ln -s dest source', 'ln -s source dest'),
('ln dest -s source', 'ln -s source dest'),
('ln dest source -s', 'ln source -s dest')])
def test_match(script, result):
output = get_output('source')
assert match(Command(script, output))
assert get_new_command(Command(script, output)) == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_brew_uninstall.py | tests/rules/test_brew_uninstall.py | import pytest
from thefuck.types import Command
from thefuck.rules.brew_uninstall import get_new_command, match
@pytest.fixture
def output():
return ("Uninstalling /usr/local/Cellar/tbb/4.4-20160916... (118 files, 1.9M)\n"
"tbb 4.4-20160526, 4.4-20160722 are still installed.\n"
"Remove all versions with `brew uninstall --force tbb`.\n")
@pytest.fixture
def new_command(formula):
return 'brew uninstall --force {}'.format(formula)
@pytest.mark.parametrize('script', ['brew uninstall tbb', 'brew rm tbb', 'brew remove tbb'])
def test_match(output, script):
assert match(Command(script, output))
@pytest.mark.parametrize('script', ['brew remove gnuplot'])
def test_not_match(script):
output = 'Uninstalling /usr/local/Cellar/gnuplot/5.0.4_1... (44 files, 2.3M)\n'
assert not match(Command(script, output))
@pytest.mark.parametrize('script, formula, ', [('brew uninstall tbb', 'tbb')])
def test_get_new_command(output, new_command, script, formula):
assert get_new_command(Command(script, output)) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_docker_login.py | tests/rules/test_docker_login.py | from thefuck.rules.docker_login import match, get_new_command
from thefuck.types import Command
def test_match():
err_response1 = """
Sending build context to Docker daemon 118.8kB
Step 1/6 : FROM foo/bar:fdb7c6d
pull access denied for foo/bar, repository does not exist or may require 'docker login'
"""
assert match(Command('docker build -t artifactory:9090/foo/bar:fdb7c6d .', err_response1))
err_response2 = """
The push refers to repository [artifactory:9090/foo/bar]
push access denied for foo/bar, repository does not exist or may require 'docker login'
"""
assert match(Command('docker push artifactory:9090/foo/bar:fdb7c6d', err_response2))
err_response3 = """
docker push artifactory:9090/foo/bar:fdb7c6d
The push refers to repository [artifactory:9090/foo/bar]
9c29c7ad209d: Preparing
71f3ad53dfe0: Preparing
f58ee068224c: Preparing
aeddc924d0f7: Preparing
c2040e5d6363: Preparing
4d42df4f350f: Preparing
35723dab26f9: Preparing
71f3ad53dfe0: Pushed
cb95fa0faeb1: Layer already exists
"""
assert not match(Command('docker push artifactory:9090/foo/bar:fdb7c6d', err_response3))
def test_get_new_command():
assert get_new_command(Command('docker build -t artifactory:9090/foo/bar:fdb7c6d .', '')) == 'docker login && docker build -t artifactory:9090/foo/bar:fdb7c6d .'
assert get_new_command(Command('docker push artifactory:9090/foo/bar:fdb7c6d', '')) == 'docker login && docker push artifactory:9090/foo/bar:fdb7c6d'
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_flag_after_filename.py | tests/rules/test_git_flag_after_filename.py | import pytest
from thefuck.rules.git_flag_after_filename import match, get_new_command
from thefuck.types import Command
command1 = Command('git log README.md -p',
"fatal: bad flag '-p' used after filename")
command2 = Command('git log README.md -p CONTRIBUTING.md',
"fatal: bad flag '-p' used after filename")
command3 = Command('git log -p README.md --name-only',
"fatal: bad flag '--name-only' used after filename")
command4 = Command('git log README.md -p',
"fatal: option '-p' must come before non-option arguments")
command5 = Command('git log README.md -p CONTRIBUTING.md',
"fatal: option '-p' must come before non-option arguments")
command6 = Command('git log -p README.md --name-only',
"fatal: option '--name-only' must come before non-option arguments")
@pytest.mark.parametrize('command', [
command1, command2, command3, command4, command5, command6])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('git log README.md', ''),
Command('git log -p README.md', '')])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, result', [
(command1, "git log -p README.md"),
(command2, "git log -p README.md CONTRIBUTING.md"),
(command3, "git log -p --name-only README.md"),
(command4, "git log -p README.md"),
(command5, "git log -p README.md CONTRIBUTING.md"),
(command6, "git log -p --name-only README.md")])
def test_get_new_command(command, result):
assert get_new_command(command) == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_unknown_command.py | tests/rules/test_unknown_command.py | import pytest
from thefuck.rules.unknown_command import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('command', [
Command('./bin/hdfs dfs ls', 'ls: Unknown command\nDid you mean -ls? This command begins with a dash.'),
Command('hdfs dfs ls',
'ls: Unknown command\nDid you mean -ls? This command begins with a dash.'),
Command('hdfs dfs ls /foo/bar', 'ls: Unknown command\nDid you mean -ls? This command begins with a dash.')])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('./bin/hdfs dfs -ls', ''),
Command('./bin/hdfs dfs -ls /foo/bar', ''),
Command('hdfs dfs -ls -R /foo/bar', ''),
Command('', '')])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('hdfs dfs ls',
'ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), ['hdfs dfs -ls']),
(Command('hdfs dfs rm /foo/bar',
'rm: Unknown command\nDid you mean -rm? This command begins with a dash.'), ['hdfs dfs -rm /foo/bar']),
(Command('./bin/hdfs dfs ls -R /foo/bar',
'ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), ['./bin/hdfs dfs -ls -R /foo/bar']),
(Command('./bin/hdfs dfs -Dtest=fred ls -R /foo/bar',
'ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), ['./bin/hdfs dfs -Dtest=fred -ls -R /foo/bar'])])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_man.py | tests/rules/test_man.py | import pytest
from thefuck.rules.man import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('command', [
Command('man read', ''),
Command('man 2 read', ''),
Command('man 3 read', ''),
Command('man -s2 read', ''),
Command('man -s3 read', ''),
Command('man -s 2 read', ''),
Command('man -s 3 read', '')])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('man', ''),
Command('man ', '')])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('man read', ''), ['man 3 read', 'man 2 read', 'read --help']),
(Command('man missing', "No manual entry for missing\n"), ['missing --help']),
(Command('man 2 read', ''), 'man 3 read'),
(Command('man 3 read', ''), 'man 2 read'),
(Command('man -s2 read', ''), 'man -s3 read'),
(Command('man -s3 read', ''), 'man -s2 read'),
(Command('man -s 2 read', ''), 'man -s 3 read'),
(Command('man -s 3 read', ''), 'man -s 2 read')])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_pacman_invalid_option.py | tests/rules/test_pacman_invalid_option.py | import pytest
from thefuck.rules.pacman_invalid_option import get_new_command, match
from thefuck.types import Command
good_output = """community/shared_meataxe 1.0-3
A set of programs for working with matrix representations over finite fields
"""
bad_output = "error: invalid option '-"
@pytest.mark.parametrize("option", "SURQFDVT")
def test_not_match_good_output(option):
assert not match(Command("pacman -{}s meat".format(option), good_output))
@pytest.mark.parametrize("option", "azxcbnm")
def test_not_match_bad_output(option):
assert not match(Command("pacman -{}v meat".format(option), bad_output))
@pytest.mark.parametrize("option", "surqfdvt")
def test_match(option):
assert match(Command("pacman -{}v meat".format(option), bad_output))
@pytest.mark.parametrize("option", "surqfdvt")
def test_get_new_command(option):
new_command = get_new_command(Command("pacman -{}v meat".format(option), ""))
assert new_command == "pacman -{}v meat".format(option.upper())
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_brew_unknown_command.py | tests/rules/test_brew_unknown_command.py | import pytest
from thefuck.rules.brew_unknown_command import match, get_new_command
from thefuck.rules.brew_unknown_command import _brew_commands
from thefuck.types import Command
@pytest.fixture
def brew_unknown_cmd():
return '''Error: Unknown command: inst'''
@pytest.fixture
def brew_unknown_cmd2():
return '''Error: Unknown command: instaa'''
def test_match(brew_unknown_cmd):
assert match(Command('brew inst', brew_unknown_cmd))
for command in _brew_commands():
assert not match(Command('brew ' + command, ''))
def test_get_new_command(brew_unknown_cmd, brew_unknown_cmd2):
assert (get_new_command(Command('brew inst', brew_unknown_cmd))
== ['brew list', 'brew install', 'brew uninstall'])
cmds = get_new_command(Command('brew instaa', brew_unknown_cmd2))
assert 'brew install' in cmds
assert 'brew uninstall' in cmds
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_dirty_unzip.py | tests/rules/test_dirty_unzip.py | # -*- coding: utf-8 -*-
import os
import pytest
import zipfile
from thefuck.rules.dirty_unzip import match, get_new_command, side_effect
from thefuck.types import Command
from unicodedata import normalize
@pytest.fixture
def zip_error(tmpdir):
def zip_error_inner(filename):
path = os.path.join(str(tmpdir), filename)
def reset(path):
with zipfile.ZipFile(path, 'w') as archive:
archive.writestr('a', '1')
archive.writestr('b', '2')
archive.writestr('c', '3')
archive.writestr('d/e', '4')
archive.extractall()
os.chdir(str(tmpdir))
reset(path)
dir_list = os.listdir(u'.')
if filename not in dir_list:
filename = normalize('NFD', filename)
assert set(dir_list) == {filename, 'a', 'b', 'c', 'd'}
assert set(os.listdir('./d')) == {'e'}
return zip_error_inner
@pytest.mark.parametrize('script,filename', [
(u'unzip café', u'café.zip'),
(u'unzip café.zip', u'café.zip'),
(u'unzip foo', u'foo.zip'),
(u'unzip foo.zip', u'foo.zip')])
def test_match(zip_error, script, filename):
zip_error(filename)
assert match(Command(script, ''))
@pytest.mark.parametrize('script,filename', [
(u'unzip café', u'café.zip'),
(u'unzip café.zip', u'café.zip'),
(u'unzip foo', u'foo.zip'),
(u'unzip foo.zip', u'foo.zip')])
def test_side_effect(zip_error, script, filename):
zip_error(filename)
side_effect(Command(script, ''), None)
dir_list = os.listdir(u'.')
if filename not in set(dir_list):
filename = normalize('NFD', filename)
assert set(dir_list) == {filename, 'd'}
@pytest.mark.parametrize('script,fixed,filename', [
(u'unzip café', u"unzip café -d 'café'", u'café.zip'),
(u'unzip foo', u'unzip foo -d foo', u'foo.zip'),
(u"unzip 'foo bar.zip'", u"unzip 'foo bar.zip' -d 'foo bar'", u'foo.zip'),
(u'unzip foo.zip', u'unzip foo.zip -d foo', u'foo.zip')])
def test_get_new_command(zip_error, script, fixed, filename):
zip_error(filename)
assert get_new_command(Command(script, '')) == fixed
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_gradle_wrapper.py | tests/rules/test_gradle_wrapper.py | import pytest
from thefuck.rules.gradle_wrapper import match, get_new_command
from thefuck.types import Command
@pytest.fixture(autouse=True)
def exists(mocker):
return mocker.patch('thefuck.rules.gradle_wrapper.os.path.isfile',
return_value=True)
@pytest.mark.parametrize('command', [
Command('gradle tasks', 'gradle: not found'),
Command('gradle build', 'gradle: not found')])
def test_match(mocker, command):
mocker.patch('thefuck.rules.gradle_wrapper.which', return_value=None)
assert match(command)
@pytest.mark.parametrize('command, gradlew, which', [
(Command('gradle tasks', 'gradle: not found'), False, None),
(Command('gradle tasks', 'command not found'), True, '/usr/bin/gradle'),
(Command('npm tasks', 'npm: not found'), True, None)])
def test_not_match(mocker, exists, command, gradlew, which):
mocker.patch('thefuck.rules.gradle_wrapper.which', return_value=which)
exists.return_value = gradlew
assert not match(command)
@pytest.mark.parametrize('script, result', [
('gradle assemble', './gradlew assemble'),
('gradle --help', './gradlew --help'),
('gradle build -c', './gradlew build -c')])
def test_get_new_command(script, result):
command = Command(script, '')
assert get_new_command(command) == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_brew_link.py | tests/rules/test_brew_link.py | import pytest
from thefuck.types import Command
from thefuck.rules.brew_link import get_new_command, match
@pytest.fixture
def output():
return ("Error: Could not symlink bin/gcp\n"
"Target /usr/local/bin/gcp\n"
"already exists. You may want to remove it:\n"
" rm '/usr/local/bin/gcp'\n"
"\n"
"To force the link and overwrite all conflicting files:\n"
" brew link --overwrite coreutils\n"
"\n"
"To list all files that would be deleted:\n"
" brew link --overwrite --dry-run coreutils\n")
@pytest.fixture
def new_command(formula):
return 'brew link --overwrite --dry-run {}'.format(formula)
@pytest.mark.parametrize('script', ['brew link coreutils', 'brew ln coreutils'])
def test_match(output, script):
assert match(Command(script, output))
@pytest.mark.parametrize('script', ['brew link coreutils'])
def test_not_match(script):
assert not match(Command(script, ''))
@pytest.mark.parametrize('script, formula, ', [('brew link coreutils', 'coreutils')])
def test_get_new_command(output, new_command, script, formula):
assert get_new_command(Command(script, output)) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_grunt_task_not_found.py | tests/rules/test_grunt_task_not_found.py | # -*- encoding: utf-8 -*-
from io import BytesIO
import pytest
from thefuck.types import Command
from thefuck.rules.grunt_task_not_found import match, get_new_command
output = '''
Warning: Task "{}" not found. Use --force to continue.
Aborted due to warnings.
Execution Time (2016-08-13 21:01:40 UTC+3)
loading tasks 11ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 92%
Total 12ms
'''.format
grunt_help_stdout = b'''
Grunt: The JavaScript Task Runner (v0.4.5)
Usage
grunt [options] [task [task ...]]
Options
--help, -h Display this help text.
--base Specify an alternate base path. By default, all file paths are
relative to the Gruntfile. (grunt.file.setBase) *
--no-color Disable colored output.
--gruntfile Specify an alternate Gruntfile. By default, grunt looks in the
current or parent directories for the nearest Gruntfile.js or
Gruntfile.coffee file.
--debug, -d Enable debugging mode for tasks that support it.
--stack Print a stack trace when exiting with a warning or fatal error.
--force, -f A way to force your way past warnings. Want a suggestion? Don't
use this option, fix your code.
--tasks Additional directory paths to scan for task and "extra" files.
(grunt.loadTasks) *
--npm Npm-installed grunt plugins to scan for task and "extra" files.
(grunt.loadNpmTasks) *
--no-write Disable writing files (dry run).
--verbose, -v Verbose mode. A lot more information output.
--version, -V Print the grunt version. Combine with --verbose for more info.
--completion Output shell auto-completion rules. See the grunt-cli
documentation for more information.
Options marked with * have methods exposed via the grunt API and should instead
be specified inside the Gruntfile wherever possible.
Available tasks
autoprefixer Prefix CSS files. *
concurrent Run grunt tasks concurrently *
clean Clean files and folders. *
compass Compile Sass to CSS using Compass *
concat Concatenate files. *
connect Start a connect web server. *
copy Copy files. *
cssmin Minify CSS *
htmlmin Minify HTML *
imagemin Minify PNG, JPEG, GIF and SVG images *
jshint Validate files with JSHint. *
uglify Minify files with UglifyJS. *
watch Run predefined tasks whenever watched files change.
filerev File revisioning based on content hashing *
cdnify Replace scripts with refs to the Google CDN *
karma run karma. *
newer Run a task with only those source files that have been modified
since the last successful run.
any-newer DEPRECATED TASK. Use the "newer" task instead
newer-postrun Internal task.
newer-clean Remove cached timestamps.
ngAnnotate Add, remove and rebuild AngularJS dependency injection
annotations *
ngconstant Dynamic angular constant generator task. *
svgmin Minify SVG *
usemin Replaces references to non-minified scripts / stylesheets *
useminPrepare Using HTML markup as the primary source of information *
wiredep Inject Bower components into your source code. *
serve Compile then start a connect web server
server DEPRECATED TASK. Use the "serve" task instead
test Alias for "clean:server", "ngconstant:test", "wiredep",
"concurrent:test", "autoprefixer", "connect:test", "karma"
tasks.
build Alias for "ngconstant:production", "clean:dist", "wiredep",
"useminPrepare", "concurrent:dist", "autoprefixer", "concat",
"ngAnnotate", "copy:dist", "cdnify", "cssmin", "uglify",
"filerev", "usemin", "htmlmin" tasks.
default Alias for "newer:jshint", "test", "build" tasks.
Tasks run in the order specified. Arguments may be passed to tasks that accept
them by using colons, like "lint:files". Tasks marked with * are "multi tasks"
and will iterate over all sub-targets if no argument is specified.
The list of available tasks may change based on tasks directories or grunt
plugins specified in the Gruntfile or via command-line options.
For more information, see http://gruntjs.com/
'''
@pytest.fixture(autouse=True)
def grunt_help(mocker):
patch = mocker.patch('thefuck.rules.grunt_task_not_found.Popen')
patch.return_value.stdout = BytesIO(grunt_help_stdout)
return patch
@pytest.mark.parametrize('command', [
Command('grunt defualt', output('defualt')),
Command('grunt buld:css', output('buld:css'))])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('npm nuild', output('nuild')),
Command('grunt rm', '')])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, result', [
(Command('grunt defualt', output('defualt')), 'grunt default'),
(Command('grunt cmpass:all', output('cmpass:all')), 'grunt compass:all'),
(Command('grunt cmpass:all --color', output('cmpass:all')),
'grunt compass:all --color')])
def test_get_new_command(command, result):
assert get_new_command(command) == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_yarn_help.py | tests/rules/test_yarn_help.py | import pytest
from thefuck.rules.yarn_help import match, get_new_command
from thefuck.types import Command
from thefuck.system import open_command
output_clean = '''
Usage: yarn [command] [flags]
Options:
-h, --help output usage information
-V, --version output the version number
--verbose output verbose messages on internal operations
--offline trigger an error if any required dependencies are not available in local cache
--prefer-offline use network only if dependencies are not available in local cache
--strict-semver
--json
--ignore-scripts don't run lifecycle scripts
--har save HAR output of network traffic
--ignore-platform ignore platform checks
--ignore-engines ignore engines check
--ignore-optional ignore optional dependencies
--force ignore all caches
--no-bin-links don't generate bin links when setting up packages
--flat only allow one version of a package
--prod, --production [prod]
--no-lockfile don't read or generate a lockfile
--pure-lockfile don't generate a lockfile
--frozen-lockfile don't generate a lockfile and fail if an update is needed
--link-duplicates create hardlinks to the repeated modules in node_modules
--global-folder <path>
--modules-folder <path> rather than installing modules into the node_modules folder relative to the cwd, output them here
--cache-folder <path> specify a custom folder to store the yarn cache
--mutex <type>[:specifier] use a mutex to ensure only one yarn instance is executing
--no-emoji disable emoji in output
--proxy <host>
--https-proxy <host>
--no-progress disable progress bar
--network-concurrency <number> maximum number of concurrent network requests
Visit https://yarnpkg.com/en/docs/cli/clean for documentation about this command.
''' # noqa
@pytest.mark.parametrize('command', [
Command('yarn help clean', output_clean)])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command, url', [
(Command('yarn help clean', output_clean),
'https://yarnpkg.com/en/docs/cli/clean')])
def test_get_new_command(command, url):
assert get_new_command(command) == open_command(url)
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_hostscli.py | tests/rules/test_hostscli.py | import pytest
from thefuck.rules.hostscli import no_website, get_new_command, match
from thefuck.types import Command
no_website_long = '''
{}:
No Domain list found for website: a_website_that_does_not_exist
Please raise a Issue here: https://github.com/dhilipsiva/hostscli/issues/new
if you think we should add domains for this website.
type `hostscli websites` to see a list of websites that you can block/unblock
'''.format(no_website)
@pytest.mark.parametrize('command', [
Command('hostscli block a_website_that_does_not_exist', no_website_long)])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command, result', [(
Command('hostscli block a_website_that_does_not_exist', no_website_long),
['hostscli websites'])])
def test_get_new_command(command, result):
assert get_new_command(command) == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_not_command.py | tests/rules/test_git_not_command.py | import pytest
from thefuck.rules.git_not_command import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def git_not_command():
return """git: 'brnch' is not a git command. See 'git --help'.
The most similar command is
branch
"""
@pytest.fixture
def git_not_command_one_of_this():
return """git: 'st' is not a git command. See 'git --help'.
The most similar commands are
status
reset
stage
stash
stats
"""
@pytest.fixture
def git_not_command_closest():
return '''git: 'tags' is not a git command. See 'git --help'.
The most similar commands are
\tstage
\ttag
'''
@pytest.fixture
def git_command():
return "* master"
def test_match(git_not_command, git_command, git_not_command_one_of_this):
assert match(Command('git brnch', git_not_command))
assert match(Command('git st', git_not_command_one_of_this))
assert not match(Command('ls brnch', git_not_command))
assert not match(Command('git branch', git_command))
def test_get_new_command(git_not_command, git_not_command_one_of_this,
git_not_command_closest):
assert (get_new_command(Command('git brnch', git_not_command))
== ['git branch'])
assert (get_new_command(Command('git st', git_not_command_one_of_this))
== ['git stats', 'git stash', 'git stage'])
assert (get_new_command(Command('git tags', git_not_command_closest))
== ['git tag', 'git stage'])
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_merge_unrelated.py | tests/rules/test_git_merge_unrelated.py | import pytest
from thefuck.rules.git_merge_unrelated import match, get_new_command
from thefuck.types import Command
output = 'fatal: refusing to merge unrelated histories'
def test_match():
assert match(Command('git merge test', output))
assert not match(Command('git merge master', ''))
assert not match(Command('ls', output))
@pytest.mark.parametrize('command, new_command', [
(Command('git merge local', output),
'git merge local --allow-unrelated-histories'),
(Command('git merge -m "test" local', output),
'git merge -m "test" local --allow-unrelated-histories'),
(Command('git merge -m "test local" local', output),
'git merge -m "test local" local --allow-unrelated-histories')])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_missing_space_before_subcommand.py | tests/rules/test_missing_space_before_subcommand.py | import pytest
from thefuck.rules.missing_space_before_subcommand import (
match, get_new_command)
from thefuck.types import Command
@pytest.fixture(autouse=True)
def all_executables(mocker):
return mocker.patch(
'thefuck.rules.missing_space_before_subcommand.get_all_executables',
return_value=['git', 'ls', 'npm', 'w', 'watch'])
@pytest.mark.parametrize('script', [
'gitbranch', 'ls-la', 'npminstall', 'watchls'])
def test_match(script):
assert match(Command(script, ''))
@pytest.mark.parametrize('script', ['git branch', 'vimfile'])
def test_not_match(script):
assert not match(Command(script, ''))
@pytest.mark.parametrize('script, result', [
('gitbranch', 'git branch'),
('ls-la', 'ls -la'),
('npminstall webpack', 'npm install webpack'),
('watchls', 'watch ls')])
def test_get_new_command(script, result):
assert get_new_command(Command(script, '')) == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_two_dashes.py | tests/rules/test_git_two_dashes.py | import pytest
from thefuck.rules.git_two_dashes import match, get_new_command
from thefuck.types import Command
output = 'error: did you mean `{}` (with two dashes ?)'.format
@pytest.mark.parametrize('command', [
Command('git add -patch', output('--patch')),
Command('git checkout -patch', output('--patch')),
Command('git commit -amend', output('--amend')),
Command('git push -tags', output('--tags')),
Command('git rebase -continue', output('--continue'))])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('git add --patch', ''),
Command('git checkout --patch', ''),
Command('git commit --amend', ''),
Command('git push --tags', ''),
Command('git rebase --continue', '')])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, output', [
(Command('git add -patch', output('--patch')),
'git add --patch'),
(Command('git checkout -patch', output('--patch')),
'git checkout --patch'),
(Command('git checkout -patch', output('--patch')),
'git checkout --patch'),
(Command('git init -bare', output('--bare')),
'git init --bare'),
(Command('git commit -amend', output('--amend')),
'git commit --amend'),
(Command('git push -tags', output('--tags')),
'git push --tags'),
(Command('git rebase -continue', output('--continue')),
'git rebase --continue')])
def test_get_new_command(command, output):
assert get_new_command(command) == output
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_checkout.py | tests/rules/test_git_checkout.py | import pytest
from io import BytesIO
from thefuck.rules.git_checkout import match, get_branches, get_new_command
from thefuck.types import Command
def did_not_match(target, did_you_forget=False):
error = ("error: pathspec '{}' did not match any "
"file(s) known to git.".format(target))
if did_you_forget:
error = ("{}\nDid you forget to 'git add'?'".format(error))
return error
@pytest.fixture
def git_branch(mocker, branches):
mock = mocker.patch('subprocess.Popen')
mock.return_value.stdout = BytesIO(branches)
return mock
@pytest.mark.parametrize('command', [
Command('git checkout unknown', did_not_match('unknown')),
Command('git commit unknown', did_not_match('unknown'))])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('git submodule update unknown',
did_not_match('unknown', True)),
Command('git checkout known', ''),
Command('git commit known', '')])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('branches, branch_list', [
(b'', []),
(b'* master', ['master']),
(b' remotes/origin/master', ['master']),
(b' remotes/origin/test/1', ['test/1']),
(b' remotes/origin/test/1/2/3', ['test/1/2/3']),
(b' test/1', ['test/1']),
(b' test/1/2/3', ['test/1/2/3']),
(b' remotes/origin/HEAD -> origin/master', []),
(b' just-another-branch', ['just-another-branch']),
(b'* master\n just-another-branch', ['master', 'just-another-branch']),
(b'* master\n remotes/origin/master\n just-another-branch',
['master', 'master', 'just-another-branch'])])
def test_get_branches(branches, branch_list, git_branch):
git_branch(branches)
assert list(get_branches()) == branch_list
@pytest.mark.parametrize('branches, command, new_command', [
(b'',
Command('git checkout unknown', did_not_match('unknown')),
['git checkout -b unknown']),
(b'',
Command('git commit unknown', did_not_match('unknown')),
['git branch unknown && git commit unknown']),
(b' test-random-branch-123',
Command('git checkout tst-rdm-brnch-123',
did_not_match('tst-rdm-brnch-123')),
['git checkout test-random-branch-123', 'git checkout -b tst-rdm-brnch-123']),
(b' test-random-branch-123',
Command('git commit tst-rdm-brnch-123',
did_not_match('tst-rdm-brnch-123')),
['git commit test-random-branch-123'])])
def test_get_new_command(branches, command, new_command, git_branch):
git_branch(branches)
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_heroku_not_command.py | tests/rules/test_heroku_not_command.py | # -*- coding: utf-8 -*-
import pytest
from thefuck.types import Command
from thefuck.rules.heroku_not_command import match, get_new_command
suggest_output = '''
▸ log is not a heroku command.
▸ Perhaps you meant logs?
▸ Run heroku _ to run heroku logs.
▸ Run heroku help for a list of available commands.'''
@pytest.mark.parametrize('cmd', ['log'])
def test_match(cmd):
assert match(
Command('heroku {}'.format(cmd), suggest_output))
@pytest.mark.parametrize('script, output', [
('cat log', suggest_output)])
def test_not_match(script, output):
assert not match(Command(script, output))
@pytest.mark.parametrize('cmd, result', [
('log', 'heroku logs')])
def test_get_new_command(cmd, result):
command = Command('heroku {}'.format(cmd), suggest_output)
assert get_new_command(command) == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_rm_dir.py | tests/rules/test_rm_dir.py | import pytest
from thefuck.rules.rm_dir import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('command', [
Command('rm foo', 'rm: foo: is a directory'),
Command('rm foo', 'rm: foo: Is a directory'),
Command('hdfs dfs -rm foo', 'rm: `foo`: Is a directory'),
Command('./bin/hdfs dfs -rm foo', 'rm: `foo`: Is a directory'),
])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('rm foo', ''),
Command('hdfs dfs -rm foo', ''),
Command('./bin/hdfs dfs -rm foo', ''),
Command('', ''),
])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('rm foo', ''), 'rm -rf foo'),
(Command('hdfs dfs -rm foo', ''), 'hdfs dfs -rm -r foo'),
])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_remove_shell_prompt_literal.py | tests/rules/test_remove_shell_prompt_literal.py | import pytest
from thefuck.rules.remove_shell_prompt_literal import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def output():
return "$: command not found"
@pytest.mark.parametrize(
"script",
[
"$ cd newdir",
" $ cd newdir",
"$ $ cd newdir",
" $ $ cd newdir",
],
)
def test_match(script, output):
assert match(Command(script, output))
@pytest.mark.parametrize(
"command",
[
Command("$", "$: command not found"),
Command(" $", "$: command not found"),
Command("$?", "127: command not found"),
Command(" $?", "127: command not found"),
Command("", ""),
],
)
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize(
"script, new_command",
[
("$ cd newdir", "cd newdir"),
("$ $ cd newdir", "cd newdir"),
("$ python3 -m virtualenv env", "python3 -m virtualenv env"),
(" $ $ $ python3 -m virtualenv env", "python3 -m virtualenv env"),
],
)
def test_get_new_command(script, new_command, output):
assert get_new_command(Command(script, output)) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_no_command.py | tests/rules/test_no_command.py | import pytest
from thefuck.rules.no_command import match, get_new_command
from thefuck.types import Command
@pytest.fixture(autouse=True)
def get_all_executables(mocker):
mocker.patch('thefuck.rules.no_command.get_all_executables',
return_value=['vim', 'fsck', 'git', 'go', 'python'])
@pytest.fixture(autouse=True)
def history_without_current(mocker):
return mocker.patch(
'thefuck.rules.no_command.get_valid_history_without_current',
return_value=['git commit'])
@pytest.mark.usefixtures('no_memoize')
@pytest.mark.parametrize('script, output', [
('vom file.py', 'vom: not found'),
('fucck', 'fucck: not found'),
('puthon', "'puthon' is not recognized as an internal or external command"),
('got commit', 'got: command not found'),
('gti commit -m "new commit"', 'gti: command not found')])
def test_match(mocker, script, output):
mocker.patch('thefuck.rules.no_command.which', return_value=None)
assert match(Command(script, output))
@pytest.mark.usefixtures('no_memoize')
@pytest.mark.parametrize('script, output, which', [
('qweqwe', 'qweqwe: not found', None),
('vom file.py', 'some text', None),
('vim file.py', 'vim: not found', 'vim')])
def test_not_match(mocker, script, output, which):
mocker.patch('thefuck.rules.no_command.which', return_value=which)
assert not match(Command(script, output))
@pytest.mark.usefixtures('no_memoize')
@pytest.mark.parametrize('script, result', [
('vom file.py', ['vim file.py']),
('fucck', ['fsck']),
('got commit', ['git commit', 'go commit']),
('gti commit -m "new commit"', ['git commit -m "new commit"'])])
def test_get_new_command(script, result):
assert get_new_command(Command(script, '')) == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_main_master.py | tests/rules/test_git_main_master.py | import pytest
from thefuck.rules.git_main_master import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def output(branch_name):
if not branch_name:
return ""
output_str = u"error: pathspec '{}' did not match any file(s) known to git"
return output_str.format(branch_name)
@pytest.mark.parametrize(
"script, branch_name",
[
("git checkout main", "main"),
("git checkout master", "master"),
("git show main", "main"),
],
)
def test_match(script, branch_name, output):
assert match(Command(script, output))
@pytest.mark.parametrize(
"script, branch_name",
[
("git checkout master", ""),
("git checkout main", ""),
("git checkout wibble", "wibble"),
],
)
def test_not_match(script, branch_name, output):
assert not match(Command(script, output))
@pytest.mark.parametrize(
"script, branch_name, new_command",
[
("git checkout main", "main", "git checkout master"),
("git checkout master", "master", "git checkout main"),
("git checkout wibble", "wibble", "git checkout wibble"),
],
)
def test_get_new_command(script, branch_name, new_command, output):
assert get_new_command(Command(script, output)) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_pull.py | tests/rules/test_git_pull.py | import pytest
from thefuck.rules.git_pull import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def output():
return '''There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=<remote>/<branch> master
'''
def test_match(output):
assert match(Command('git pull', output))
assert not match(Command('git pull', ''))
assert not match(Command('ls', output))
def test_get_new_command(output):
assert (get_new_command(Command('git pull', output))
== "git branch --set-upstream-to=origin/master master && git pull")
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_port_already_in_use.py | tests/rules/test_port_already_in_use.py | from io import BytesIO
import pytest
from thefuck.rules.port_already_in_use import match, get_new_command
from thefuck.types import Command
outputs = [
'''
DE 70% 1/1 build modulesevents.js:141
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE 127.0.0.1:8080
at Object.exports._errnoException (util.js:873:11)
at exports._exceptionWithHostPort (util.js:896:20)
at Server._listen2 (net.js:1250:14)
at listen (net.js:1286:10)
at net.js:1395:9
at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:64:16)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:83:10)
''',
'''
[6:40:01 AM] <START> Building Dependency Graph
[6:40:01 AM] <START> Crawling File System
ERROR Packager can't listen on port 8080
Most likely another process is already using this port
Run the following command to find out which process:
lsof -n -i4TCP:8080
You can either shut down the other process:
kill -9 <PID>
or run packager on different port.
''',
'''
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/nvbn/exp/code_view/server/code_view/main.py", line 14, in <module>
web.run_app(app)
File "/home/nvbn/.virtualenvs/code_view/lib/python3.5/site-packages/aiohttp/web.py", line 310, in run_app
backlog=backlog))
File "/usr/lib/python3.5/asyncio/base_events.py", line 373, in run_until_complete
return future.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
File "/usr/lib/python3.5/asyncio/tasks.py", line 240, in _step
result = coro.send(None)
File "/usr/lib/python3.5/asyncio/base_events.py", line 953, in create_server
% (sa, err.strerror.lower()))
OSError: [Errno 98] error while attempting to bind on address ('0.0.0.0', 8080): address already in use
Task was destroyed but it is pending!
task: <Task pending coro=<RedisProtocol._reader_coroutine() running at /home/nvbn/.virtualenvs/code_view/lib/python3.5/site-packages/asyncio_redis/protocol.py:921> wait_for=<Future pending cb=[Task._wakeup()]>>
'''
]
lsof_stdout = b'''COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 18233 nvbn 16u IPv4 557134 0t0 TCP localhost:http-alt (LISTEN)
'''
@pytest.fixture(autouse=True)
def lsof(mocker):
patch = mocker.patch('thefuck.rules.port_already_in_use.Popen')
patch.return_value.stdout = BytesIO(lsof_stdout)
return patch
@pytest.mark.usefixtures('no_memoize')
@pytest.mark.parametrize(
'command',
[Command('./app', output) for output in outputs]
+ [Command('./app', output) for output in outputs])
def test_match(command):
assert match(command)
@pytest.mark.usefixtures('no_memoize')
@pytest.mark.parametrize('command, lsof_output', [
(Command('./app', ''), lsof_stdout),
(Command('./app', outputs[1]), b''),
(Command('./app', outputs[2]), b'')])
def test_not_match(lsof, command, lsof_output):
lsof.return_value.stdout = BytesIO(lsof_output)
assert not match(command)
@pytest.mark.parametrize(
'command',
[Command('./app', output) for output in outputs]
+ [Command('./app', output) for output in outputs])
def test_get_new_command(command):
assert get_new_command(command) == 'kill 18233 && ./app'
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_terraform_no_command.py | tests/rules/test_terraform_no_command.py | import pytest
from thefuck.rules.terraform_no_command import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('script, output', [
('terraform appyl', 'Terraform has no command named "appyl". Did you mean "apply"?'),
('terraform destory', 'Terraform has no command named "destory". Did you mean "destroy"?')])
def test_match(script, output):
assert match(Command(script, output))
@pytest.mark.parametrize('script, output', [
('terraform --version', 'Terraform v0.12.2'),
('terraform plan', 'No changes. Infrastructure is up-to-date.'),
('terraform apply', 'Apply complete! Resources: 0 added, 0 changed, 0 destroyed.'),
])
def test_not_match(script, output):
assert not match(Command(script, output))
@pytest.mark.parametrize('script, output, new_command', [
('terraform appyl', 'Terraform has no command named "appyl". Did you mean "apply"?', 'terraform apply',),
('terraform destory --some-other-option', 'Terraform has no command named "destory". Did you mean "destroy"?', 'terraform destroy --some-other-option',),
])
def test_get_new_command(script, output, new_command):
assert get_new_command(Command(script, output)) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_clone_missing.py | tests/rules/test_git_clone_missing.py | import pytest
from thefuck.rules.git_clone_missing import match, get_new_command
from thefuck.types import Command
valid_urls = [
'https://github.com/nvbn/thefuck.git',
'https://github.com/nvbn/thefuck',
'http://github.com/nvbn/thefuck.git',
'git@github.com:nvbn/thefuck.git',
'git@github.com:nvbn/thefuck',
'ssh://git@github.com:nvbn/thefuck.git',
]
invalid_urls = [
'', # No command
'notacommand', # Command not found
'ssh git@github.com:nvbn/thefrick.git', # ssh command, not a git clone
'git clone foo', # Valid clone
'git clone https://github.com/nvbn/thefuck.git', # Full command
'github.com/nvbn/thefuck.git', # Missing protocol
'github.com:nvbn/thefuck.git', # SSH missing username
'git clone git clone ssh://git@github.com:nvbn/thefrick.git', # 2x clone
'https:/github.com/nvbn/thefuck.git' # Bad protocol
]
outputs = [
'No such file or directory',
'not found',
'is not recognised as',
]
@pytest.mark.parametrize('cmd', valid_urls)
@pytest.mark.parametrize('output', outputs)
def test_match(cmd, output):
c = Command(cmd, output)
assert match(c)
@pytest.mark.parametrize('cmd', invalid_urls)
@pytest.mark.parametrize('output', outputs + ["some other output"])
def test_not_match(cmd, output):
c = Command(cmd, output)
assert not match(c)
@pytest.mark.parametrize('script', valid_urls)
@pytest.mark.parametrize('output', outputs)
def test_get_new_command(script, output):
command = Command(script, output)
new_command = 'git clone ' + script
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_dnf_no_such_command.py | tests/rules/test_dnf_no_such_command.py | from io import BytesIO
import pytest
from thefuck.types import Command
from thefuck.rules.dnf_no_such_command import match, get_new_command, _get_operations
help_text = b'''usage: dnf [options] COMMAND
List of Main Commands:
autoremove remove all unneeded packages that were originally installed as dependencies
check check for problems in the packagedb
check-update check for available package upgrades
clean remove cached data
deplist List package's dependencies and what packages provide them
distro-sync synchronize installed packages to the latest available versions
downgrade Downgrade a package
group display, or use, the groups information
help display a helpful usage message
history display, or use, the transaction history
info display details about a package or group of packages
install install a package or packages on your system
list list a package or groups of packages
makecache generate the metadata cache
mark mark or unmark installed packages as installed by user.
provides find what package provides the given value
reinstall reinstall a package
remove remove a package or packages from your system
repolist display the configured software repositories
repoquery search for packages matching keyword
repository-packages run commands on top of all packages in given repository
search search package details for the given string
shell run an interactive DNF shell
swap run an interactive dnf mod for remove and install one spec
updateinfo display advisories about packages
upgrade upgrade a package or packages on your system
upgrade-minimal upgrade, but only 'newest' package match which fixes a problem that affects your system
List of Plugin Commands:
builddep Install build dependencies for package or spec file
config-manager manage dnf configuration options and repositories
copr Interact with Copr repositories.
debug-dump dump information about installed rpm packages to file
debug-restore restore packages recorded in debug-dump file
debuginfo-install install debuginfo packages
download Download package to current directory
needs-restarting determine updated binaries that need restarting
playground Interact with Playground repository.
repoclosure Display a list of unresolved dependencies for repositories
repograph Output a full package dependency graph in dot format
repomanage Manage a directory of rpm packages
reposync download all packages from remote repo
Optional arguments:
-c [config file], --config [config file]
config file location
-q, --quiet quiet operation
-v, --verbose verbose operation
--version show DNF version and exit
--installroot [path] set install root
--nodocs do not install documentations
--noplugins disable all plugins
--enableplugin [plugin]
enable plugins by name
--disableplugin [plugin]
disable plugins by name
--releasever RELEASEVER
override the value of $releasever in config and repo
files
--setopt SETOPTS set arbitrary config and repo options
--skip-broken resolve depsolve problems by skipping packages
-h, --help, --help-cmd
show command help
--allowerasing allow erasing of installed packages to resolve
dependencies
-b, --best try the best available package versions in
transactions.
-C, --cacheonly run entirely from system cache, don't update cache
-R [minutes], --randomwait [minutes]
maximum command wait time
-d [debug level], --debuglevel [debug level]
debugging output level
--debugsolver dumps detailed solving results into files
--showduplicates show duplicates, in repos, in list/search commands
-e ERRORLEVEL, --errorlevel ERRORLEVEL
error output level
--obsoletes enables dnf's obsoletes processing logic for upgrade
or display capabilities that the package obsoletes for
info, list and repoquery
--rpmverbosity [debug level name]
debugging output level for rpm
-y, --assumeyes automatically answer yes for all questions
--assumeno automatically answer no for all questions
--enablerepo [repo]
--disablerepo [repo]
--repo [repo], --repoid [repo]
enable just specific repositories by an id or a glob,
can be specified multiple times
-x [package], --exclude [package], --excludepkgs [package]
exclude packages by name or glob
--disableexcludes [repo], --disableexcludepkgs [repo]
disable excludepkgs
--repofrompath [repo,path]
label and path to additional repository, can be
specified multiple times.
--noautoremove disable removal of dependencies that are no longer
used
--nogpgcheck disable gpg signature checking
--color COLOR control whether colour is used
--refresh set metadata as expired before running the command
-4 resolve to IPv4 addresses only
-6 resolve to IPv6 addresses only
--destdir DESTDIR, --downloaddir DESTDIR
set directory to copy packages to
--downloadonly only download packages
--bugfix Include bugfix relevant packages, in updates
--enhancement Include enhancement relevant packages, in updates
--newpackage Include newpackage relevant packages, in updates
--security Include security relevant packages, in updates
--advisory ADVISORY, --advisories ADVISORY
Include packages needed to fix the given advisory, in
updates
--bzs BUGZILLA Include packages needed to fix the given BZ, in
updates
--cves CVES Include packages needed to fix the given CVE, in
updates
--sec-severity {Critical,Important,Moderate,Low}, --secseverity {Critical,Important,Moderate,Low}
Include security relevant packages matching the
severity, in updates
--forcearch ARCH Force the use of an architecture
'''
dnf_operations = ['autoremove', 'check', 'check-update', 'clean', 'deplist',
'distro-sync', 'downgrade', 'group', 'help', 'history',
'info', 'install', 'list', 'makecache', 'mark', 'provides',
'reinstall', 'remove', 'repolist', 'repoquery',
'repository-packages', 'search', 'shell', 'swap', 'updateinfo',
'upgrade', 'upgrade-minimal', 'builddep', 'config-manager',
'copr', 'debug-dump', 'debug-restore', 'debuginfo-install',
'download', 'needs-restarting', 'playground', 'repoclosure',
'repograph', 'repomanage', 'reposync']
def invalid_command(command):
return """No such command: %s. Please use /usr/bin/dnf --help
It could be a DNF plugin command, try: "dnf install 'dnf-command(%s)'"
""" % (command, command)
@pytest.mark.parametrize('output', [
(invalid_command('saerch')),
(invalid_command('isntall'))
])
def test_match(output):
assert match(Command('dnf', output))
@pytest.mark.parametrize('script, output', [
('pip', invalid_command('isntall')),
('vim', "")
])
def test_not_match(script, output):
assert not match(Command(script, output))
@pytest.fixture
def set_help(mocker):
mock = mocker.patch('subprocess.Popen')
def _set_text(text):
mock.return_value.stdout = BytesIO(text)
return _set_text
def test_get_operations(set_help):
set_help(help_text)
assert _get_operations() == dnf_operations
@pytest.mark.parametrize('script, output, result', [
('dnf isntall vim', invalid_command('isntall'),
'dnf install vim'),
('dnf saerch vim', invalid_command('saerch'),
'dnf search vim'),
])
def test_get_new_command(set_help, output, script, result):
set_help(help_text)
assert result in get_new_command(Command(script, output))
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_python_execute.py | tests/rules/test_python_execute.py | import pytest
from thefuck.rules.python_execute import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('command', [
Command('python foo', ''),
Command('python bar', '')])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('python foo', ''), 'python foo.py'),
(Command('python bar', ''), 'python bar.py')])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_sudo.py | tests/rules/test_sudo.py | import pytest
from thefuck.rules.sudo import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('output', [
'Permission denied',
'permission denied',
"npm ERR! Error: EACCES, unlink",
'requested operation requires superuser privilege',
'need to be root',
'need root',
'shutdown: NOT super-user',
'Error: This command has to be run with superuser privileges (under the root user on most systems).',
'updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db',
'must be root',
'You don\'t have access to the history DB.',
"error: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/ipaddr.py'"])
def test_match(output):
assert match(Command('', output))
def test_not_match():
assert not match(Command('', ''))
assert not match(Command('sudo ls', 'Permission denied'))
@pytest.mark.parametrize('before, after', [
('ls', 'sudo ls'),
('echo a > b', 'sudo sh -c "echo a > b"'),
('echo "a" >> b', 'sudo sh -c "echo \\"a\\" >> b"'),
('mkdir && touch a', 'sudo sh -c "mkdir && touch a"')])
def test_get_new_command(before, after):
assert get_new_command(Command(before, '')) == after
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_touch.py | tests/rules/test_touch.py | import pytest
from thefuck.rules.touch import match, get_new_command
from thefuck.types import Command
def output(is_bsd):
if is_bsd:
return "touch: /a/b/c: No such file or directory"
return "touch: cannot touch '/a/b/c': No such file or directory"
@pytest.mark.parametrize('script, is_bsd', [
('touch /a/b/c', False),
('touch /a/b/c', True)])
def test_match(script, is_bsd):
command = Command(script, output(is_bsd))
assert match(command)
@pytest.mark.parametrize('command', [
Command('touch /a/b/c', ''),
Command('ls /a/b/c', output(False))])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('script, is_bsd', [
('touch /a/b/c', False),
('touch /a/b/c', True)])
def test_get_new_command(script, is_bsd):
command = Command(script, output(is_bsd))
fixed_command = get_new_command(command)
assert fixed_command == 'mkdir -p /a/b && touch /a/b/c'
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_cd_correction.py | tests/rules/test_cd_correction.py | import pytest
from thefuck.rules.cd_correction import match
from thefuck.types import Command
@pytest.mark.parametrize('command', [
Command('cd foo', 'cd: foo: No such file or directory'),
Command('cd foo/bar/baz',
'cd: foo: No such file or directory'),
Command('cd foo/bar/baz', 'cd: can\'t cd to foo/bar/baz'),
Command('cd /foo/bar/', 'cd: The directory "/foo/bar/" does not exist')])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('cd foo', ''), Command('', '')])
def test_not_match(command):
assert not match(command)
# Note that get_new_command uses local filesystem, so not testing it here.
# Instead, see the functional test `functional.test_cd_correction`
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_apt_get_search.py | tests/rules/test_apt_get_search.py | import pytest
from thefuck.rules.apt_get_search import get_new_command, match
from thefuck.types import Command
def test_match():
assert match(Command('apt-get search foo', ''))
@pytest.mark.parametrize('command', [
Command('apt-cache search foo', ''),
Command('aptitude search foo', ''),
Command('apt search foo', ''),
Command('apt-get install foo', ''),
Command('apt-get source foo', ''),
Command('apt-get clean', ''),
Command('apt-get remove', ''),
Command('apt-get update', '')
])
def test_not_match(command):
assert not match(command)
def test_get_new_command():
new_command = get_new_command(Command('apt-get search foo', ''))
assert new_command == 'apt-cache search foo'
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_heroku_multiple_apps.py | tests/rules/test_heroku_multiple_apps.py | # -*- coding: utf-8 -*-
import pytest
from thefuck.types import Command
from thefuck.rules.heroku_multiple_apps import match, get_new_command
suggest_output = '''
▸ Multiple apps in git remotes
▸ Usage: --remote heroku-dev
▸ or: --app myapp-dev
▸ Your local git repository has more than 1 app referenced in git remotes.
▸ Because of this, we can't determine which app you want to run this command against.
▸ Specify the app you want with --app or --remote.
▸ Heroku remotes in repo:
▸ myapp (heroku)
▸ myapp-dev (heroku-dev)
▸
▸ https://devcenter.heroku.com/articles/multiple-environments
'''
not_match_output = '''
=== HEROKU_POSTGRESQL_TEAL_URL, DATABASE_URL
Plan: Hobby-basic
Status: Available
Connections: 20/20
PG Version: 9.6.4
Created: 2017-01-01 00:00 UTC
Data Size: 99.9 MB
Tables: 99
Rows: 12345/10000000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
Continuous Protection: Off
Add-on: postgresql-round-12345
'''
@pytest.mark.parametrize('cmd', ['pg'])
def test_match(cmd):
assert match(
Command('heroku {}'.format(cmd), suggest_output))
@pytest.mark.parametrize('script, output', [
('heroku pg', not_match_output)])
def test_not_match(script, output):
assert not match(Command(script, output))
@pytest.mark.parametrize('cmd, result', [
('pg', ['heroku pg --app myapp', 'heroku pg --app myapp-dev'])])
def test_get_new_command(cmd, result):
command = Command('heroku {}'.format(cmd), suggest_output)
assert get_new_command(command) == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_python_command.py | tests/rules/test_python_command.py | from thefuck.rules.python_command import match, get_new_command
from thefuck.types import Command
def test_match():
assert match(Command('temp.py', 'Permission denied'))
assert not match(Command('', ''))
def test_get_new_command():
assert (get_new_command(Command('./test_sudo.py', ''))
== 'python ./test_sudo.py')
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_remote_delete.py | tests/rules/test_git_remote_delete.py | import pytest
from thefuck.rules.git_remote_delete import get_new_command, match
from thefuck.types import Command
def test_match():
assert match(Command('git remote delete foo', ''))
@pytest.mark.parametrize('command', [
Command('git remote remove foo', ''),
Command('git remote add foo', ''),
Command('git commit', '')
])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('git remote delete foo', ''), 'git remote remove foo'),
(Command('git remote delete delete', ''), 'git remote remove delete'),
])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_push_without_commits.py | tests/rules/test_git_push_without_commits.py | from thefuck.types import Command
from thefuck.rules.git_push_without_commits import get_new_command, match
def test_match():
script = "git push -u origin master"
output = "error: src refspec master does not match any\nerror: failed to..."
assert match(Command(script, output))
def test_not_match():
script = "git push -u origin master"
assert not match(Command(script, "Everything up-to-date"))
def test_get_new_command():
script = "git push -u origin master"
output = "error: src refspec master does not match any\nerror: failed to..."
new_command = 'git commit -m "Initial commit" && git push -u origin master'
assert get_new_command(Command(script, output)) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_push.py | tests/rules/test_git_push.py | import pytest
from thefuck.rules.git_push import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def output(branch_name):
if not branch_name:
return ''
return '''fatal: The current branch {} has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin {}
'''.format(branch_name, branch_name)
@pytest.fixture
def output_bitbucket():
return '''Total 0 (delta 0), reused 0 (delta 0)
remote:
remote: Create pull request for feature/set-upstream:
remote: https://bitbucket.org/set-upstream
remote:
To git@bitbucket.org:test.git
e5e7fbb..700d998 feature/set-upstream -> feature/set-upstream
Branch feature/set-upstream set up to track remote branch feature/set-upstream from origin.
'''
@pytest.mark.parametrize('script, branch_name', [
('git push', 'master'),
('git push origin', 'master')])
def test_match(output, script, branch_name):
assert match(Command(script, output))
def test_match_bitbucket(output_bitbucket):
assert not match(Command('git push origin', output_bitbucket))
@pytest.mark.parametrize('script, branch_name', [
('git push master', None),
('ls', 'master')])
def test_not_match(output, script, branch_name):
assert not match(Command(script, output))
@pytest.mark.parametrize('script, branch_name, new_command', [
('git push', 'master',
'git push --set-upstream origin master'),
('git push master', 'master',
'git push --set-upstream origin master'),
('git push -u', 'master',
'git push --set-upstream origin master'),
('git push -u origin', 'master',
'git push --set-upstream origin master'),
('git push origin', 'master',
'git push --set-upstream origin master'),
('git push --set-upstream origin', 'master',
'git push --set-upstream origin master'),
('git push --quiet', 'master',
'git push --set-upstream origin master --quiet'),
('git push --quiet origin', 'master',
'git push --set-upstream origin master --quiet'),
('git -c test=test push --quiet origin', 'master',
'git -c test=test push --set-upstream origin master --quiet'),
('git push', "test's",
"git push --set-upstream origin test\\'s"),
('git push --force', 'master',
'git push --set-upstream origin master --force'),
('git push --force-with-lease', 'master',
'git push --set-upstream origin master --force-with-lease')])
def test_get_new_command(output, script, branch_name, new_command):
assert get_new_command(Command(script, output)) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_java.py | tests/rules/test_java.py | import pytest
from thefuck.rules.java import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('command', [
Command('java foo.java', ''),
Command('java bar.java', '')])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('java foo.java', ''), 'java foo'),
(Command('java bar.java', ''), 'java bar')])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_has_exists_script.py | tests/rules/test_has_exists_script.py | from mock import patch
from thefuck.rules.has_exists_script import match, get_new_command
from thefuck.types import Command
def test_match():
with patch('os.path.exists', return_value=True):
assert match(Command('main', 'main: command not found'))
assert match(Command('main --help',
'main: command not found'))
assert not match(Command('main', ''))
with patch('os.path.exists', return_value=False):
assert not match(Command('main', 'main: command not found'))
def test_get_new_command():
assert get_new_command(Command('main --help', '')) == './main --help'
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_quotation_marks.py | tests/rules/test_quotation_marks.py | import pytest
from thefuck.rules.quotation_marks import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('command', [
Command("git commit -m \'My Message\"", ''),
Command("git commit -am \"Mismatched Quotation Marks\'", ''),
Command("echo \"hello\'", '')])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command, new_command', [
(Command("git commit -m \'My Message\"", ''), "git commit -m \"My Message\""),
(Command("git commit -am \"Mismatched Quotation Marks\'", ''), "git commit -am \"Mismatched Quotation Marks\""),
(Command("echo \"hello\'", ''), "echo \"hello\"")])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_fab_command_not_found.py | tests/rules/test_fab_command_not_found.py | import pytest
from thefuck.rules.fab_command_not_found import match, get_new_command
from thefuck.types import Command
output = '''
Warning: Command(s) not found:
extenson
deloyp
Available commands:
update_config
prepare_extension
Template A string class for supporting $-substitutions.
deploy
glob Return a list of paths matching a pathname pattern.
install_web
set_version
'''
@pytest.mark.parametrize('command', [
Command('fab extenson', output),
Command('fab deloyp', output),
Command('fab extenson deloyp', output)])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('gulp extenson', output),
Command('fab deloyp', '')])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('script, result', [
('fab extenson', 'fab prepare_extension'),
('fab extenson:version=2016',
'fab prepare_extension:version=2016'),
('fab extenson:version=2016 install_web set_version:val=0.5.0',
'fab prepare_extension:version=2016 install_web set_version:val=0.5.0'),
('fab extenson:version=2016 deloyp:beta=true -H the.fuck',
'fab prepare_extension:version=2016 deploy:beta=true -H the.fuck'),
])
def test_get_new_command(script, result):
command = Command(script, output)
assert get_new_command(command) == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_fix_stash.py | tests/rules/test_git_fix_stash.py | import pytest
from thefuck.rules.git_fix_stash import match, get_new_command
from thefuck.types import Command
git_stash_err = '''
usage: git stash list [<options>]
or: git stash show [<stash>]
or: git stash drop [-q|--quiet] [<stash>]
or: git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
or: git stash branch <branchname> [<stash>]
or: git stash [save [--patch] [-k|--[no-]keep-index] [-q|--quiet]
\t\t [-u|--include-untracked] [-a|--all] [<message>]]
or: git stash clear
'''
@pytest.mark.parametrize('wrong', [
'git stash opp',
'git stash Some message',
'git stash saev Some message'])
def test_match(wrong):
assert match(Command(wrong, git_stash_err))
def test_not_match():
assert not match(Command("git", git_stash_err))
@pytest.mark.parametrize('wrong,fixed', [
('git stash opp', 'git stash pop'),
('git stash Some message', 'git stash save Some message'),
('git stash saev Some message', 'git stash save Some message')])
def test_get_new_command(wrong, fixed):
assert get_new_command(Command(wrong, git_stash_err)) == fixed
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_add.py | tests/rules/test_git_add.py | import pytest
from thefuck.rules.git_add import match, get_new_command
from thefuck.types import Command
@pytest.fixture(autouse=True)
def path_exists(mocker):
return mocker.patch('thefuck.rules.git_add.Path.exists',
return_value=True)
@pytest.fixture
def output(target):
return ("error: pathspec '{}' did not match any "
'file(s) known to git.'.format(target))
@pytest.mark.parametrize('script, target', [
('git submodule update unknown', 'unknown'),
('git commit unknown', 'unknown')])
def test_match(output, script, target):
assert match(Command(script, output))
@pytest.mark.parametrize('script, target, exists', [
('git submodule update known', '', True),
('git commit known', '', True),
('git submodule update known', output, False)])
def test_not_match(path_exists, output, script, target, exists):
path_exists.return_value = exists
assert not match(Command(script, output))
@pytest.mark.parametrize('script, target, new_command', [
('git submodule update unknown', 'unknown',
'git add -- unknown && git submodule update unknown'),
('git commit unknown', 'unknown',
'git add -- unknown && git commit unknown')])
def test_get_new_command(output, script, target, new_command):
assert get_new_command(Command(script, output)) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_pip_unknown_command.py | tests/rules/test_pip_unknown_command.py | import pytest
from thefuck.rules.pip_unknown_command import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def pip_unknown_cmd_without_recommend():
return '''ERROR: unknown command "i"'''
@pytest.fixture
def broken():
return 'instatl'
@pytest.fixture
def suggested():
return 'install'
@pytest.fixture
def pip_unknown_cmd(broken, suggested):
return 'ERROR: unknown command "{}" - maybe you meant "{}"'.format(broken, suggested)
def test_match(pip_unknown_cmd, pip_unknown_cmd_without_recommend):
assert match(Command('pip instatl', pip_unknown_cmd))
assert not match(Command('pip i',
pip_unknown_cmd_without_recommend))
@pytest.mark.parametrize('script, broken, suggested, new_cmd', [
('pip un+install thefuck', 'un+install', 'uninstall', 'pip uninstall thefuck'),
('pip instatl', 'instatl', 'install', 'pip install')])
def test_get_new_command(script, new_cmd, pip_unknown_cmd):
assert get_new_command(Command(script,
pip_unknown_cmd)) == new_cmd
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_brew_cask_dependency.py | tests/rules/test_brew_cask_dependency.py | import pytest
from thefuck.rules.brew_cask_dependency import match, get_new_command
from thefuck.types import Command
output = '''sshfs: OsxfuseRequirement unsatisfied!
You can install with Homebrew-Cask:
brew cask install osxfuse
You can download from:
https://osxfuse.github.io/
Error: An unsatisfied requirement failed this build.'''
def test_match():
command = Command('brew install sshfs', output)
assert match(command)
@pytest.mark.parametrize('script, output', [
('brew link sshfs', output),
('cat output', output),
('brew install sshfs', '')])
def test_not_match(script, output):
command = Command(script, output)
assert not match(command)
@pytest.mark.parametrize('before, after', [
('brew install sshfs',
'brew cask install osxfuse && brew install sshfs')])
def test_get_new_command(before, after):
command = Command(before, output)
assert get_new_command(command) == after
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_switch_lang.py | tests/rules/test_switch_lang.py | # -*- encoding: utf-8 -*-
import pytest
from thefuck.rules import switch_lang
from thefuck.types import Command
@pytest.mark.parametrize('command', [
Command(u'фзе-пуе', 'command not found: фзе-пуе'),
Command(u'λσ', 'command not found: λσ'),
Command(u'שפא-עקא', 'command not found: שפא-עקא'),
Command(u'ךד', 'command not found: ךד'),
Command(u'녀애 ㅣㄴ', 'command not found: 녀애 ㅣㄴ')])
def test_match(command):
assert switch_lang.match(command)
@pytest.mark.parametrize('command', [
Command(u'pat-get', 'command not found: pat-get'),
Command(u'ls', 'command not found: ls'),
Command(u'агсл', 'command not found: агсл'),
Command(u'фзе-пуе', 'some info'),
Command(u'שפא-עקא', 'some info'),
Command(u'녀애 ㅣㄴ', 'some info')])
def test_not_match(command):
assert not switch_lang.match(command)
@pytest.mark.parametrize('command, new_command', [
(Command(u'фзе-пуе штыефдд мшь', ''), 'apt-get install vim'),
(Command(u'λσ -λα', ''), 'ls -la'),
(Command(u'שפא-עקא ןמדאשךך הןצ', ''), 'apt-get install vim'),
(Command(u'ךד -ךש', ''), 'ls -la'),
(Command(u'멧-ㅎㄷㅅ ㅑㅜㄴㅅ미ㅣ 퍄ㅡ', ''), 'apt-get install vim'),
(Command(u'ㅣㄴ -ㅣㅁ', ''), 'ls -la'),
(Command(u'ㅔㅁㅅ촤', ''), 'patchk'), ])
def test_get_new_command(command, new_command):
assert switch_lang.get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_ssh_known_host.py | tests/rules/test_ssh_known_host.py | import os
import pytest
from thefuck.rules.ssh_known_hosts import match, get_new_command, \
side_effect
from thefuck.types import Command
@pytest.fixture
def ssh_error(tmpdir):
path = os.path.join(str(tmpdir), 'known_hosts')
def reset(path):
with open(path, 'w') as fh:
lines = [
'123.234.567.890 asdjkasjdakjsd\n'
'98.765.432.321 ejioweojwejrosj\n'
'111.222.333.444 qwepoiwqepoiss\n'
]
fh.writelines(lines)
def known_hosts(path):
with open(path, 'r') as fh:
return fh.readlines()
reset(path)
errormsg = u"""@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
b6:cb:07:34:c0:a0:94:d3:0d:69:83:31:f4:c5:20:9b.
Please contact your system administrator.
Add correct host key in {0} to get rid of this message.
Offending RSA key in {0}:2
RSA host key for {1} has changed and you have requested strict checking.
Host key verification failed.""".format(path, '98.765.432.321')
return errormsg, path, reset, known_hosts
def test_match(ssh_error):
errormsg, _, _, _ = ssh_error
assert match(Command('ssh', errormsg))
assert match(Command('ssh', errormsg))
assert match(Command('scp something something', errormsg))
assert match(Command('scp something something', errormsg))
assert not match(Command(errormsg, ''))
assert not match(Command('notssh', errormsg))
assert not match(Command('ssh', ''))
@pytest.mark.skipif(os.name == 'nt', reason='Skip if testing on Windows')
def test_side_effect(ssh_error):
errormsg, path, reset, known_hosts = ssh_error
command = Command('ssh user@host', errormsg)
side_effect(command, None)
expected = ['123.234.567.890 asdjkasjdakjsd\n', '111.222.333.444 qwepoiwqepoiss\n']
assert known_hosts(path) == expected
def test_get_new_command(ssh_error, monkeypatch):
errormsg, _, _, _ = ssh_error
assert get_new_command(Command('ssh user@host', errormsg)) == 'ssh user@host'
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_prove_recursively.py | tests/rules/test_prove_recursively.py | import pytest
from thefuck.rules.prove_recursively import match, get_new_command
from thefuck.types import Command
output = '''Files=0, Tests=0, 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)
Result: NOTESTS'''
@pytest.fixture
def isdir(mocker):
return mocker.patch('thefuck.rules.prove_recursively'
'.os.path.isdir')
@pytest.mark.parametrize('script, output', [
('prove -lv t', output),
('prove app/t', output)])
def test_match(isdir, script, output):
isdir.return_value = True
command = Command(script, output)
assert match(command)
@pytest.mark.parametrize('script, output, isdir_result', [
('prove -lv t', output, False),
('prove -r t', output, True),
('prove --recurse t', output, True)])
def test_not_match(isdir, script, output, isdir_result):
isdir.return_value = isdir_result
command = Command(script, output)
assert not match(command)
@pytest.mark.parametrize('before, after', [
('prove -lv t', 'prove -r -lv t'),
('prove t', 'prove -r t')])
def test_get_new_command(before, after):
command = Command(before, output)
assert get_new_command(command) == after
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_nixos_cmd_not_found.py | tests/rules/test_nixos_cmd_not_found.py | import pytest
from thefuck.rules.nixos_cmd_not_found import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('command', [
Command('vim', 'nix-env -iA nixos.vim')])
def test_match(mocker, command):
mocker.patch('thefuck.rules.nixos_cmd_not_found', return_value=None)
assert match(command)
@pytest.mark.parametrize('command', [
Command('vim', ''),
Command('', '')])
def test_not_match(mocker, command):
mocker.patch('thefuck.rules.nixos_cmd_not_found', return_value=None)
assert not match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('vim', 'nix-env -iA nixos.vim'), 'nix-env -iA nixos.vim && vim'),
(Command('pacman', 'nix-env -iA nixos.pacman'), 'nix-env -iA nixos.pacman && pacman')])
def test_get_new_command(mocker, command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_commit_reset.py | tests/rules/test_git_commit_reset.py | import pytest
from thefuck.rules.git_commit_reset import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('script, output', [
('git commit -m "test"', 'test output'),
('git commit', '')])
def test_match(output, script):
assert match(Command(script, output))
@pytest.mark.parametrize('script', [
'git branch foo',
'git checkout feature/test_commit',
'git push'])
def test_not_match(script):
assert not match(Command(script, ''))
@pytest.mark.parametrize('script', [
('git commit -m "test commit"'),
('git commit')])
def test_get_new_command(script):
assert get_new_command(Command(script, '')) == 'git reset HEAD~'
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_cd_parent.py | tests/rules/test_cd_parent.py | from thefuck.rules.cd_parent import match, get_new_command
from thefuck.types import Command
def test_match():
assert match(Command('cd..', 'cd..: command not found'))
assert not match(Command('', ''))
def test_get_new_command():
assert get_new_command(Command('cd..', '')) == 'cd ..'
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_brew_reinstall.py | tests/rules/test_brew_reinstall.py | import pytest
from thefuck.types import Command
from thefuck.rules.brew_reinstall import get_new_command, match
output = ("Warning: thefuck 9.9 is already installed and up-to-date\nTo "
"reinstall 9.9, run `brew reinstall thefuck`")
def test_match():
command = Command('brew install thefuck', output)
assert match(command)
@pytest.mark.parametrize('script', [
'brew reinstall thefuck',
'brew install foo'])
def test_not_match(script):
assert not match(Command(script, ''))
@pytest.mark.parametrize('script, formula, ', [
('brew install foo', 'foo'),
('brew install bar zap', 'bar zap')])
def test_get_new_command(script, formula):
command = Command(script, output)
new_command = 'brew reinstall {}'.format(formula)
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_pacman.py | tests/rules/test_pacman.py | import pytest
from mock import patch
from thefuck.rules import pacman
from thefuck.rules.pacman import match, get_new_command
from thefuck.types import Command
pacman_cmd = getattr(pacman, 'pacman', 'pacman')
PKGFILE_OUTPUT_SUDO = 'core/sudo 1.8.13-13/usr/bin/sudo'
PKGFILE_OUTPUT_CONVERT = 'extra/imagemagick 6.9.1.0-1\t/usr/bin/convert'
PKGFILE_OUTPUT_VIM = '''extra/gvim 7.4.712-1 \t/usr/bin/vim
extra/gvim-python3 7.4.712-1\t/usr/bin/vim
extra/vim 7.4.712-1 \t/usr/bin/vim
extra/vim-minimal 7.4.712-1 \t/usr/bin/vim
extra/vim-python3 7.4.712-1 \t/usr/bin/vim'''
@pytest.mark.skipif(not getattr(pacman, 'enabled_by_default', True),
reason='Skip if pacman is not available')
@pytest.mark.parametrize('command', [
Command('vim', 'vim: command not found'),
Command('sudo vim', 'sudo: vim: command not found')])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command, return_value', [
(Command('vim', 'vim: command not found'), PKGFILE_OUTPUT_VIM),
(Command('sudo vim', 'sudo: vim: command not found'), PKGFILE_OUTPUT_VIM)])
@patch('thefuck.specific.archlinux.subprocess')
@patch.multiple(pacman, create=True, pacman=pacman_cmd)
def test_match_mocked(subp_mock, command, return_value):
subp_mock.check_output.return_value = return_value
assert match(command)
@pytest.mark.parametrize('command', [
Command('vim', ''), Command('', ''),
Command('sudo vim', ''), Command('', '')])
def test_not_match(command):
assert not match(command)
sudo_vim_possibilities = ['{} -S extra/gvim && sudo vim',
'{} -S extra/gvim-python3 && sudo vim',
'{} -S extra/vim && sudo vim',
'{} -S extra/vim-minimal && sudo vim',
'{} -S extra/vim-python3 && sudo vim']
sudo_vim_possibilities = [s.format(pacman_cmd) for s in sudo_vim_possibilities]
vim_possibilities = ['{} -S extra/gvim && vim',
'{} -S extra/gvim-python3 && vim',
'{} -S extra/vim && vim',
'{} -S extra/vim-minimal && vim',
'{} -S extra/vim-python3 && vim']
vim_possibilities = [s.format(pacman_cmd) for s in vim_possibilities]
@pytest.mark.skipif(not getattr(pacman, 'enabled_by_default', True),
reason='Skip if pacman is not available')
@pytest.mark.parametrize('command, new_command', [
(Command('vim', ''), vim_possibilities),
(Command('sudo vim', ''), sudo_vim_possibilities),
(Command('convert', ''), ['{} -S extra/imagemagick && convert'.format(pacman_cmd)]),
(Command('sudo convert', ''), ['{} -S extra/imagemagick && sudo convert'.format(pacman_cmd)])])
def test_get_new_command(command, new_command, mocker):
assert get_new_command(command) == new_command
@pytest.mark.parametrize('command, new_command, return_value', [
(Command('vim', ''), vim_possibilities, PKGFILE_OUTPUT_VIM),
(Command('sudo vim', ''), sudo_vim_possibilities, PKGFILE_OUTPUT_VIM),
(Command('convert', ''), ['{} -S extra/imagemagick && convert'.format(pacman_cmd)], PKGFILE_OUTPUT_CONVERT),
(Command('sudo', ''), ['{} -S core/sudo && sudo'.format(pacman_cmd)], PKGFILE_OUTPUT_SUDO),
(Command('sudo convert', ''), ['{} -S extra/imagemagick && sudo convert'.format(pacman_cmd)], PKGFILE_OUTPUT_CONVERT)])
@patch('thefuck.specific.archlinux.subprocess')
@patch.multiple(pacman, create=True, pacman=pacman_cmd)
def test_get_new_command_mocked(subp_mock, command, new_command, return_value):
subp_mock.check_output.return_value = return_value
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_hook_bypass.py | tests/rules/test_git_hook_bypass.py | import pytest
from thefuck.rules.git_hook_bypass import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize(
"command",
[
Command("git am", ""),
Command("git commit", ""),
Command("git commit -m 'foo bar'", ""),
Command("git push", ""),
Command("git push -u foo bar", ""),
],
)
def test_match(command):
assert match(command)
@pytest.mark.parametrize(
"command",
[
Command("git add foo", ""),
Command("git status", ""),
Command("git diff foo bar", ""),
],
)
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize(
"command, new_command",
[
(Command("git am", ""), "git am --no-verify"),
(Command("git commit", ""), "git commit --no-verify"),
(Command("git commit -m 'foo bar'", ""), "git commit --no-verify -m 'foo bar'"),
(Command("git push", ""), "git push --no-verify"),
(Command("git push -p", ""), "git push --no-verify -p"),
],
)
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_pull_unstaged_changes.py | tests/rules/test_git_pull_unstaged_changes.py | import pytest
from thefuck.rules.git_pull_uncommitted_changes import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def output():
return '''error: Cannot pull with rebase: Your index contains uncommitted changes.'''
def test_match(output):
assert match(Command('git pull', output))
assert not match(Command('git pull', ''))
assert not match(Command('ls', output))
def test_get_new_command(output):
assert (get_new_command(Command('git pull', output))
== "git stash && git pull && git stash pop")
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_lein_not_task.py | tests/rules/test_lein_not_task.py | import pytest
from thefuck.rules.lein_not_task import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def is_not_task():
return ''''rpl' is not a task. See 'lein help'.
Did you mean this?
repl
jar
'''
def test_match(is_not_task):
assert match(Command('lein rpl', is_not_task))
assert not match(Command('ls', is_not_task))
def test_get_new_command(is_not_task):
assert (get_new_command(Command('lein rpl --help', is_not_task))
== ['lein repl --help', 'lein jar --help'])
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_conda_mistype.py | tests/rules/test_conda_mistype.py | import pytest
from thefuck.rules.conda_mistype import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def mistype_response():
return """
CommandNotFoundError: No command 'conda lst'.
Did you mean 'conda list'?
"""
def test_match(mistype_response):
assert match(Command('conda lst', mistype_response))
err_response = 'bash: codna: command not found'
assert not match(Command('codna list', err_response))
def test_get_new_command(mistype_response):
assert (get_new_command(Command('conda lst', mistype_response)) == ['conda list'])
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_help_aliased.py | tests/rules/test_git_help_aliased.py | import pytest
from thefuck.rules.git_help_aliased import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('script, output', [
('git help st', "`git st' is aliased to `status'"),
('git help ds', "`git ds' is aliased to `diff --staged'")])
def test_match(script, output):
assert match(Command(script, output))
@pytest.mark.parametrize('script, output', [
('git help status', "GIT-STATUS(1)...Git Manual...GIT-STATUS(1)"),
('git help diff', "GIT-DIFF(1)...Git Manual...GIT-DIFF(1)")])
def test_not_match(script, output):
assert not match(Command(script, output))
@pytest.mark.parametrize('script, output, new_command', [
('git help st', "`git st' is aliased to `status'", 'git help status'),
('git help ds', "`git ds' is aliased to `diff --staged'", 'git help diff')])
def test_get_new_command(script, output, new_command):
assert get_new_command(Command(script, output)) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_dirty_untar.py | tests/rules/test_dirty_untar.py | import os
import pytest
import tarfile
from thefuck.rules.dirty_untar import match, get_new_command, side_effect, \
tar_extensions # noqa: E126
from thefuck.types import Command
@pytest.fixture
def tar_error(tmpdir):
def fixture(filename):
path = os.path.join(str(tmpdir), filename)
def reset(path):
os.mkdir('d')
with tarfile.TarFile(path, 'w') as archive:
for file in ('a', 'b', 'c', 'd/e'):
with open(file, 'w') as f:
f.write('*')
archive.add(file)
os.remove(file)
with tarfile.TarFile(path, 'r') as archive:
archive.extractall()
os.chdir(str(tmpdir))
reset(path)
assert set(os.listdir('.')) == {filename, 'a', 'b', 'c', 'd'}
assert set(os.listdir('./d')) == {'e'}
return fixture
parametrize_extensions = pytest.mark.parametrize('ext', tar_extensions)
# (filename as typed by the user, unquoted filename, quoted filename as per shells.quote)
parametrize_filename = pytest.mark.parametrize('filename, unquoted, quoted', [
('foo{}', 'foo{}', 'foo{}'),
('"foo bar{}"', 'foo bar{}', "'foo bar{}'")])
parametrize_script = pytest.mark.parametrize('script, fixed', [
('tar xvf {}', 'mkdir -p {dir} && tar xvf {filename} -C {dir}'),
('tar -xvf {}', 'mkdir -p {dir} && tar -xvf {filename} -C {dir}'),
('tar --extract -f {}', 'mkdir -p {dir} && tar --extract -f {filename} -C {dir}')])
@parametrize_extensions
@parametrize_filename
@parametrize_script
def test_match(ext, tar_error, filename, unquoted, quoted, script, fixed):
tar_error(unquoted.format(ext))
assert match(Command(script.format(filename.format(ext)), ''))
@parametrize_extensions
@parametrize_filename
@parametrize_script
def test_side_effect(ext, tar_error, filename, unquoted, quoted, script, fixed):
tar_error(unquoted.format(ext))
side_effect(Command(script.format(filename.format(ext)), ''), None)
assert set(os.listdir('.')) == {unquoted.format(ext), 'd'}
@parametrize_extensions
@parametrize_filename
@parametrize_script
def test_get_new_command(ext, tar_error, filename, unquoted, quoted, script, fixed):
tar_error(unquoted.format(ext))
assert (get_new_command(Command(script.format(filename.format(ext)), ''))
== fixed.format(dir=quoted.format(''), filename=filename.format(ext)))
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_diff_no_index.py | tests/rules/test_git_diff_no_index.py | import pytest
from thefuck.rules.git_diff_no_index import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('command', [
Command('git diff foo bar', '')])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('git diff --no-index foo bar', ''),
Command('git diff foo', ''),
Command('git diff foo bar baz', '')])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('git diff foo bar', ''), 'git diff --no-index foo bar')])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_commit_add.py | tests/rules/test_git_commit_add.py | import pytest
from thefuck.rules.git_commit_add import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize(
"script, output",
[
('git commit -m "test"', "no changes added to commit"),
("git commit", "no changes added to commit"),
],
)
def test_match(output, script):
assert match(Command(script, output))
@pytest.mark.parametrize(
"script, output",
[
('git commit -m "test"', " 1 file changed, 15 insertions(+), 14 deletions(-)"),
("git branch foo", ""),
("git checkout feature/test_commit", ""),
("git push", ""),
],
)
def test_not_match(output, script):
assert not match(Command(script, output))
@pytest.mark.parametrize(
"script, new_command",
[
("git commit", ["git commit -a", "git commit -p"]),
('git commit -m "foo"', ['git commit -a -m "foo"', 'git commit -p -m "foo"']),
],
)
def test_get_new_command(script, new_command):
assert get_new_command(Command(script, "")) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_remove_trailing_cedilla.py | tests/rules/test_remove_trailing_cedilla.py | import pytest
from thefuck.rules.remove_trailing_cedilla import match, get_new_command, CEDILLA
from thefuck.types import Command
@pytest.mark.parametrize('command', [
Command('wrong' + CEDILLA, ''),
Command('wrong with args' + CEDILLA, '')])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('wrong' + CEDILLA, ''), 'wrong'),
(Command('wrong with args' + CEDILLA, ''), 'wrong with args')])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_django_south_ghost.py | tests/rules/test_django_south_ghost.py | import pytest
from thefuck.rules.django_south_ghost import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def output():
return '''Traceback (most recent call last):
File "/home/nvbn/work/.../bin/python", line 42, in <module>
exec(compile(__file__f.read(), __file__, "exec"))
File "/home/nvbn/work/.../app/manage.py", line 34, in <module>
execute_from_command_line(sys.argv)
File "/home/nvbn/work/.../lib/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/home/nvbn/work/.../lib/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/nvbn/work/.../lib/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/nvbn/work/.../lib/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/home/nvbn/work/.../app/lib/south/management/commands/migrate.py", line 108, in handle
ignore_ghosts = ignore_ghosts,
File "/home/nvbn/work/.../app/lib/south/migration/__init__.py", line 193, in migrate_app
applied_all = check_migration_histories(applied_all, delete_ghosts, ignore_ghosts)
File "/home/nvbn/work/.../app/lib/south/migration/__init__.py", line 88, in check_migration_histories
raise exceptions.GhostMigrations(ghosts)
south.exceptions.GhostMigrations:
! These migrations are in the database but not on disk:
<app1: 0033_auto__...>
<app1: 0034_fill_...>
<app1: 0035_rename_...>
<app2: 0003_add_...>
<app2: 0004_denormalize_...>
<app1: 0033_auto....>
<app1: 0034_fill...>
! I'm not trusting myself; either fix this yourself by fiddling
! with the south_migrationhistory table, or pass --delete-ghost-migrations
! to South to have it delete ALL of these records (this may not be good).
''' # noqa
def test_match(output):
assert match(Command('./manage.py migrate', output))
assert match(Command('python manage.py migrate', output))
assert not match(Command('./manage.py migrate', ''))
assert not match(Command('app migrate', output))
assert not match(Command('./manage.py test', output))
def test_get_new_command():
assert get_new_command(Command('./manage.py migrate auth', ''))\
== './manage.py migrate auth --delete-ghost-migrations'
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_rebase_merge_dir.py | tests/rules/test_git_rebase_merge_dir.py | import pytest
from thefuck.rules.git_rebase_merge_dir import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def output():
return ('\n\nIt seems that there is already a rebase-merge directory, and\n'
'I wonder if you are in the middle of another rebase. If that is the\n'
'case, please try\n'
'\tgit rebase (--continue | --abort | --skip)\n'
'If that is not the case, please\n'
'\trm -fr "/foo/bar/baz/egg/.git/rebase-merge"\n'
'and run me again. I am stopping in case you still have something\n'
'valuable there.\n')
@pytest.mark.parametrize('script', [
'git rebase master',
'git rebase -skip',
'git rebase'])
def test_match(output, script):
assert match(Command(script, output))
@pytest.mark.parametrize('script', ['git rebase master', 'git rebase -abort'])
def test_not_match(script):
assert not match(Command(script, ''))
@pytest.mark.parametrize('script, result', [
('git rebase master', [
'git rebase --abort', 'git rebase --skip', 'git rebase --continue',
'rm -fr "/foo/bar/baz/egg/.git/rebase-merge"']),
('git rebase -skip', [
'git rebase --skip', 'git rebase --abort', 'git rebase --continue',
'rm -fr "/foo/bar/baz/egg/.git/rebase-merge"']),
('git rebase', [
'git rebase --skip', 'git rebase --abort', 'git rebase --continue',
'rm -fr "/foo/bar/baz/egg/.git/rebase-merge"'])])
def test_get_new_command(output, script, result):
assert get_new_command(Command(script, output)) == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_clone_git_clone.py | tests/rules/test_git_clone_git_clone.py | from thefuck.rules.git_clone_git_clone import match, get_new_command
from thefuck.types import Command
output_clean = """
fatal: Too many arguments.
usage: git clone [<options>] [--] <repo> [<dir>]
"""
def test_match():
assert match(Command('git clone git clone foo', output_clean))
def test_not_match():
assert not match(Command('', ''))
assert not match(Command('git branch', ''))
assert not match(Command('git clone foo', ''))
assert not match(Command('git clone foo bar baz', output_clean))
def test_get_new_command():
assert get_new_command(Command('git clone git clone foo', output_clean)) == 'git clone foo'
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_sl_ls.py | tests/rules/test_sl_ls.py |
from thefuck.rules.sl_ls import match, get_new_command
from thefuck.types import Command
def test_match():
assert match(Command('sl', ''))
assert not match(Command('ls', ''))
def test_get_new_command():
assert get_new_command(Command('sl', '')) == 'ls'
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_rm_local_modifications.py | tests/rules/test_git_rm_local_modifications.py | import pytest
from thefuck.rules.git_rm_local_modifications import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def output(target):
return ('error: the following file has local modifications:\n {}\n(use '
'--cached to keep the file, or -f to force removal)').format(target)
@pytest.mark.parametrize('script, target', [
('git rm foo', 'foo'),
('git rm foo bar', 'bar')])
def test_match(output, script, target):
assert match(Command(script, output))
@pytest.mark.parametrize('script', ['git rm foo', 'git rm foo bar', 'git rm'])
def test_not_match(script):
assert not match(Command(script, ''))
@pytest.mark.parametrize('script, target, new_command', [
('git rm foo', 'foo', ['git rm --cached foo', 'git rm -f foo']),
('git rm foo bar', 'bar', ['git rm --cached foo bar', 'git rm -f foo bar'])])
def test_get_new_command(output, script, target, new_command):
assert get_new_command(Command(script, output)) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_scm_correction.py | tests/rules/test_scm_correction.py | import pytest
from thefuck.rules.scm_correction import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def get_actual_scm_mock(mocker):
return mocker.patch('thefuck.rules.scm_correction._get_actual_scm',
return_value=None)
@pytest.mark.parametrize('script, output, actual_scm', [
('git log', 'fatal: Not a git repository '
'(or any of the parent directories): .git',
'hg'),
('hg log', "abort: no repository found in '/home/nvbn/exp/thefuck' "
"(.hg not found)!",
'git')])
def test_match(get_actual_scm_mock, script, output, actual_scm):
get_actual_scm_mock.return_value = actual_scm
assert match(Command(script, output))
@pytest.mark.parametrize('script, output, actual_scm', [
('git log', '', 'hg'),
('git log', 'fatal: Not a git repository '
'(or any of the parent directories): .git',
None),
('hg log', "abort: no repository found in '/home/nvbn/exp/thefuck' "
"(.hg not found)!",
None),
('not-scm log', "abort: no repository found in '/home/nvbn/exp/thefuck' "
"(.hg not found)!",
'git')])
def test_not_match(get_actual_scm_mock, script, output, actual_scm):
get_actual_scm_mock.return_value = actual_scm
assert not match(Command(script, output))
@pytest.mark.parametrize('script, actual_scm, result', [
('git log', 'hg', 'hg log'),
('hg log', 'git', 'git log')])
def test_get_new_command(get_actual_scm_mock, script, actual_scm, result):
get_actual_scm_mock.return_value = actual_scm
new_command = get_new_command(Command(script, ''))
assert new_command == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_stash_pop.py | tests/rules/test_git_stash_pop.py | import pytest
from thefuck.rules.git_stash_pop import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def output():
return '''error: Your local changes to the following files would be overwritten by merge:'''
def test_match(output):
assert match(Command('git stash pop', output))
assert not match(Command('git stash', ''))
def test_get_new_command(output):
assert (get_new_command(Command('git stash pop', output))
== "git add --update && git stash pop && git reset .")
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_sudo_command_from_user_path.py | tests/rules/test_sudo_command_from_user_path.py | import pytest
from thefuck.rules.sudo_command_from_user_path import match, get_new_command
from thefuck.types import Command
output = 'sudo: {}: command not found'
@pytest.fixture(autouse=True)
def which(mocker):
return mocker.patch('thefuck.rules.sudo_command_from_user_path.which',
return_value='/usr/bin/app')
@pytest.mark.parametrize('script, output', [
('sudo npm install -g react-native-cli', output.format('npm')),
('sudo -u app appcfg update .', output.format('appcfg'))])
def test_match(script, output):
assert match(Command(script, output))
@pytest.mark.parametrize('script, output, which_result', [
('npm --version', output.format('npm'), '/usr/bin/npm'),
('sudo npm --version', '', '/usr/bin/npm'),
('sudo npm --version', output.format('npm'), None)])
def test_not_match(which, script, output, which_result):
which.return_value = which_result
assert not match(Command(script, output))
@pytest.mark.parametrize('script, output, result', [
('sudo npm install -g react-native-cli',
output.format('npm'),
'sudo env "PATH=$PATH" npm install -g react-native-cli'),
('sudo -u app appcfg update .',
output.format('appcfg'),
'sudo -u app env "PATH=$PATH" appcfg update .')])
def test_get_new_command(script, output, result):
assert get_new_command(Command(script, output)) == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_choco_install.py | tests/rules/test_choco_install.py | import pytest
from thefuck.rules.choco_install import match, get_new_command
from thefuck.types import Command
package_not_found_error = (
'Chocolatey v0.10.15\n'
'Installing the following packages:\n'
'logstitcher\n'
'By installing you accept licenses for the packages.\n'
'logstitcher not installed. The package was not found with the source(s) listed.\n'
' Source(s): \'https://chocolatey.org/api/v2/\'\n'
' NOTE: When you specify explicit sources, it overrides default sources.\n'
'If the package version is a prerelease and you didn\'t specify `--pre`,\n'
' the package may not be found.\n'
'Please see https://chocolatey.org/docs/troubleshooting for more\n'
' assistance.\n'
'\n'
'Chocolatey installed 0/1 packages. 1 packages failed.\n'
' See the log for details (C:\\ProgramData\\chocolatey\\logs\\chocolatey.log).\n'
'\n'
'Failures\n'
' - logstitcher - logstitcher not installed. The package was not found with the source(s) listed.\n'
' Source(s): \'https://chocolatey.org/api/v2/\'\n'
' NOTE: When you specify explicit sources, it overrides default sources.\n'
'If the package version is a prerelease and you didn\'t specify `--pre`,\n'
' the package may not be found.\n'
'Please see https://chocolatey.org/docs/troubleshooting for more\n'
' assistance.\n'
)
@pytest.mark.parametrize('command', [
Command('choco install logstitcher', package_not_found_error),
Command('cinst logstitcher', package_not_found_error),
Command('choco install logstitcher -y', package_not_found_error),
Command('cinst logstitcher -y', package_not_found_error),
Command('choco install logstitcher -y -n=test', package_not_found_error),
Command('cinst logstitcher -y -n=test', package_not_found_error),
Command('choco install logstitcher -y -n=test /env', package_not_found_error),
Command('cinst logstitcher -y -n=test /env', package_not_found_error),
Command('choco install chocolatey -y', package_not_found_error),
Command('cinst chocolatey -y', package_not_found_error)])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('choco /?', ''),
Command('choco upgrade logstitcher', ''),
Command('cup logstitcher', ''),
Command('choco upgrade logstitcher -y', ''),
Command('cup logstitcher -y', ''),
Command('choco upgrade logstitcher -y -n=test', ''),
Command('cup logstitcher -y -n=test', ''),
Command('choco upgrade logstitcher -y -n=test /env', ''),
Command('cup logstitcher -y -n=test /env', ''),
Command('choco upgrade chocolatey -y', ''),
Command('cup chocolatey -y', ''),
Command('choco uninstall logstitcher', ''),
Command('cuninst logstitcher', ''),
Command('choco uninstall logstitcher -y', ''),
Command('cuninst logstitcher -y', ''),
Command('choco uninstall logstitcher -y -n=test', ''),
Command('cuninst logstitcher -y -n=test', ''),
Command('choco uninstall logstitcher -y -n=test /env', ''),
Command('cuninst logstitcher -y -n=test /env', ''),
Command('choco uninstall chocolatey -y', ''),
Command('cuninst chocolatey -y', '')])
def not_test_match(command):
assert not match(command)
@pytest.mark.parametrize('before, after', [
('choco install logstitcher', 'choco install logstitcher.install'),
('cinst logstitcher', 'cinst logstitcher.install'),
('choco install logstitcher -y', 'choco install logstitcher.install -y'),
('cinst logstitcher -y', 'cinst logstitcher.install -y'),
('choco install logstitcher -y -n=test', 'choco install logstitcher.install -y -n=test'),
('cinst logstitcher -y -n=test', 'cinst logstitcher.install -y -n=test'),
('choco install logstitcher -y -n=test /env', 'choco install logstitcher.install -y -n=test /env'),
('cinst logstitcher -y -n=test /env', 'cinst logstitcher.install -y -n=test /env'),
('choco install chocolatey -y', 'choco install chocolatey.install -y'),
('cinst chocolatey -y', 'cinst chocolatey.install -y'), ])
def test_get_new_command(before, after):
assert (get_new_command(Command(before, '')) == after)
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_mvn_no_command.py | tests/rules/test_mvn_no_command.py | import pytest
from thefuck.rules.mvn_no_command import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('command', [
Command('mvn', '[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]')])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('mvn clean', """
[INFO] Scanning for projects...[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test 0.2
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ test ---
[INFO] Deleting /home/mlk/code/test/target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.477s
[INFO] Finished at: Wed Aug 26 13:05:47 BST 2015
[INFO] Final Memory: 6M/240M
[INFO] ------------------------------------------------------------------------
"""), # noqa
Command('mvn --help', ''),
Command('mvn -v', '')
])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('mvn', '[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]'), ['mvn clean package', 'mvn clean install']),
(Command('mvn -N', '[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]'), ['mvn -N clean package', 'mvn -N clean install'])])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_apt_invalid_operation.py | tests/rules/test_apt_invalid_operation.py | from io import BytesIO
import pytest
from thefuck.types import Command
from thefuck.rules.apt_invalid_operation import match, get_new_command, \
_get_operations
invalid_operation = 'E: Invalid operation {}'.format
apt_help = b'''apt 1.0.10.2ubuntu1 for amd64 compiled on Oct 5 2015 15:55:05
Usage: apt [options] command
CLI for apt.
Basic commands:
list - list packages based on package names
search - search in package descriptions
show - show package details
update - update list of available packages
install - install packages
remove - remove packages
upgrade - upgrade the system by installing/upgrading packages
full-upgrade - upgrade the system by removing/installing/upgrading packages
edit-sources - edit the source information file
'''
apt_operations = ['list', 'search', 'show', 'update', 'install', 'remove',
'upgrade', 'full-upgrade', 'edit-sources']
apt_get_help = b'''apt 1.0.10.2ubuntu1 for amd64 compiled on Oct 5 2015 15:55:05
Usage: apt-get [options] command
apt-get [options] install|remove pkg1 [pkg2 ...]
apt-get [options] source pkg1 [pkg2 ...]
apt-get is a simple command line interface for downloading and
installing packages. The most frequently used commands are update
and install.
Commands:
update - Retrieve new lists of packages
upgrade - Perform an upgrade
install - Install new packages (pkg is libc6 not libc6.deb)
remove - Remove packages
autoremove - Remove automatically all unused packages
purge - Remove packages and config files
source - Download source archives
build-dep - Configure build-dependencies for source packages
dist-upgrade - Distribution upgrade, see apt-get(8)
dselect-upgrade - Follow dselect selections
clean - Erase downloaded archive files
autoclean - Erase old downloaded archive files
check - Verify that there are no broken dependencies
changelog - Download and display the changelog for the given package
download - Download the binary package into the current directory
Options:
-h This help text.
-q Loggable output - no progress indicator
-qq No output except for errors
-d Download only - do NOT install or unpack archives
-s No-act. Perform ordering simulation
-y Assume Yes to all queries and do not prompt
-f Attempt to correct a system with broken dependencies in place
-m Attempt to continue if archives are unlocatable
-u Show a list of upgraded packages as well
-b Build the source package after fetching it
-V Show verbose version numbers
-c=? Read this configuration file
-o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp
See the apt-get(8), sources.list(5) and apt.conf(5) manual
pages for more information and options.
This APT has Super Cow Powers.
'''
apt_get_operations = ['update', 'upgrade', 'install', 'remove', 'autoremove',
'purge', 'source', 'build-dep', 'dist-upgrade',
'dselect-upgrade', 'clean', 'autoclean', 'check',
'changelog', 'download']
new_apt_get_help = b'''apt 1.6.12 (amd64)
Usage: apt-get [options] command
apt-get [options] install|remove pkg1 [pkg2 ...]
apt-get [options] source pkg1 [pkg2 ...]
apt-get is a command line interface for retrieval of packages
and information about them from authenticated sources and
for installation, upgrade and removal of packages together
with their dependencies.
Most used commands:
update - Retrieve new lists of packages
upgrade - Perform an upgrade
install - Install new packages (pkg is libc6 not libc6.deb)
remove - Remove packages
purge - Remove packages and config files
autoremove - Remove automatically all unused packages
dist-upgrade - Distribution upgrade, see apt-get(8)
dselect-upgrade - Follow dselect selections
build-dep - Configure build-dependencies for source packages
clean - Erase downloaded archive files
autoclean - Erase old downloaded archive files
check - Verify that there are no broken dependencies
source - Download source archives
download - Download the binary package into the current directory
changelog - Download and display the changelog for the given package
See apt-get(8) for more information about the available commands.
Configuration options and syntax is detailed in apt.conf(5).
Information about how to configure sources can be found in sources.list(5).
Package and version choices can be expressed via apt_preferences(5).
Security details are available in apt-secure(8).
This APT has Super Cow Powers.
'''
new_apt_get_operations = ['update', 'upgrade', 'install', 'remove', 'purge',
'autoremove', 'dist-upgrade', 'dselect-upgrade',
'build-dep', 'clean', 'autoclean', 'check',
'source', 'download', 'changelog']
@pytest.mark.parametrize('script, output', [
('apt', invalid_operation('saerch')),
('apt-get', invalid_operation('isntall')),
('apt-cache', invalid_operation('rumove'))])
def test_match(script, output):
assert match(Command(script, output))
@pytest.mark.parametrize('script, output', [
('vim', invalid_operation('vim')),
('apt-get', "")])
def test_not_match(script, output):
assert not match(Command(script, output))
@pytest.fixture
def set_help(mocker):
mock = mocker.patch('subprocess.Popen')
def _set_text(text):
mock.return_value.stdout = BytesIO(text)
return _set_text
@pytest.mark.parametrize('app, help_text, operations', [
('apt', apt_help, apt_operations),
('apt-get', apt_get_help, apt_get_operations),
('apt-get', new_apt_get_help, new_apt_get_operations)
])
def test_get_operations(set_help, app, help_text, operations):
set_help(help_text)
assert _get_operations(app) == operations
@pytest.mark.parametrize('script, output, help_text, result', [
('apt-get isntall vim', invalid_operation('isntall'),
apt_get_help, 'apt-get install vim'),
('apt saerch vim', invalid_operation('saerch'),
apt_help, 'apt search vim'),
('apt uninstall vim', invalid_operation('uninstall'),
apt_help, 'apt remove vim'),
])
def test_get_new_command(set_help, output, script, help_text, result):
set_help(help_text)
assert get_new_command(Command(script, output))[0] == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_react_native_command_unrecognized.py | tests/rules/test_react_native_command_unrecognized.py | import pytest
from io import BytesIO
from thefuck.rules.react_native_command_unrecognized import match, \
get_new_command
from thefuck.types import Command
output = "Unrecognized command '{}'".format
stdout = b'''
Scanning 615 folders for symlinks in /home/nvbn/work/zcho/BookkaWebView/node_modules (6ms)
Usage: react-native [options] [command]
Options:
-V, --version output the version number
-h, --help output usage information
Commands:
start [options] starts the webserver
run-ios [options] builds your app and starts it on iOS simulator
run-android [options] builds your app and starts it on a connected Android emulator or device
new-library [options] generates a native library bridge
bundle [options] builds the javascript bundle for offline use
unbundle [options] builds javascript as "unbundle" for offline use
eject [options] Re-create the iOS and Android folders and native code
link [options] [packageName] links all native dependencies (updates native build files)
unlink [options] <packageName> unlink native dependency
install [options] <packageName> install and link native dependencies
uninstall [options] <packageName> uninstall and unlink native dependencies
upgrade [options] upgrade your app's template files to the latest version; run this after updating the react-native version in your package.json and running npm install
log-android [options] starts adb logcat
log-ios [options] starts iOS device syslog tail
'''
@pytest.mark.parametrize('command', [
Command('react-native star', output('star')),
Command('react-native android-logs', output('android-logs'))])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('gradle star', output('star')),
Command('react-native start', '')])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, result', [
(Command('react-native star', output('star')),
'react-native start'),
(Command('react-native logsandroid -f', output('logsandroid')),
'react-native log-android -f')])
def test_get_new_command(mocker, command, result):
patch = mocker.patch(
'thefuck.rules.react_native_command_unrecognized.Popen')
patch.return_value.stdout = BytesIO(stdout)
assert get_new_command(command)[0] == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_gem_unknown_command.py | tests/rules/test_gem_unknown_command.py | import pytest
from six import BytesIO
from thefuck.rules.gem_unknown_command import match, get_new_command
from thefuck.types import Command
output = '''
ERROR: While executing gem ... (Gem::CommandLineError)
Unknown command {}
'''
gem_help_commands_stdout = b'''
GEM commands are:
build Build a gem from a gemspec
cert Manage RubyGems certificates and signing settings
check Check a gem repository for added or missing files
cleanup Clean up old versions of installed gems
contents Display the contents of the installed gems
dependency Show the dependencies of an installed gem
environment Display information about the RubyGems environment
fetch Download a gem and place it in the current directory
generate_index Generates the index files for a gem server directory
help Provide help on the 'gem' command
install Install a gem into the local repository
list Display local gems whose name matches REGEXP
lock Generate a lockdown list of gems
mirror Mirror all gem files (requires rubygems-mirror)
open Open gem sources in editor
outdated Display all gems that need updates
owner Manage gem owners of a gem on the push server
pristine Restores installed gems to pristine condition from files
located in the gem cache
push Push a gem up to the gem server
query Query gem information in local or remote repositories
rdoc Generates RDoc for pre-installed gems
search Display remote gems whose name matches REGEXP
server Documentation and gem repository HTTP server
sources Manage the sources and cache file RubyGems uses to search
for gems
specification Display gem specification (in yaml)
stale List gems along with access times
uninstall Uninstall gems from the local repository
unpack Unpack an installed gem to the current directory
update Update installed gems to the latest version
which Find the location of a library file you can require
yank Remove a pushed gem from the index
For help on a particular command, use 'gem help COMMAND'.
Commands may be abbreviated, so long as they are unambiguous.
e.g. 'gem i rake' is short for 'gem install rake'.
'''
@pytest.fixture(autouse=True)
def gem_help_commands(mocker):
patch = mocker.patch('subprocess.Popen')
patch.return_value.stdout = BytesIO(gem_help_commands_stdout)
return patch
@pytest.mark.parametrize('script, command', [
('gem isntall jekyll', 'isntall'),
('gem last --local', 'last')])
def test_match(script, command):
assert match(Command(script, output.format(command)))
@pytest.mark.parametrize('script, output', [
('gem install jekyll', ''),
('git log', output.format('log'))])
def test_not_match(script, output):
assert not match(Command(script, output))
@pytest.mark.parametrize('script, output, result', [
('gem isntall jekyll', output.format('isntall'), 'gem install jekyll'),
('gem last --local', output.format('last'), 'gem list --local')])
def test_get_new_command(script, output, result):
new_command = get_new_command(Command(script, output))
assert new_command[0] == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_whois.py | tests/rules/test_whois.py | import pytest
from thefuck.rules.whois import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('command', [
Command('whois https://en.wikipedia.org/wiki/Main_Page', ''),
Command('whois https://en.wikipedia.org/', ''),
Command('whois meta.unix.stackexchange.com', '')])
def test_match(command):
assert match(command)
def test_not_match():
assert not match(Command('whois', ''))
# `whois com` actually makes sense
@pytest.mark.parametrize('command, new_command', [
(Command('whois https://en.wikipedia.org/wiki/Main_Page', ''),
'whois en.wikipedia.org'),
(Command('whois https://en.wikipedia.org/', ''),
'whois en.wikipedia.org'),
(Command('whois meta.unix.stackexchange.com', ''),
['whois unix.stackexchange.com',
'whois stackexchange.com',
'whois com'])])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_grep_arguments_order.py | tests/rules/test_grep_arguments_order.py | import pytest
from thefuck.rules.grep_arguments_order import get_new_command, match
from thefuck.types import Command
output = 'grep: {}: No such file or directory'.format
@pytest.fixture(autouse=True)
def os_path(monkeypatch):
monkeypatch.setattr('os.path.isfile', lambda x: not x.startswith('-'))
@pytest.mark.parametrize('script, file', [
('grep test.py test', 'test'),
('grep -lir . test', 'test'),
('egrep test.py test', 'test'),
('egrep -lir . test', 'test')])
def test_match(script, file):
assert match(Command(script, output(file)))
@pytest.mark.parametrize('script, output', [
('cat test.py', output('test')),
('grep test test.py', ''),
('grep -lir test .', ''),
('egrep test test.py', ''),
('egrep -lir test .', '')])
def test_not_match(script, output):
assert not match(Command(script, output))
@pytest.mark.parametrize('script, output, result', [
('grep test.py test', output('test'), 'grep test test.py'),
('grep -lir . test', output('test'), 'grep -lir test .'),
('grep . test -lir', output('test'), 'grep test -lir .'),
('egrep test.py test', output('test'), 'egrep test test.py'),
('egrep -lir . test', output('test'), 'egrep -lir test .'),
('egrep . test -lir', output('test'), 'egrep test -lir .')])
def test_get_new_command(script, output, result):
assert get_new_command(Command(script, output)) == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_mercurial.py | tests/rules/test_mercurial.py | import pytest
from thefuck.types import Command
from thefuck.rules.mercurial import (
extract_possibilities, match, get_new_command
)
@pytest.mark.parametrize('command', [
Command('hg base', (
"hg: unknown command 'base'"
'\n(did you mean one of blame, phase, rebase?)'
)),
Command('hg branchch', (
"hg: unknown command 'branchch'"
'\n(did you mean one of branch, branches?)'
)),
Command('hg vert', (
"hg: unknown command 'vert'"
'\n(did you mean one of revert?)'
)),
Command('hg lgo -r tip', (
"hg: command 're' is ambiguous:"
'\n(did you mean one of log?)'
)),
Command('hg rerere', (
"hg: unknown command 'rerere'"
'\n(did you mean one of revert?)'
)),
Command('hg re', (
"hg: command 're' is ambiguous:"
'\n rebase recover remove rename resolve revert'
)),
Command('hg re re', (
"hg: command 're' is ambiguous:"
'\n rebase recover remove rename resolve revert'
)),
])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('hg', (
'\nMercurial Distributed SCM\n\nbasic commands:'
)),
Command('hg asdf', (
"hg: unknown command 'asdf'"
'\nMercurial Distributed SCM\n\nbasic commands:'
)),
Command('hg qwer', (
"hg: unknown command 'qwer'"
'\nMercurial Distributed SCM\n\nbasic commands:'
)),
Command('hg me', (
"\nabort: no repository found in './thefuck' (.hg not found)!"
)),
Command('hg reb', (
"\nabort: no repository found in './thefuck' (.hg not found)!"
)),
Command('hg co', (
"\nabort: no repository found in './thefuck' (.hg not found)!"
)),
])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, possibilities', [
(Command('hg base', (
"hg: unknown command 'base'"
'\n(did you mean one of blame, phase, rebase?)'
)), ['blame', 'phase', 'rebase']),
(Command('hg branchch', (
"hg: unknown command 'branchch'"
'\n(did you mean one of branch, branches?)'
)), ['branch', 'branches']),
(Command('hg vert', (
"hg: unknown command 'vert'"
'\n(did you mean one of revert?)'
)), ['revert']),
(Command('hg lgo -r tip', (
"hg: command 're' is ambiguous:"
'\n(did you mean one of log?)'
)), ['log']),
(Command('hg rerere', (
"hg: unknown command 'rerere'"
'\n(did you mean one of revert?)'
)), ['revert']),
(Command('hg re', (
"hg: command 're' is ambiguous:"
'\n rebase recover remove rename resolve revert'
)), ['rebase', 'recover', 'remove', 'rename', 'resolve', 'revert']),
(Command('hg re re', (
"hg: command 're' is ambiguous:"
'\n rebase recover remove rename resolve revert'
)), ['rebase', 'recover', 'remove', 'rename', 'resolve', 'revert']),
])
def test_extract_possibilities(command, possibilities):
assert extract_possibilities(command) == possibilities
@pytest.mark.parametrize('command, new_command', [
(Command('hg base', (
"hg: unknown command 'base'"
'\n(did you mean one of blame, phase, rebase?)'
)), 'hg rebase'),
(Command('hg branchch', (
"hg: unknown command 'branchch'"
'\n(did you mean one of branch, branches?)'
)), 'hg branch'),
(Command('hg vert', (
"hg: unknown command 'vert'"
'\n(did you mean one of revert?)'
)), 'hg revert'),
(Command('hg lgo -r tip', (
"hg: command 're' is ambiguous:"
'\n(did you mean one of log?)'
)), 'hg log -r tip'),
(Command('hg rerere', (
"hg: unknown command 'rerere'"
'\n(did you mean one of revert?)'
)), 'hg revert'),
(Command('hg re', (
"hg: command 're' is ambiguous:"
'\n rebase recover remove rename resolve revert'
)), 'hg rebase'),
(Command('hg re re', (
"hg: command 're' is ambiguous:"
'\n rebase recover remove rename resolve revert'
)), 'hg rebase re'),
])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_omnienv_no_such_command.py | tests/rules/test_omnienv_no_such_command.py | import pytest
from thefuck.rules.omnienv_no_such_command import get_new_command, match
from thefuck.types import Command
@pytest.fixture
def output(pyenv_cmd):
return "pyenv: no such command `{}'".format(pyenv_cmd)
@pytest.fixture(autouse=True)
def Popen(mocker):
mock = mocker.patch('thefuck.rules.omnienv_no_such_command.Popen')
mock.return_value.stdout.readlines.return_value = (
b'--version\nactivate\ncommands\ncompletions\ndeactivate\nexec_\n'
b'global\nhelp\nhooks\ninit\ninstall\nlocal\nprefix_\n'
b'realpath.dylib\nrehash\nroot\nshell\nshims\nuninstall\nversion_\n'
b'version-file\nversion-file-read\nversion-file-write\nversion-name_\n'
b'version-origin\nversions\nvirtualenv\nvirtualenv-delete_\n'
b'virtualenv-init\nvirtualenv-prefix\nvirtualenvs_\n'
b'virtualenvwrapper\nvirtualenvwrapper_lazy\nwhence\nwhich_\n'
).split()
return mock
@pytest.mark.parametrize('script, pyenv_cmd', [
('pyenv globe', 'globe'),
('pyenv intall 3.8.0', 'intall'),
('pyenv list', 'list'),
])
def test_match(script, pyenv_cmd, output):
assert match(Command(script, output=output))
def test_match_goenv_output_quote():
"""test goenv's specific output with quotes (')"""
assert match(Command('goenv list', output="goenv: no such command 'list'"))
@pytest.mark.parametrize('script, output', [
('pyenv global', 'system'),
('pyenv versions', ' 3.7.0\n 3.7.1\n* 3.7.2\n'),
('pyenv install --list', ' 3.7.0\n 3.7.1\n 3.7.2\n'),
])
def test_not_match(script, output):
assert not match(Command(script, output=output))
@pytest.mark.parametrize('script, pyenv_cmd, result', [
('pyenv globe', 'globe', 'pyenv global'),
('pyenv intall 3.8.0', 'intall', 'pyenv install 3.8.0'),
('pyenv list', 'list', 'pyenv install --list'),
('pyenv remove 3.8.0', 'remove', 'pyenv uninstall 3.8.0'),
])
def test_get_new_command(script, pyenv_cmd, output, result):
assert result in get_new_command(Command(script, output))
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_push_pull.py | tests/rules/test_git_push_pull.py | import pytest
from thefuck.rules.git_push_pull import match, get_new_command
from thefuck.types import Command
git_err = '''
To /tmp/foo
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '/tmp/bar'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
'''
git_err2 = '''
To /tmp/foo
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '/tmp/bar'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
'''
git_uptodate = 'Everything up-to-date'
git_ok = '''
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 282 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /tmp/bar
514eed3..f269c79 master -> master
'''
@pytest.mark.parametrize('command', [
Command('git push', git_err),
Command('git push nvbn', git_err),
Command('git push nvbn master', git_err),
Command('git push', git_err2),
Command('git push nvbn', git_err2),
Command('git push nvbn master', git_err2)])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('git push', git_ok),
Command('git push', git_uptodate),
Command('git push nvbn', git_ok),
Command('git push nvbn master', git_uptodate),
Command('git push nvbn', git_ok),
Command('git push nvbn master', git_uptodate)])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, output', [
(Command('git push', git_err), 'git pull && git push'),
(Command('git push nvbn', git_err),
'git pull nvbn && git push nvbn'),
(Command('git push nvbn master', git_err),
'git pull nvbn master && git push nvbn master'),
(Command('git push', git_err2), 'git pull && git push'),
(Command('git push nvbn', git_err2),
'git pull nvbn && git push nvbn'),
(Command('git push nvbn master', git_err2),
'git pull nvbn master && git push nvbn master')])
def test_get_new_command(command, output):
assert get_new_command(command) == output
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_adb_unknown_command.py | tests/rules/test_adb_unknown_command.py | import pytest
from thefuck.rules.adb_unknown_command import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def output():
return '''Android Debug Bridge version 1.0.31
-d - directs command to the only connected USB device
returns an error if more than one USB device is present.
-e - directs command to the only running emulator.
returns an error if more than one emulator is running.
-s <specific device> - directs command to the device or emulator with the given
serial number or qualifier. Overrides ANDROID_SERIAL
environment variable.
'''
@pytest.mark.parametrize('script', [
('adb lgcat'),
('adb puhs')])
def test_match(output, script):
assert match(Command(script, output))
@pytest.mark.parametrize('script', [
'git branch foo',
'abd push'])
def test_not_match(script):
assert not match(Command(script, ''))
@pytest.mark.parametrize('script, new_command', [
('adb puhs test.bin /sdcard/test.bin', 'adb push test.bin /sdcard/test.bin'),
('adb -s 1111 logcta', 'adb -s 1111 logcat'),
('adb -P 666 pulll /sdcard/test.bin', 'adb -P 666 pull /sdcard/test.bin'),
('adb -d logcatt', 'adb -d logcat'),
('adb -e reboott', 'adb -e reboot')])
def test_get_new_command(script, output, new_command):
assert get_new_command(Command(script, output)) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_no_such_file.py | tests/rules/test_no_such_file.py | import pytest
from thefuck.rules.no_such_file import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('command', [
Command('mv foo bar/foo', "mv: cannot move 'foo' to 'bar/foo': No such file or directory"),
Command('mv foo bar/', "mv: cannot move 'foo' to 'bar/': No such file or directory"),
])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('mv foo bar/', ""),
Command('mv foo bar/foo', "mv: permission denied"),
])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('mv foo bar/foo', "mv: cannot move 'foo' to 'bar/foo': No such file or directory"), 'mkdir -p bar && mv foo bar/foo'),
(Command('mv foo bar/', "mv: cannot move 'foo' to 'bar/': No such file or directory"), 'mkdir -p bar && mv foo bar/'),
])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_systemctl.py | tests/rules/test_systemctl.py | from thefuck.rules.systemctl import match, get_new_command
from thefuck.types import Command
def test_match():
assert match(Command('systemctl nginx start', 'Unknown operation \'nginx\'.'))
assert match(Command('sudo systemctl nginx start', 'Unknown operation \'nginx\'.'))
assert not match(Command('systemctl start nginx', ''))
assert not match(Command('systemctl start nginx', ''))
assert not match(Command('sudo systemctl nginx', 'Unknown operation \'nginx\'.'))
assert not match(Command('systemctl nginx', 'Unknown operation \'nginx\'.'))
assert not match(Command('systemctl start wtf', 'Failed to start wtf.service: Unit wtf.service failed to load: No such file or directory.'))
def test_get_new_command():
assert get_new_command(Command('systemctl nginx start', '')) == "systemctl start nginx"
assert get_new_command(Command('sudo systemctl nginx start', '')) == "sudo systemctl start nginx"
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_docker_not_command.py | tests/rules/test_docker_not_command.py | import pytest
from io import BytesIO
from thefuck.types import Command
from thefuck.rules.docker_not_command import get_new_command, match
_DOCKER_SWARM_OUTPUT = '''
Usage: docker swarm COMMAND
Manage Swarm
Commands:
ca Display and rotate the root CA
init Initialize a swarm
join Join a swarm as a node and/or manager
join-token Manage join tokens
leave Leave the swarm
unlock Unlock swarm
unlock-key Manage the unlock key
update Update the swarm
Run 'docker swarm COMMAND --help' for more information on a command.
'''
_DOCKER_IMAGE_OUTPUT = '''
Usage: docker image COMMAND
Manage images
Commands:
build Build an image from a Dockerfile
history Show the history of an image
import Import the contents from a tarball to create a filesystem image
inspect Display detailed information on one or more images
load Load an image from a tar archive or STDIN
ls List images
prune Remove unused images
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rm Remove one or more images
save Save one or more images to a tar archive (streamed to STDOUT by default)
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
Run 'docker image COMMAND --help' for more information on a command.
'''
@pytest.fixture
def docker_help(mocker):
help = b'''Usage: docker [OPTIONS] COMMAND [arg...]
A self-sufficient runtime for linux containers.
Options:
--api-cors-header= Set CORS headers in the remote API
-b, --bridge= Attach containers to a network bridge
--bip= Specify network bridge IP
-D, --debug=false Enable debug mode
-d, --daemon=false Enable daemon mode
--default-gateway= Container default gateway IPv4 address
--default-gateway-v6= Container default gateway IPv6 address
--default-ulimit=[] Set default ulimits for containers
--dns=[] DNS server to use
--dns-search=[] DNS search domains to use
-e, --exec-driver=native Exec driver to use
--exec-opt=[] Set exec driver options
--exec-root=/var/run/docker Root of the Docker execdriver
--fixed-cidr= IPv4 subnet for fixed IPs
--fixed-cidr-v6= IPv6 subnet for fixed IPs
-G, --group=docker Group for the unix socket
-g, --graph=/var/lib/docker Root of the Docker runtime
-H, --host=[] Daemon socket(s) to connect to
-h, --help=false Print usage
--icc=true Enable inter-container communication
--insecure-registry=[] Enable insecure registry communication
--ip=0.0.0.0 Default IP when binding container ports
--ip-forward=true Enable net.ipv4.ip_forward
--ip-masq=true Enable IP masquerading
--iptables=true Enable addition of iptables rules
--ipv6=false Enable IPv6 networking
-l, --log-level=info Set the logging level
--label=[] Set key=value labels to the daemon
--log-driver=json-file Default driver for container logs
--log-opt=map[] Set log driver options
--mtu=0 Set the containers network MTU
-p, --pidfile=/var/run/docker.pid Path to use for daemon PID file
--registry-mirror=[] Preferred Docker registry mirror
-s, --storage-driver= Storage driver to use
--selinux-enabled=false Enable selinux support
--storage-opt=[] Set storage driver options
--tls=false Use TLS; implied by --tlsverify
--tlscacert=~/.docker/ca.pem Trust certs signed only by this CA
--tlscert=~/.docker/cert.pem Path to TLS certificate file
--tlskey=~/.docker/key.pem Path to TLS key file
--tlsverify=false Use TLS and verify the remote
--userland-proxy=true Use userland proxy for loopback traffic
-v, --version=false Print version information and quit
Commands:
attach Attach to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders from a container's filesystem to the host path
create Create a new container
diff Inspect changes on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Stream the contents of a container as a tar archive
history Show the history of an image
images List images
import Create a new filesystem image from the contents of a tarball
info Display system-wide information
inspect Return low-level information on a container or image
kill Kill a running container
load Load an image from a tar archive
login Register or log in to a Docker registry server
logout Log out from a Docker registry server
logs Fetch the logs of a container
pause Pause all processes within a container
port Lookup the public-facing port that is NAT-ed to PRIVATE_PORT
ps List containers
pull Pull an image or a repository from a Docker registry server
push Push an image or a repository to a Docker registry server
rename Rename an existing container
restart Restart a running container
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save an image to a tar archive
search Search for an image on the Docker Hub
start Start a stopped container
stats Display a stream of a containers' resource usage statistics
stop Stop a running container
tag Tag an image into a repository
top Lookup the running processes of a container
unpause Unpause a paused container
version Show the Docker version information
wait Block until a container stops, then print its exit code
Run 'docker COMMAND --help' for more information on a command.
'''
mock = mocker.patch('subprocess.Popen')
mock.return_value.stdout = BytesIO(help)
return mock
@pytest.fixture
def docker_help_new(mocker):
helptext_new = b'''
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/Users/ik1ne/.docker")
-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var
and default context set with "docker context use")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/Users/ik1ne/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/Users/ik1ne/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/Users/ik1ne/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
builder Manage builds
config Manage Docker configs
container Manage containers
context Manage contexts
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
Run 'docker COMMAND --help' for more information on a command.
'''
mock = mocker.patch('subprocess.Popen')
mock.return_value.stdout = BytesIO(b'')
mock.return_value.stderr = BytesIO(helptext_new)
return mock
def output(cmd):
return "docker: '{}' is not a docker command.\n" \
"See 'docker --help'.".format(cmd)
def test_match():
assert match(Command('docker pes', output('pes')))
# tests docker (management command)
@pytest.mark.usefixtures('no_memoize')
@pytest.mark.parametrize('script, output', [
('docker swarn', output('swarn')),
('docker imge', output('imge'))])
def test_match_management_cmd(script, output):
assert match(Command(script, output))
# tests docker (management cmd) (management subcmd)
@pytest.mark.usefixtures('no_memoize')
@pytest.mark.parametrize('script, output', [
('docker swarm int', _DOCKER_SWARM_OUTPUT),
('docker image la', _DOCKER_IMAGE_OUTPUT)])
def test_match_management_subcmd(script, output):
assert match(Command(script, output))
@pytest.mark.parametrize('script, output', [
('docker ps', ''),
('cat pes', output('pes'))])
def test_not_match(script, output):
assert not match(Command(script, output))
@pytest.mark.usefixtures('no_memoize', 'docker_help')
@pytest.mark.parametrize('wrong, fixed', [
('pes', ['ps', 'push', 'pause']),
('tags', ['tag', 'stats', 'images'])])
def test_get_new_command(wrong, fixed):
command = Command('docker {}'.format(wrong), output(wrong))
assert get_new_command(command) == ['docker {}'.format(x) for x in fixed]
@pytest.mark.usefixtures('no_memoize', 'docker_help_new')
@pytest.mark.parametrize('wrong, fixed', [
('swarn', ['swarm', 'start', 'search']),
('inage', ['image', 'images', 'rename'])])
def test_get_new_management_command(wrong, fixed):
command = Command('docker {}'.format(wrong), output(wrong))
assert get_new_command(command) == ['docker {}'.format(x) for x in fixed]
@pytest.mark.usefixtures('no_memoize', 'docker_help_new')
@pytest.mark.parametrize('wrong, fixed, output', [
('swarm int', ['swarm init', 'swarm join', 'swarm join-token'], _DOCKER_SWARM_OUTPUT),
('image la', ['image load', 'image ls', 'image tag'], _DOCKER_IMAGE_OUTPUT)])
def test_get_new_management_command_subcommand(wrong, fixed, output):
command = Command('docker {}'.format(wrong), output)
assert get_new_command(command) == ['docker {}'.format(x) for x in fixed]
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_apt_list_upgradable.py | tests/rules/test_apt_list_upgradable.py | # -*- coding: utf-8 -*-
import pytest
from thefuck.rules.apt_list_upgradable import get_new_command, match
from thefuck.types import Command
full_english_output = '''
Hit:1 http://us.archive.ubuntu.com/ubuntu zesty InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu zesty-updates InRelease
Get:3 http://us.archive.ubuntu.com/ubuntu zesty-backports InRelease [89.2 kB]
Hit:4 http://security.ubuntu.com/ubuntu zesty-security InRelease
Hit:5 http://ppa.launchpad.net/ubuntu-mozilla-daily/ppa/ubuntu zesty InRelease
Hit:6 https://download.docker.com/linux/ubuntu zesty InRelease
Hit:7 https://cli-assets.heroku.com/branches/stable/apt ./ InRelease
Fetched 89.2 kB in 0s (122 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
8 packages can be upgraded. Run 'apt list --upgradable' to see them.
'''
match_output = [
full_english_output,
'Führen Sie »apt list --upgradable« aus, um sie anzuzeigen.' # German
]
no_match_output = '''
Hit:1 http://us.archive.ubuntu.com/ubuntu zesty InRelease
Get:2 http://us.archive.ubuntu.com/ubuntu zesty-updates InRelease [89.2 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu zesty-backports InRelease [89.2 kB]
Get:4 http://security.ubuntu.com/ubuntu zesty-security InRelease [89.2 kB]
Hit:5 https://cli-assets.heroku.com/branches/stable/apt ./ InRelease
Hit:6 http://ppa.launchpad.net/ubuntu-mozilla-daily/ppa/ubuntu zesty InRelease
Hit:7 https://download.docker.com/linux/ubuntu zesty InRelease
Get:8 http://us.archive.ubuntu.com/ubuntu zesty-updates/main i386 Packages [232 kB]
Get:9 http://us.archive.ubuntu.com/ubuntu zesty-updates/main amd64 Packages [235 kB]
Get:10 http://us.archive.ubuntu.com/ubuntu zesty-updates/main amd64 DEP-11 Metadata [55.2 kB]
Get:11 http://us.archive.ubuntu.com/ubuntu zesty-updates/main DEP-11 64x64 Icons [32.3 kB]
Get:12 http://us.archive.ubuntu.com/ubuntu zesty-updates/universe amd64 Packages [156 kB]
Get:13 http://us.archive.ubuntu.com/ubuntu zesty-updates/universe i386 Packages [156 kB]
Get:14 http://us.archive.ubuntu.com/ubuntu zesty-updates/universe amd64 DEP-11 Metadata [175 kB]
Get:15 http://us.archive.ubuntu.com/ubuntu zesty-updates/universe DEP-11 64x64 Icons [253 kB]
Get:16 http://us.archive.ubuntu.com/ubuntu zesty-updates/multiverse amd64 DEP-11 Metadata [5,840 B]
Get:17 http://us.archive.ubuntu.com/ubuntu zesty-backports/universe amd64 DEP-11 Metadata [4,588 B]
Get:18 http://security.ubuntu.com/ubuntu zesty-security/main amd64 DEP-11 Metadata [12.7 kB]
Get:19 http://security.ubuntu.com/ubuntu zesty-security/main DEP-11 64x64 Icons [17.6 kB]
Get:20 http://security.ubuntu.com/ubuntu zesty-security/universe amd64 DEP-11 Metadata [21.6 kB]
Get:21 http://security.ubuntu.com/ubuntu zesty-security/universe DEP-11 64x64 Icons [47.7 kB]
Get:22 http://security.ubuntu.com/ubuntu zesty-security/multiverse amd64 DEP-11 Metadata [208 B]
Fetched 1,673 kB in 0s (1,716 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
'''
@pytest.mark.parametrize('output', match_output)
def test_match(output):
assert match(Command('sudo apt update', output))
@pytest.mark.parametrize('command', [
Command('apt-cache search foo', ''),
Command('aptitude search foo', ''),
Command('apt search foo', ''),
Command('apt-get install foo', ''),
Command('apt-get source foo', ''),
Command('apt-get clean', ''),
Command('apt-get remove', ''),
Command('apt-get update', ''),
Command('sudo apt update', no_match_output)
])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('output', match_output)
def test_get_new_command(output):
new_command = get_new_command(Command('sudo apt update', output))
assert new_command == 'sudo apt list --upgradable'
new_command = get_new_command(Command('apt update', output))
assert new_command == 'apt list --upgradable'
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_tmux.py | tests/rules/test_tmux.py | import pytest
from thefuck.rules.tmux import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def tmux_ambiguous():
return "ambiguous command: list, could be: " \
"list-buffers, list-clients, list-commands, list-keys, " \
"list-panes, list-sessions, list-windows"
def test_match(tmux_ambiguous):
assert match(Command('tmux list', tmux_ambiguous))
def test_get_new_command(tmux_ambiguous):
assert get_new_command(Command('tmux list', tmux_ambiguous))\
== ['tmux list-keys', 'tmux list-panes', 'tmux list-windows']
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_ifconfig_device_not_found.py | tests/rules/test_ifconfig_device_not_found.py | import pytest
from six import BytesIO
from thefuck.rules.ifconfig_device_not_found import match, get_new_command
from thefuck.types import Command
output = '{}: error fetching interface information: Device not found'
stdout = b'''
wlp2s0 Link encap:Ethernet HWaddr 5c:51:4f:7c:58:5d
inet addr:192.168.0.103 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::be23:69b9:96d2:6d39/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:23581604 errors:0 dropped:0 overruns:0 frame:0
TX packets:17017655 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:16148429061 (16.1 GB) TX bytes:7067533695 (7.0 GB)
'''
@pytest.fixture(autouse=True)
def ifconfig(mocker):
mock = mocker.patch(
'thefuck.rules.ifconfig_device_not_found.subprocess.Popen')
mock.return_value.stdout = BytesIO(stdout)
return mock
@pytest.mark.parametrize('script, output', [
('ifconfig wlan0', output.format('wlan0')),
('ifconfig -s eth0', output.format('eth0')),
])
def test_match(script, output):
assert match(Command(script, output))
@pytest.mark.parametrize('script, output', [
('config wlan0',
'wlan0: error fetching interface information: Device not found'),
('ifconfig eth0', ''),
])
def test_not_match(script, output):
assert not match(Command(script, output))
@pytest.mark.parametrize('script, result', [
('ifconfig wlan0', ['ifconfig wlp2s0']),
('ifconfig -s wlan0', ['ifconfig -s wlp2s0']),
])
def test_get_new_comman(script, result):
new_command = get_new_command(
Command(script, output.format('wlan0')))
assert new_command == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_az_cli.py | tests/rules/test_az_cli.py | import pytest
from thefuck.rules.az_cli import match, get_new_command
from thefuck.types import Command
no_suggestions = '''\
az provider: error: the following arguments are required: _subcommand
usage: az provider [-h] {list,show,register,unregister,operation} ...
'''
misspelled_command = '''\
az: 'providers' is not in the 'az' command group. See 'az --help'.
The most similar choice to 'providers' is:
provider
'''
misspelled_subcommand = '''\
az provider: 'lis' is not in the 'az provider' command group. See 'az provider --help'.
The most similar choice to 'lis' is:
list
'''
@pytest.mark.parametrize('command', [
Command('az providers', misspelled_command),
Command('az provider lis', misspelled_subcommand)])
def test_match(command):
assert match(command)
def test_not_match():
assert not match(Command('az provider', no_suggestions))
@pytest.mark.parametrize('command, result', [
(Command('az providers list', misspelled_command), ['az provider list']),
(Command('az provider lis', misspelled_subcommand), ['az provider list'])
])
def test_get_new_command(command, result):
assert get_new_command(command) == result
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_docker_image_being_used_by_container.py | tests/rules/test_docker_image_being_used_by_container.py | from thefuck.rules.docker_image_being_used_by_container import match, get_new_command
from thefuck.types import Command
def test_match():
err_response = """Error response from daemon: conflict: unable to delete cd809b04b6ff (cannot be forced) - image is being used by running container e5e2591040d1"""
assert match(Command('docker image rm -f cd809b04b6ff', err_response))
def test_not_match():
err_response = 'bash: docker: command not found'
assert not match(Command('docker image rm -f cd809b04b6ff', err_response))
def test_not_docker_command():
err_response = """Error response from daemon: conflict: unable to delete cd809b04b6ff (cannot be forced) - image is being used by running container e5e2591040d1"""
assert not match(Command('git image rm -f cd809b04b6ff', err_response))
def test_get_new_command():
err_response = """
Error response from daemon: conflict: unable to delete cd809b04b6ff (cannot be forced) - image
is being used by running container e5e2591040d1
"""
result = get_new_command(Command('docker image rm -f cd809b04b6ff', err_response))
expected = 'docker container rm -f e5e2591040d1 && docker image rm -f cd809b04b6ff'
assert result == expected
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_tsuru_login.py | tests/rules/test_tsuru_login.py | import pytest
from thefuck.rules.tsuru_login import match, get_new_command
from thefuck.types import Command
error_msg = (
"Error: you're not authenticated or your session has expired.",
("You're not authenticated or your session has expired. "
"Please use \"login\" command for authentication."),
)
@pytest.mark.parametrize('command', [
Command('tsuru app-shell', error_msg[0]),
Command('tsuru app-log -f', error_msg[1]),
])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('tsuru', ''),
Command('tsuru app-restart', 'Error: unauthorized'),
Command('tsuru app-log -f', 'Error: unparseable data'),
])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('tsuru app-shell', error_msg[0]),
'tsuru login && tsuru app-shell'),
(Command('tsuru app-log -f', error_msg[1]),
'tsuru login && tsuru app-log -f'),
])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_rm_recursive.py | tests/rules/test_git_rm_recursive.py | import pytest
from thefuck.rules.git_rm_recursive import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def output(target):
return "fatal: not removing '{}' recursively without -r".format(target)
@pytest.mark.parametrize('script, target', [
('git rm foo', 'foo'),
('git rm foo bar', 'foo bar')])
def test_match(output, script, target):
assert match(Command(script, output))
@pytest.mark.parametrize('script', ['git rm foo', 'git rm foo bar'])
def test_not_match(script):
assert not match(Command(script, ''))
@pytest.mark.parametrize('script, target, new_command', [
('git rm foo', 'foo', 'git rm -r foo'),
('git rm foo bar', 'foo bar', 'git rm -r foo bar')])
def test_get_new_command(output, script, target, new_command):
assert get_new_command(Command(script, output)) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_cp_create_destination.py | tests/rules/test_cp_create_destination.py | import pytest
from thefuck.rules.cp_create_destination import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize(
"script, output",
[("cp", "cp: directory foo does not exist\n"), ("mv", "No such file or directory")],
)
def test_match(script, output):
assert match(Command(script, output))
@pytest.mark.parametrize(
"script, output", [("cp", ""), ("mv", ""), ("ls", "No such file or directory")]
)
def test_not_match(script, output):
assert not match(Command(script, output))
@pytest.mark.parametrize(
"script, output, new_command",
[
("cp foo bar/", "cp: directory foo does not exist\n", "mkdir -p bar/ && cp foo bar/"),
("mv foo bar/", "No such file or directory", "mkdir -p bar/ && mv foo bar/"),
("cp foo bar/baz/", "cp: directory foo does not exist\n", "mkdir -p bar/baz/ && cp foo bar/baz/"),
],
)
def test_get_new_command(script, output, new_command):
assert get_new_command(Command(script, output)) == new_command
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_git_push_force.py | tests/rules/test_git_push_force.py | import pytest
from thefuck.rules.git_push_force import match, get_new_command
from thefuck.types import Command
git_err = '''
To /tmp/foo
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '/tmp/bar'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
'''
git_uptodate = 'Everything up-to-date'
git_ok = '''
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 282 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /tmp/bar
514eed3..f269c79 master -> master
'''
@pytest.mark.parametrize('command', [
Command('git push', git_err),
Command('git push nvbn', git_err),
Command('git push nvbn master', git_err)])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('git push', git_ok),
Command('git push', git_uptodate),
Command('git push nvbn', git_ok),
Command('git push nvbn master', git_uptodate),
Command('git push nvbn', git_ok),
Command('git push nvbn master', git_uptodate)])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, output', [
(Command('git push', git_err), 'git push --force-with-lease'),
(Command('git push nvbn', git_err), 'git push --force-with-lease nvbn'),
(Command('git push nvbn master', git_err), 'git push --force-with-lease nvbn master')])
def test_get_new_command(command, output):
assert get_new_command(command) == output
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
nvbn/thefuck | https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/tests/rules/test_go_unknown_command.py | tests/rules/test_go_unknown_command.py | import pytest
from io import BytesIO
from thefuck.rules.go_unknown_command import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def build_misspelled_output():
return '''go bulid: unknown command
Run 'go help' for usage.'''
@pytest.fixture
def go_stderr(mocker):
stderr = b'''Go is a tool for managing Go source code.
Usage:
\tgo <command> [arguments]
The commands are:
\tbug start a bug report
\tbuild compile packages and dependencies
\tclean remove object files and cached files
\tdoc show documentation for package or symbol
\tenv print Go environment information
\tfix update packages to use new APIs
\tfmt gofmt (reformat) package sources
\tgenerate generate Go files by processing source
\tget add dependencies to current module and install them
\tinstall compile and install packages and dependencies
\tlist list packages or modules
\tmod module maintenance
\trun compile and run Go program
\ttest test packages
\ttool run specified go tool
\tversion print Go version
\tvet report likely mistakes in packages
Use "go help <command>" for more information about a command.
Additional help topics:
\tbuildconstraint build constraints
\tbuildmode build modes
\tc calling between Go and C
\tcache build and test caching
\tenvironment environment variables
\tfiletype file types
\tgo.mod the go.mod file
\tgopath GOPATH environment variable
\tgopath-get legacy GOPATH go get
\tgoproxy module proxy protocol
\timportpath import path syntax
\tmodules modules, module versions, and more
\tmodule-get module-aware go get
\tmodule-auth module authentication using go.sum
\tmodule-private module configuration for non-public modules
\tpackages package lists and patterns
\ttestflag testing flags
\ttestfunc testing functions
Use "go help <topic>" for more information about that topic.
'''
mock = mocker.patch('subprocess.Popen')
mock.return_value.stderr = BytesIO(stderr)
return mock
def test_match(build_misspelled_output):
assert match(Command('go bulid', build_misspelled_output))
def test_not_match():
assert not match(Command('go run', 'go run: no go files listed'))
@pytest.mark.usefixtures('no_memoize', 'go_stderr')
def test_get_new_command(build_misspelled_output):
assert get_new_command(Command('go bulid', build_misspelled_output)) == 'go build'
| python | MIT | c7e7e1d884d3bb241ea6448f72a989434c2a35ec | 2026-01-04T14:38:15.457096Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.