1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-06 02:41:10 +01:00

Merge pull request #259 from diezcami/master

Added Python Compile Rule
This commit is contained in:
Vladimir Iakovlev 2015-06-22 19:19:41 +03:00
commit c6aead735b
3 changed files with 33 additions and 0 deletions

View File

@ -181,6 +181,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
* `open` – prepends `http` to address passed to `open`;
* `pip_unknown_command` – fixes wrong pip commands, for example `pip instatl/pip install`;
* `python_command` – prepends `python` when you trying to run not executable/without `./` python script;
* `python_compile` – appends missing `.py` when compiling and running Python files;
* `quotation_marks` – fixes uneven usage of `'` and `"` when containing args'
* `rm_dir` – adds `-rf` when you trying to remove directory;
* `sl_ls` – changes `sl` to `ls`;

View File

@ -0,0 +1,17 @@
import pytest
from thefuck.rules.python_compile import match, get_new_command
from tests.utils import Command
@pytest.mark.parametrize('command', [
Command(script='python foo'),
Command(script='python bar')])
def test_match(command):
assert match(command, None)
@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, None) == new_command

View File

@ -0,0 +1,15 @@
# Appends .py when compiling python files
#
# Example:
# > python foo
# error: python: can't open file 'foo': [Errno 2] No such file or directory
#
#
def match(command, settings):
return (command.script.startswith ('python ')
and not command.script.endswith('.py'))
def get_new_command(command, settings):
return command.script + '.py'