diff --git a/.travis.yml b/.travis.yml index 2798eed9..990a7f00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,6 +42,7 @@ install: - python setup.py develop - rm -rf build script: + - flake8 - export COVERAGE_PYTHON_VERSION=python-${TRAVIS_PYTHON_VERSION:0:1} - export RUN_TESTS="coverage run --source=thefuck,tests -m py.test -v --capture=sys tests" - if [[ $TRAVIS_PYTHON_VERSION == 3.6 && $TRAVIS_OS_NAME != "osx" ]]; then $RUN_TESTS --enable-functional; fi diff --git a/README.md b/README.md index b4b8b5a5..7eec6654 100644 --- a/README.md +++ b/README.md @@ -388,6 +388,12 @@ pip install -r requirements.txt python setup.py develop ``` +Run code style checks: + +```bash +flake8 +``` + Run unit tests: ```bash diff --git a/appveyor.yml b/appveyor.yml index 005e0d1a..96da08c9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,4 +20,5 @@ install: - "%PYTHON%/Scripts/pip.exe install -U -r requirements.txt" test_script: + - "%PYTHON%/python.exe -m flake8" - "%PYTHON%/Scripts/py.test.exe -sv" diff --git a/requirements.txt b/requirements.txt index ca9a8cc8..c450e437 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ pip +flake8 pytest mock pytest-mock diff --git a/tests/rules/test_brew_link.py b/tests/rules/test_brew_link.py index 14b13c7a..0586574c 100644 --- a/tests/rules/test_brew_link.py +++ b/tests/rules/test_brew_link.py @@ -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)) diff --git a/tests/rules/test_brew_uninstall.py b/tests/rules/test_brew_uninstall.py index e01ffc1e..cba0d424 100644 --- a/tests/rules/test_brew_uninstall.py +++ b/tests/rules/test_brew_uninstall.py @@ -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)) diff --git a/tests/rules/test_brew_unknown_command.py b/tests/rules/test_brew_unknown_command.py index 45e02f67..2185b867 100644 --- a/tests/rules/test_brew_unknown_command.py +++ b/tests/rules/test_brew_unknown_command.py @@ -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 diff --git a/tests/rules/test_composer_not_command.py b/tests/rules/test_composer_not_command.py index c4e4a5a4..717ee3ab 100644 --- a/tests/rules/test_composer_not_command.py +++ b/tests/rules/test_composer_not_command.py @@ -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') diff --git a/tests/rules/test_dirty_untar.py b/tests/rules/test_dirty_untar.py index b33a8900..5308a4e5 100644 --- a/tests/rules/test_dirty_untar.py +++ b/tests/rules/test_dirty_untar.py @@ -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) diff --git a/tests/rules/test_django_south_ghost.py b/tests/rules/test_django_south_ghost.py index 83656467..bbc83fe5 100644 --- a/tests/rules/test_django_south_ghost.py +++ b/tests/rules/test_django_south_ghost.py @@ -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): diff --git a/tests/rules/test_django_south_merge.py b/tests/rules/test_django_south_merge.py index 13f7dbaf..581a1cf3 100644 --- a/tests/rules/test_django_south_merge.py +++ b/tests/rules/test_django_south_merge.py @@ -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') diff --git a/tests/rules/test_fab_command_not_found.py b/tests/rules/test_fab_command_not_found.py index 361c3742..da596b6b 100644 --- a/tests/rules/test_fab_command_not_found.py +++ b/tests/rules/test_fab_command_not_found.py @@ -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 diff --git a/tests/rules/test_fix_alt_space.py b/tests/rules/test_fix_alt_space.py index c5b03c50..abc0ed1f 100644 --- a/tests/rules/test_fix_alt_space.py +++ b/tests/rules/test_fix_alt_space.py @@ -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') diff --git a/tests/rules/test_fix_file.py b/tests/rules/test_fix_file.py index 30f5fa1d..70921cb8 100644 --- a/tests/rules/test_fix_file.py +++ b/tests/rules/test_fix_file.py @@ -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])) diff --git a/tests/rules/test_git_add_force.py b/tests/rules/test_git_add_force.py index abe2bd79..d6d3dd7c 100644 --- a/tests/rules/test_git_add_force.py +++ b/tests/rules/test_git_add_force.py @@ -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") diff --git a/tests/rules/test_git_not_command.py b/tests/rules/test_git_not_command.py index 6257767e..0c3c06f7 100644 --- a/tests/rules/test_git_not_command.py +++ b/tests/rules/test_git_not_command.py @@ -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']) diff --git a/tests/rules/test_git_pull.py b/tests/rules/test_git_pull.py index 11c50171..d24e400c 100644 --- a/tests/rules/test_git_pull.py +++ b/tests/rules/test_git_pull.py @@ -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") diff --git a/tests/rules/test_git_pull_uncommitted_changes.py b/tests/rules/test_git_pull_uncommitted_changes.py index 480b31d8..e32a7370 100644 --- a/tests/rules/test_git_pull_uncommitted_changes.py +++ b/tests/rules/test_git_pull_uncommitted_changes.py @@ -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") diff --git a/tests/rules/test_git_pull_unstaged_changes.py b/tests/rules/test_git_pull_unstaged_changes.py index a8cbb4c3..ef3d94ea 100644 --- a/tests/rules/test_git_pull_unstaged_changes.py +++ b/tests/rules/test_git_pull_unstaged_changes.py @@ -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") diff --git a/tests/rules/test_git_push_pull.py b/tests/rules/test_git_push_pull.py index afa74748..93e41bc2 100644 --- a/tests/rules/test_git_push_pull.py +++ b/tests/rules/test_git_push_pull.py @@ -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'), diff --git a/tests/rules/test_git_remote_seturl_add.py b/tests/rules/test_git_remote_seturl_add.py index 8b8667e5..011d6207 100644 --- a/tests/rules/test_git_remote_seturl_add.py +++ b/tests/rules/test_git_remote_seturl_add.py @@ -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')]) diff --git a/tests/rules/test_git_stash.py b/tests/rules/test_git_stash.py index da9aded7..53cdce42 100644 --- a/tests/rules/test_git_stash.py +++ b/tests/rules/test_git_stash.py @@ -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', [ diff --git a/tests/rules/test_git_stash_pop.py b/tests/rules/test_git_stash_pop.py index 1ff34686..2e0578e4 100644 --- a/tests/rules/test_git_stash_pop.py +++ b/tests/rules/test_git_stash_pop.py @@ -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 .") diff --git a/tests/rules/test_git_tag_force.py b/tests/rules/test_git_tag_force.py index 46c96fc6..3a2e40d9 100644 --- a/tests/rules/test_git_tag_force.py +++ b/tests/rules/test_git_tag_force.py @@ -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") diff --git a/tests/rules/test_has_exists_script.py b/tests/rules/test_has_exists_script.py index c6b4b1ed..7ddb7b89 100644 --- a/tests/rules/test_has_exists_script.py +++ b/tests/rules/test_has_exists_script.py @@ -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): diff --git a/tests/rules/test_lein_not_task.py b/tests/rules/test_lein_not_task.py index b4fc4498..8b3420c2 100644 --- a/tests/rules/test_lein_not_task.py +++ b/tests/rules/test_lein_not_task.py @@ -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']) diff --git a/tests/rules/test_ln_s_order.py b/tests/rules/test_ln_s_order.py index d4119f40..8501b664 100644 --- a/tests/rules/test_ln_s_order.py +++ b/tests/rules/test_ln_s_order.py @@ -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 diff --git a/tests/rules/test_mvn_no_command.py b/tests/rules/test_mvn_no_command.py index 1871716c..7e729457 100644 --- a/tests/rules/test_mvn_no_command.py +++ b/tests/rules/test_mvn_no_command.py @@ -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') ]) diff --git a/tests/rules/test_mvn_unknown_lifecycle_phase.py b/tests/rules/test_mvn_unknown_lifecycle_phase.py index c4b4b7a5..b880fd20 100644 --- a/tests/rules/test_mvn_unknown_lifecycle_phase.py +++ b/tests/rules/test_mvn_unknown_lifecycle_phase.py @@ -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') ]) diff --git a/tests/rules/test_python_command.py b/tests/rules/test_python_command.py index 053457da..234d2e54 100644 --- a/tests/rules/test_python_command.py +++ b/tests/rules/test_python_command.py @@ -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') diff --git a/tests/rules/test_rm_root.py b/tests/rules/test_rm_root.py index 47c243f8..fe419904 100644 --- a/tests/rules/test_rm_root.py +++ b/tests/rules/test_rm_root.py @@ -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') diff --git a/tests/rules/test_sed_unterminated_s.py b/tests/rules/test_sed_unterminated_s.py index 0c890efd..7b2bf78d 100644 --- a/tests/rules/test_sed_unterminated_s.py +++ b/tests/rules/test_sed_unterminated_s.py @@ -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/") diff --git a/tests/rules/test_unknown_command.py b/tests/rules/test_unknown_command.py index 9a2d37e7..7e7f9aa7 100644 --- a/tests/rules/test_unknown_command.py +++ b/tests/rules/test_unknown_command.py @@ -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 diff --git a/tests/rules/test_vagrant_up.py b/tests/rules/test_vagrant_up.py index 19d7b335..4319eed6 100644 --- a/tests/rules/test_vagrant_up.py +++ b/tests/rules/test_vagrant_up.py @@ -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 diff --git a/tests/rules/test_yarn_command_not_found.py b/tests/rules/test_yarn_command_not_found.py index 67b7823b..d8a11618 100644 --- a/tests/rules/test_yarn_command_not_found.py +++ b/tests/rules/test_yarn_command_not_found.py @@ -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) diff --git a/tests/test_corrector.py b/tests/test_corrector.py index 08e4160e..39b3c108 100644 --- a/tests/test_corrector.py +++ b/tests/test_corrector.py @@ -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(): diff --git a/tests/test_types.py b/tests/test_types.py index 9cb951ba..4faf8edf 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -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): diff --git a/tests/test_ui.py b/tests/test_ui.py index 90efbac2..1c2a9933 100644 --- a/tests/test_ui.py +++ b/tests/test_ui.py @@ -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): diff --git a/tests/test_utils.py b/tests/test_utils.py index c9290894..ac45a7b1 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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 diff --git a/thefuck/main.py b/thefuck/main.py index 6ca89ac2..5fa9e7c0 100644 --- a/thefuck/main.py +++ b/thefuck/main.py @@ -3,16 +3,16 @@ from .system import init_output init_output() -from argparse import ArgumentParser -from pprint import pformat -import sys -from . import logs, types -from .shells import shell -from .conf import settings -from .corrector import get_corrected_commands -from .exceptions import EmptyCommand -from .utils import get_installation_info, get_alias -from .ui import select_command +from argparse import ArgumentParser # noqa: E402 +from pprint import pformat # noqa: E402 +import sys # noqa: E402 +from . import logs, types # noqa: E402 +from .shells import shell # noqa: E402 +from .conf import settings # noqa: E402 +from .corrector import get_corrected_commands # noqa: E402 +from .exceptions import EmptyCommand # noqa: E402 +from .utils import get_installation_info, get_alias # noqa: E402 +from .ui import select_command # noqa: E402 def fix_command(): @@ -59,11 +59,10 @@ def how_to_configure_alias(): def main(): parser = ArgumentParser(prog='thefuck') version = get_installation_info().version - parser.add_argument( - '-v', '--version', - action='version', - version='The Fuck {} using Python {}'.format( - version, sys.version.split()[0])) + parser.add_argument('-v', '--version', + action='version', + version='The Fuck {} using Python {}'.format( + version, sys.version.split()[0])) parser.add_argument('-a', '--alias', action='store_true', help='[custom-alias-name] prints alias for current shell') diff --git a/thefuck/rules/brew_unknown_command.py b/thefuck/rules/brew_unknown_command.py index 35f6e937..1d8186e6 100644 --- a/thefuck/rules/brew_unknown_command.py +++ b/thefuck/rules/brew_unknown_command.py @@ -54,8 +54,8 @@ def _brew_commands(): brew_path_prefix = get_brew_path_prefix() if brew_path_prefix: try: - return _get_brew_commands(brew_path_prefix) \ - + _get_brew_tap_specific_commands(brew_path_prefix) + return (_get_brew_commands(brew_path_prefix) + + _get_brew_tap_specific_commands(brew_path_prefix)) except OSError: pass diff --git a/thefuck/rules/dirty_unzip.py b/thefuck/rules/dirty_unzip.py index 23878f5f..3f74ef14 100644 --- a/thefuck/rules/dirty_unzip.py +++ b/thefuck/rules/dirty_unzip.py @@ -39,7 +39,7 @@ def match(command): def get_new_command(command): return u'{} -d {}'.format( - command.script, shell.quote(_zip_file(command)[:-4])) + command.script, shell.quote(_zip_file(command)[:-4])) def side_effect(old_cmd, command): diff --git a/thefuck/rules/dry.py b/thefuck/rules/dry.py index cfc91da8..dce9b3d7 100644 --- a/thefuck/rules/dry.py +++ b/thefuck/rules/dry.py @@ -9,6 +9,7 @@ def match(command): def get_new_command(command): return ' '.join(command.script_parts[1:]) + # it should be rare enough to actually have to type twice the same word, so # this rule can have a higher priority to come before things like "cd cd foo" priority = 900 diff --git a/thefuck/rules/fix_file.py b/thefuck/rules/fix_file.py index a83034d4..b10cf047 100644 --- a/thefuck/rules/fix_file.py +++ b/thefuck/rules/fix_file.py @@ -40,6 +40,8 @@ def _make_pattern(pattern): .replace('{line}', '(?P[0-9]+)') \ .replace('{col}', '(?P[0-9]+)') return re.compile(pattern, re.MULTILINE) + + patterns = [_make_pattern(p).search for p in patterns] diff --git a/thefuck/rules/git_add_force.py b/thefuck/rules/git_add_force.py index 9adc0725..bf7c28b8 100644 --- a/thefuck/rules/git_add_force.py +++ b/thefuck/rules/git_add_force.py @@ -10,4 +10,4 @@ def match(command): @git_support def get_new_command(command): - return replace_argument(command.script, 'add', 'add --force') + return replace_argument(command.script, 'add', 'add --force') diff --git a/thefuck/rules/git_fix_stash.py b/thefuck/rules/git_fix_stash.py index 19cef4c3..0ff01b92 100644 --- a/thefuck/rules/git_fix_stash.py +++ b/thefuck/rules/git_fix_stash.py @@ -11,6 +11,7 @@ def match(command): else: return False + # git's output here is too complicated to be parsed (see the test file) stash_commands = ( 'apply', diff --git a/thefuck/rules/git_pull_uncommitted_changes.py b/thefuck/rules/git_pull_uncommitted_changes.py index 8e9a640d..3a8be31a 100644 --- a/thefuck/rules/git_pull_uncommitted_changes.py +++ b/thefuck/rules/git_pull_uncommitted_changes.py @@ -6,7 +6,7 @@ from thefuck.specific.git import git_support def match(command): return ('pull' in command.script and ('You have unstaged changes' in command.stderr - or 'contains uncommitted changes' in command.stderr)) + or 'contains uncommitted changes' in command.stderr)) @git_support diff --git a/thefuck/rules/ifconfig_device_not_found.py b/thefuck/rules/ifconfig_device_not_found.py index f8692236..a7e5026f 100644 --- a/thefuck/rules/ifconfig_device_not_found.py +++ b/thefuck/rules/ifconfig_device_not_found.py @@ -1,6 +1,6 @@ import subprocess from thefuck.utils import for_app, replace_command, eager -import sys + @for_app('ifconfig') def match(command): @@ -21,5 +21,3 @@ def get_new_command(command): interface = command.stderr.split(' ')[0][:-1] possible_interfaces = _get_possible_interfaces() return replace_command(command, interface, possible_interfaces) - - diff --git a/thefuck/rules/man_no_space.py b/thefuck/rules/man_no_space.py index c5869345..2d5d74e6 100644 --- a/thefuck/rules/man_no_space.py +++ b/thefuck/rules/man_no_space.py @@ -6,4 +6,5 @@ def match(command): def get_new_command(command): return u'man {}'.format(command.script[3:]) + priority = 2000 diff --git a/thefuck/rules/pacman.py b/thefuck/rules/pacman.py index 13a08d65..779ed20f 100644 --- a/thefuck/rules/pacman.py +++ b/thefuck/rules/pacman.py @@ -13,4 +13,5 @@ def get_new_command(command): return [formatme.format(pacman, package, command.script) for package in packages] + enabled_by_default, pacman = archlinux_env() diff --git a/thefuck/rules/switch_lang.py b/thefuck/rules/switch_lang.py index b1abb63d..60e5780c 100644 --- a/thefuck/rules/switch_lang.py +++ b/thefuck/rules/switch_lang.py @@ -33,8 +33,8 @@ def match(command): if 'not found' not in command.stderr: return False matched_layout = _get_matched_layout(command) - return matched_layout and \ - _switch_command(command, matched_layout) != get_alias() + return (matched_layout and + _switch_command(command, matched_layout) != get_alias()) def get_new_command(command): diff --git a/thefuck/rules/unknown_command.py b/thefuck/rules/unknown_command.py index ee7139e2..30a90bc8 100644 --- a/thefuck/rules/unknown_command.py +++ b/thefuck/rules/unknown_command.py @@ -3,8 +3,8 @@ from thefuck.utils import replace_command def match(command): - return (re.search(r"([^:]*): Unknown command.*", command.stderr) != None - and re.search(r"Did you mean ([^?]*)?", command.stderr) != None) + return (re.search(r"([^:]*): Unknown command.*", command.stderr) is not None + and re.search(r"Did you mean ([^?]*)?", command.stderr) is not None) def get_new_command(command): diff --git a/thefuck/rules/workon_doesnt_exists.py b/thefuck/rules/workon_doesnt_exists.py index 6c97ce49..41d17c07 100644 --- a/thefuck/rules/workon_doesnt_exists.py +++ b/thefuck/rules/workon_doesnt_exists.py @@ -26,7 +26,7 @@ def get_new_command(command): available = _get_all_environments() if available: - return replace_command(command, misspelled_env, available) \ - + [create_new] + return (replace_command(command, misspelled_env, available) + + [create_new]) else: return create_new diff --git a/thefuck/shells/tcsh.py b/thefuck/shells/tcsh.py index 057dc560..9c9ee0d4 100644 --- a/thefuck/shells/tcsh.py +++ b/thefuck/shells/tcsh.py @@ -19,9 +19,9 @@ class Tcsh(Generic): def get_aliases(self): proc = Popen(['tcsh', '-ic', 'alias'], stdout=PIPE, stderr=DEVNULL) return dict( - self._parse_alias(alias) - for alias in proc.stdout.read().decode('utf-8').split('\n') - if alias and '\t' in alias) + self._parse_alias(alias) + for alias in proc.stdout.read().decode('utf-8').split('\n') + if alias and '\t' in alias) def _get_history_file_name(self): return os.environ.get("HISTFILE", diff --git a/thefuck/system/__init__.py b/thefuck/system/__init__.py index cc4698ac..bb13c30b 100644 --- a/thefuck/system/__init__.py +++ b/thefuck/system/__init__.py @@ -2,6 +2,6 @@ import sys if sys.platform == 'win32': - from .win32 import * + from .win32 import * # noqa: F401,F403 else: - from .unix import * + from .unix import * # noqa: F401,F403 diff --git a/thefuck/system/unix.py b/thefuck/system/unix.py index 0a29bb6b..e6e87ea2 100644 --- a/thefuck/system/unix.py +++ b/thefuck/system/unix.py @@ -52,5 +52,6 @@ except ImportError: def _expanduser(self): return self.__class__(os.path.expanduser(str(self))) + if not hasattr(Path, 'expanduser'): Path.expanduser = _expanduser diff --git a/thefuck/system/win32.py b/thefuck/system/win32.py index ce649a48..190d5430 100644 --- a/thefuck/system/win32.py +++ b/thefuck/system/win32.py @@ -41,5 +41,6 @@ except ImportError: def _expanduser(self): return self.__class__(os.path.expanduser(str(self))) + # pathlib's expanduser fails on windows, see http://bugs.python.org/issue19776 Path.expanduser = _expanduser diff --git a/thefuck/types.py b/thefuck/types.py index c03cb932..91f69e9c 100644 --- a/thefuck/types.py +++ b/thefuck/types.py @@ -40,8 +40,8 @@ class Command(object): def __eq__(self, other): if isinstance(other, Command): - return (self.script, self.stdout, self.stderr) \ - == (other.script, other.stdout, other.stderr) + return ((self.script, self.stdout, self.stderr) + == (other.script, other.stdout, other.stderr)) else: return False @@ -159,12 +159,12 @@ class Rule(object): def __eq__(self, other): if isinstance(other, Rule): - return (self.name, self.match, self.get_new_command, - self.enabled_by_default, self.side_effect, - self.priority, self.requires_output) \ - == (other.name, other.match, other.get_new_command, - other.enabled_by_default, other.side_effect, - other.priority, other.requires_output) + return ((self.name, self.match, self.get_new_command, + self.enabled_by_default, self.side_effect, + self.priority, self.requires_output) + == (other.name, other.match, other.get_new_command, + other.enabled_by_default, other.side_effect, + other.priority, other.requires_output)) else: return False @@ -172,9 +172,9 @@ class Rule(object): return 'Rule(name={}, match={}, get_new_command={}, ' \ 'enabled_by_default={}, side_effect={}, ' \ 'priority={}, requires_output)'.format( - self.name, self.match, self.get_new_command, - self.enabled_by_default, self.side_effect, - self.priority, self.requires_output) + self.name, self.match, self.get_new_command, + self.enabled_by_default, self.side_effect, + self.priority, self.requires_output) @classmethod def from_path(cls, path): diff --git a/thefuck/utils.py b/thefuck/utils.py index 2bb20a22..29ea2486 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -40,6 +40,8 @@ def memoize(fn): return value return wrapper + + memoize.disabled = False @@ -238,6 +240,8 @@ def cache(*depends_on): return value return _cache + + cache.disabled = False diff --git a/tox.ini b/tox.ini index 2b0b03e4..71deba95 100644 --- a/tox.ini +++ b/tox.ini @@ -4,3 +4,7 @@ envlist = py27,py33,py34,py35,py36 [testenv] deps = -rrequirements.txt commands = py.test -v --capture=sys + +[flake8] +ignore = E501,W503 +exclude = venv