1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-10-30 22:54:14 +00:00

Merge branch 'flake8' of https://github.com/josephfrazier/thefuck into josephfrazier-flake8

# Conflicts:
#	thefuck/system/unix.py
#	thefuck/system/win32.py
This commit is contained in:
Vladimir Iakovlev
2017-03-13 13:35:11 +01:00
60 changed files with 172 additions and 173 deletions

View File

@@ -6,15 +6,15 @@ from thefuck.rules.brew_link import get_new_command, match
@pytest.fixture
def stderr():
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")
"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
@@ -29,7 +29,7 @@ def test_match(stderr, script):
@pytest.mark.parametrize('script', ['brew link coreutils'])
def test_not_match(script):
stderr=''
stderr = ''
assert not match(Command(script=script, stderr=stderr))

View File

@@ -22,7 +22,7 @@ def test_match(stdout, script):
@pytest.mark.parametrize('script', ['brew remove gnuplot'])
def test_not_match(script):
stdout='Uninstalling /usr/local/Cellar/gnuplot/5.0.4_1... (44 files, 2.3M)\n'
stdout = 'Uninstalling /usr/local/Cellar/gnuplot/5.0.4_1... (44 files, 2.3M)\n'
assert not match(Command(script=script, stdout=stdout))

View File

@@ -21,8 +21,8 @@ def test_match(brew_unknown_cmd):
def test_get_new_command(brew_unknown_cmd, brew_unknown_cmd2):
assert get_new_command(Command('brew inst', stderr=brew_unknown_cmd)) \
== ['brew list', 'brew install', 'brew uninstall']
assert (get_new_command(Command('brew inst', stderr=brew_unknown_cmd))
== ['brew list', 'brew install', 'brew uninstall'])
cmds = get_new_command(Command('brew instaa', stderr=brew_unknown_cmd2))
assert 'brew install' in cmds

View File

@@ -48,9 +48,9 @@ def test_match(composer_not_command, composer_not_command_one_of_this):
def test_get_new_command(composer_not_command, composer_not_command_one_of_this):
assert get_new_command(Command('composer udpate',
stderr=composer_not_command)) \
== 'composer update'
assert get_new_command(
Command('composer pdate', stderr=composer_not_command_one_of_this)) \
== 'composer selfupdate'
assert (get_new_command(Command('composer udpate',
stderr=composer_not_command))
== 'composer update')
assert (get_new_command(Command('composer pdate',
stderr=composer_not_command_one_of_this))
== 'composer selfupdate')

View File

@@ -2,7 +2,7 @@ import os
import pytest
import tarfile
from thefuck.rules.dirty_untar import match, get_new_command, side_effect, \
tar_extensions
tar_extensions # noqa: E126
from tests.utils import Command
@@ -33,6 +33,7 @@ def tar_error(tmpdir):
return fixture
parametrize_extensions = pytest.mark.parametrize('ext', tar_extensions)
# (filename as typed by the user, unquoted filename, quoted filename as per shells.quote)

View File

@@ -37,7 +37,7 @@ south.exceptions.GhostMigrations:
! 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(stderr):

View File

@@ -39,5 +39,5 @@ def test_match(stderr):
def test_get_new_command():
assert get_new_command(Command('./manage.py migrate auth')) \
== './manage.py migrate auth --merge'
assert (get_new_command(Command('./manage.py migrate auth'))
== './manage.py migrate auth --merge')

View File

@@ -45,5 +45,5 @@ def test_not_match(command):
'fab prepare_extension:version=2016 deploy:beta=true -H the.fuck'),
])
def test_get_new_command(script, result):
command = Command(script, stdout,stderr)
command = Command(script, stdout, stderr)
assert get_new_command(command) == result

View File

@@ -18,5 +18,5 @@ def test_match():
def test_get_new_command():
""" Replace the Alt+Space character by a simple space """
assert get_new_command(Command(u'ps -ef | grep foo'))\
== 'ps -ef | grep foo'
assert (get_new_command(Command(u'ps -ef | grep foo'))
== 'ps -ef | grep foo')

View File

@@ -191,7 +191,7 @@ E NameError: name 'mocker' is not defined
/home/thefuck/tests/rules/test_fix_file.py:218: NameError
""", ''),
)
) # noqa
@pytest.mark.parametrize('test', tests)
@@ -227,10 +227,6 @@ def test_get_new_command(mocker, monkeypatch, test):
mocker.patch('os.path.isfile', return_value=True)
monkeypatch.setenv('EDITOR', 'dummy_editor')
cmd = Command(script=test[0], stdout=test[4], stderr=test[5])
#assert (get_new_command(cmd, Settings({})) ==
# 'dummy_editor {} +{} && {}'.format(test[1], test[2], test[0]))
@pytest.mark.parametrize('test', tests)
@pytest.mark.usefixtures('no_memoize')
@@ -243,7 +239,7 @@ def test_get_new_command_with_settings(mocker, monkeypatch, test, settings):
if test[3]:
assert (get_new_command(cmd) ==
u'dummy_editor {} +{}:{} && {}'.format(test[1], test[2], test[3], test[0]))
u'dummy_editor {} +{}:{} && {}'.format(test[1], test[2], test[3], test[0]))
else:
assert (get_new_command(cmd) ==
u'dummy_editor {} +{} && {}'.format(test[1], test[2], test[0]))
u'dummy_editor {} +{} && {}'.format(test[1], test[2], test[0]))

View File

@@ -18,5 +18,5 @@ def test_match(stderr):
def test_get_new_command(stderr):
assert get_new_command(Command('git add dist/*.js', stderr=stderr)) \
== "git add --force dist/*.js"
assert (get_new_command(Command('git add dist/*.js', stderr=stderr))
== "git add --force dist/*.js")

View File

@@ -49,9 +49,9 @@ def test_match(git_not_command, git_command, git_not_command_one_of_this):
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', stderr=git_not_command)) \
== ['git branch']
assert get_new_command(Command('git st', stderr=git_not_command_one_of_this)) \
== ['git stats', 'git stash', 'git stage']
assert get_new_command(Command('git tags', stderr=git_not_command_closest)) \
== ['git tag', 'git stage']
assert (get_new_command(Command('git brnch', stderr=git_not_command))
== ['git branch'])
assert (get_new_command(Command('git st', stderr=git_not_command_one_of_this))
== ['git stats', 'git stash', 'git stage'])
assert (get_new_command(Command('git tags', stderr=git_not_command_closest))
== ['git tag', 'git stage'])

View File

@@ -25,5 +25,5 @@ def test_match(stderr):
def test_get_new_command(stderr):
assert get_new_command(Command('git pull', stderr=stderr)) \
== "git branch --set-upstream-to=origin/master master && git pull"
assert (get_new_command(Command('git pull', stderr=stderr))
== "git branch --set-upstream-to=origin/master master && git pull")

View File

@@ -15,5 +15,5 @@ def test_match(stderr):
def test_get_new_command(stderr):
assert get_new_command(Command('git pull', stderr=stderr)) \
== "git stash && git pull && git stash pop"
assert (get_new_command(Command('git pull', stderr=stderr))
== "git stash && git pull && git stash pop")

View File

@@ -15,5 +15,5 @@ def test_match(stderr):
def test_get_new_command(stderr):
assert get_new_command(Command('git pull', stderr=stderr)) \
== "git stash && git pull && git stash pop"
assert (get_new_command(Command('git pull', stderr=stderr))
== "git stash && git pull && git stash pop")

View File

@@ -39,12 +39,7 @@ To /tmp/bar
@pytest.mark.parametrize('command', [
Command(script='git push', stderr=git_err),
Command(script='git push nvbn', stderr=git_err),
Command(script='git push nvbn master', stderr=git_err)])
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command(script='git push nvbn master', stderr=git_err),
Command(script='git push', stderr=git_err2),
Command(script='git push nvbn', stderr=git_err2),
Command(script='git push nvbn master', stderr=git_err2)])
@@ -68,12 +63,7 @@ def test_not_match(command):
(Command(script='git push nvbn', stderr=git_err),
'git pull nvbn && git push nvbn'),
(Command(script='git push nvbn master', stderr=git_err),
'git pull nvbn master && git push nvbn master')])
def test_get_new_command(command, output):
assert get_new_command(command) == output
@pytest.mark.parametrize('command, output', [
'git pull nvbn master && git push nvbn master'),
(Command(script='git push', stderr=git_err2), 'git pull && git push'),
(Command(script='git push nvbn', stderr=git_err2),
'git pull nvbn && git push nvbn'),

View File

@@ -14,11 +14,11 @@ def test_match(command):
Command('git remote add origin url'),
Command('git remote remove origin'),
Command('git remote prune origin'),
Command('git remote set-branches origin branch')
])
Command('git remote set-branches origin branch')])
def test_not_match(command):
assert not match(command)
@pytest.mark.parametrize('command, new_command', [
(Command('git remote set-url origin git@github.com:nvbn/thefuck.git'),
'git remote add origin git@github.com:nvbn/thefuck.git')])

View File

@@ -4,14 +4,14 @@ from tests.utils import Command
cherry_pick_error = (
'error: Your local changes would be overwritten by cherry-pick.\n'
'hint: Commit your changes or stash them to proceed.\n'
'fatal: cherry-pick failed')
'error: Your local changes would be overwritten by cherry-pick.\n'
'hint: Commit your changes or stash them to proceed.\n'
'fatal: cherry-pick failed')
rebase_error = (
'Cannot rebase: Your index contains uncommitted changes.\n'
'Please commit or stash them.')
'Cannot rebase: Your index contains uncommitted changes.\n'
'Please commit or stash them.')
@pytest.mark.parametrize('command', [

View File

@@ -14,5 +14,5 @@ def test_match(stderr):
def test_get_new_command(stderr):
assert get_new_command(Command('git stash pop', stderr=stderr)) \
== "git add . && git stash pop && git reset ."
assert (get_new_command(Command('git stash pop', stderr=stderr))
== "git add . && git stash pop && git reset .")

View File

@@ -14,5 +14,5 @@ def test_match(stderr):
def test_get_new_command(stderr):
assert get_new_command(Command('git tag alert', stderr=stderr)) \
== "git tag --force alert"
assert (get_new_command(Command('git tag alert', stderr=stderr))
== "git tag --force alert")

View File

@@ -7,7 +7,7 @@ def test_match():
with patch('os.path.exists', return_value=True):
assert match(Command(script='main', stderr='main: command not found'))
assert match(Command(script='main --help',
stderr='main: command not found'))
stderr='main: command not found'))
assert not match(Command(script='main', stderr=''))
with patch('os.path.exists', return_value=False):

View File

@@ -19,5 +19,5 @@ def test_match(is_not_task):
def test_get_new_command(is_not_task):
assert get_new_command(Command(script='lein rpl --help', stderr=is_not_task)) \
== ['lein repl --help', 'lein jar --help']
assert (get_new_command(Command(script='lein rpl --help', stderr=is_not_task))
== ['lein repl --help', 'lein jar --help'])

View File

@@ -11,16 +11,6 @@ def file_exists(mocker):
get_stderr = "ln: failed to create symbolic link '{}': File exists".format
@pytest.mark.usefixtures('file_exists')
@pytest.mark.parametrize('script', [
'ln -s dest source',
'ln dest -s source',
'ln dest source -s'])
def test_match(script):
stderr = get_stderr('source')
assert match(Command(script, stderr=stderr))
@pytest.mark.parametrize('script, stderr, exists', [
('ln dest source', get_stderr('source'), True),
('ls -s dest source', get_stderr('source'), True),
@@ -38,4 +28,5 @@ def test_not_match(file_exists, script, stderr, exists):
('ln dest source -s', 'ln source -s dest')])
def test_match(script, result):
stderr = get_stderr('source')
assert match(Command(script, stderr=stderr))
assert get_new_command(Command(script, stderr=stderr)) == result

View File

@@ -25,7 +25,7 @@ def test_match(command):
[INFO] Finished at: Wed Aug 26 13:05:47 BST 2015
[INFO] Final Memory: 6M/240M
[INFO] ------------------------------------------------------------------------
"""),
"""), # noqa
Command(script='mvn --help'),
Command(script='mvn -v')
])

View File

@@ -25,7 +25,7 @@ def test_match(command):
[INFO] Finished at: Wed Aug 26 13:05:47 BST 2015
[INFO] Final Memory: 6M/240M
[INFO] ------------------------------------------------------------------------
"""),
"""), # noqa
Command(script='mvn --help'),
Command(script='mvn -v')
])

View File

@@ -8,5 +8,5 @@ def test_match():
def test_get_new_command():
assert get_new_command(Command('./test_sudo.py'))\
== 'python ./test_sudo.py'
assert (get_new_command(Command('./test_sudo.py'))
== 'python ./test_sudo.py')

View File

@@ -17,5 +17,5 @@ def test_not_match(command):
def test_get_new_command():
assert get_new_command(Command(script='rm -rf /')) \
== 'rm -rf / --no-preserve-root'
assert (get_new_command(Command(script='rm -rf /'))
== 'rm -rf / --no-preserve-root')

View File

@@ -18,11 +18,11 @@ def test_match(sed_unterminated_s):
def test_get_new_command(sed_unterminated_s):
assert get_new_command(Command('sed -e s/foo/bar', stderr=sed_unterminated_s)) \
== 'sed -e s/foo/bar/'
assert get_new_command(Command('sed -es/foo/bar', stderr=sed_unterminated_s)) \
== 'sed -es/foo/bar/'
assert get_new_command(Command(r"sed -e 's/\/foo/bar'", stderr=sed_unterminated_s)) \
== r"sed -e 's/\/foo/bar/'"
assert get_new_command(Command(r"sed -e s/foo/bar -es/baz/quz", stderr=sed_unterminated_s)) \
== r"sed -e s/foo/bar/ -es/baz/quz/"
assert (get_new_command(Command('sed -e s/foo/bar', stderr=sed_unterminated_s))
== 'sed -e s/foo/bar/')
assert (get_new_command(Command('sed -es/foo/bar', stderr=sed_unterminated_s))
== 'sed -es/foo/bar/')
assert (get_new_command(Command(r"sed -e 's/\/foo/bar'", stderr=sed_unterminated_s))
== r"sed -e 's/\/foo/bar/'")
assert (get_new_command(Command(r"sed -e s/foo/bar -es/baz/quz", stderr=sed_unterminated_s))
== r"sed -e s/foo/bar/ -es/baz/quz/")

View File

@@ -23,12 +23,12 @@ def test_not_match(command):
@pytest.mark.parametrize('command, new_command', [
(Command('hdfs dfs ls',
stderr='ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), ['hdfs dfs -ls']),
stderr='ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), ['hdfs dfs -ls']),
(Command('hdfs dfs rm /foo/bar',
stderr='rm: Unknown command\nDid you mean -rm? This command begins with a dash.'), ['hdfs dfs -rm /foo/bar']),
stderr='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',
stderr='ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), ['./bin/hdfs dfs -ls -R /foo/bar']),
stderr='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',
stderr='ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), ['./bin/hdfs dfs -Dtest=fred -ls -R /foo/bar'])])
stderr='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

View File

@@ -27,8 +27,8 @@ def test_not_match(command):
(Command(script='vagrant ssh', stderr='VM must be running to open SSH connection. Run `vagrant up`\nto start the virtual machine.'), 'vagrant up && vagrant ssh'),
(Command(script='vagrant ssh devbox', stderr='VM must be running to open SSH connection. Run `vagrant up`\nto start the virtual machine.'), ['vagrant up devbox && vagrant ssh devbox', 'vagrant up && vagrant ssh devbox']),
(Command(script='vagrant rdp',
stderr='VM must be created before running this command. Run `vagrant up` first.'), 'vagrant up && vagrant rdp'),
stderr='VM must be created before running this command. Run `vagrant up` first.'), 'vagrant up && vagrant rdp'),
(Command(script='vagrant rdp devbox',
stderr='VM must be created before running this command. Run `vagrant up` first.'), ['vagrant up devbox && vagrant rdp devbox', 'vagrant up && vagrant rdp devbox'])])
stderr='VM must be created before running this command. Run `vagrant up` first.'), ['vagrant up devbox && vagrant rdp devbox', 'vagrant up && vagrant rdp devbox'])])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command

View File

@@ -82,7 +82,7 @@ yarn_help_stdout = b'''
Run `yarn help COMMAND` for more information on specific commands.
Visit https://yarnpkg.com/en/docs/cli/ to learn more about Yarn.
'''
''' # noqa
@pytest.fixture(autouse=True)

View File

@@ -47,8 +47,8 @@ def test_get_corrected_commands(mocker):
get_new_command=lambda x: [x.script + '@', x.script + ';'],
priority=60)]
mocker.patch('thefuck.corrector.get_rules', return_value=rules)
assert [cmd.script for cmd in get_corrected_commands(command)] \
== ['test!', 'test@', 'test;']
assert ([cmd.script for cmd in get_corrected_commands(command)]
== ['test!', 'test@', 'test;'])
def test_organize_commands():

View File

@@ -13,10 +13,10 @@ from thefuck.system import Path
class TestCorrectedCommand(object):
def test_equality(self):
assert CorrectedCommand('ls', None, 100) == \
CorrectedCommand('ls', None, 200)
assert CorrectedCommand('ls', None, 100) != \
CorrectedCommand('ls', lambda *_: _, 100)
assert (CorrectedCommand('ls', None, 100) ==
CorrectedCommand('ls', None, 200))
assert (CorrectedCommand('ls', None, 100) !=
CorrectedCommand('ls', lambda *_: _, 100))
def test_hashable(self):
assert {CorrectedCommand('ls', None, 100),
@@ -41,8 +41,8 @@ class TestRule(object):
priority=900,
requires_output=True))
rule_path = os.path.join(os.sep, 'rules', 'bash.py')
assert Rule.from_path(Path(rule_path)) \
== Rule('bash', match, get_new_command, priority=900)
assert (Rule.from_path(Path(rule_path))
== Rule('bash', match, get_new_command, priority=900))
load_source.assert_called_once_with('bash', rule_path)
@pytest.mark.parametrize('rules, exclude_rules, rule, is_enabled', [
@@ -79,15 +79,15 @@ class TestRule(object):
def test_get_corrected_commands_with_rule_returns_list(self):
rule = Rule(get_new_command=lambda x: [x.script + '!', x.script + '@'],
priority=100)
assert list(rule.get_corrected_commands(Command(script='test'))) \
== [CorrectedCommand(script='test!', priority=100),
CorrectedCommand(script='test@', priority=200)]
assert (list(rule.get_corrected_commands(Command(script='test')))
== [CorrectedCommand(script='test!', priority=100),
CorrectedCommand(script='test@', priority=200)])
def test_get_corrected_commands_with_rule_returns_command(self):
rule = Rule(get_new_command=lambda x: x.script + '!',
priority=100)
assert list(rule.get_corrected_commands(Command(script='test'))) \
== [CorrectedCommand(script='test!', priority=100)]
assert (list(rule.get_corrected_commands(Command(script='test')))
== [CorrectedCommand(script='test!', priority=100)])
class TestCommand(object):

View File

@@ -30,11 +30,11 @@ def test_read_actions(patch_get_key):
const.KEY_DOWN, 'j',
# Ctrl+C:
const.KEY_CTRL_C, 'q'])
assert list(islice(ui.read_actions(), 8)) \
== [const.ACTION_SELECT, const.ACTION_SELECT,
const.ACTION_PREVIOUS, const.ACTION_PREVIOUS,
const.ACTION_NEXT, const.ACTION_NEXT,
const.ACTION_ABORT, const.ACTION_ABORT]
assert (list(islice(ui.read_actions(), 8))
== [const.ACTION_SELECT, const.ACTION_SELECT,
const.ACTION_PREVIOUS, const.ACTION_PREVIOUS,
const.ACTION_NEXT, const.ACTION_NEXT,
const.ACTION_ABORT, const.ACTION_ABORT])
def test_command_selector():
@@ -74,8 +74,8 @@ class TestSelectCommand(object):
def test_without_confirmation_with_side_effects(
self, capsys, commands_with_side_effect, settings):
settings.require_confirmation = False
assert ui.select_command(iter(commands_with_side_effect)) \
== commands_with_side_effect[0]
assert (ui.select_command(iter(commands_with_side_effect))
== commands_with_side_effect[0])
assert capsys.readouterr() == ('', 'ls (+side effect)\n')
def test_with_confirmation(self, capsys, patch_get_key, commands):
@@ -91,8 +91,8 @@ class TestSelectCommand(object):
def test_with_confirmation_with_side_effct(self, capsys, patch_get_key,
commands_with_side_effect):
patch_get_key(['\n'])
assert ui.select_command(iter(commands_with_side_effect)) \
== commands_with_side_effect[0]
assert (ui.select_command(iter(commands_with_side_effect))
== commands_with_side_effect[0])
assert capsys.readouterr() == ('', u'\x1b[1K\rls (+side effect) [enter/↑/↓/ctrl+c]\n')
def test_with_confirmation_select_second(self, capsys, patch_get_key, commands):

View File

@@ -18,8 +18,7 @@ from tests.utils import Command
def test_default_settings(settings, override, old, new):
settings.clear()
settings.update(old)
fn = lambda _: _
default_settings(override)(fn)(None)
default_settings(override)(lambda _: _)(None)
assert settings == new