mirror of
https://github.com/nvbn/thefuck.git
synced 2025-10-30 14:44:05 +00:00
Merge branch 'master' into flake8
This commit is contained in:
@@ -3,18 +3,11 @@ from tests.functional.plots import with_confirmation, without_confirmation, \
|
||||
refuse_with_confirmation, history_changed, history_not_changed, \
|
||||
select_command_with_arrows, how_to_configure
|
||||
|
||||
containers = ((u'thefuck/ubuntu-python3-bash',
|
||||
u'''FROM ubuntu:latest
|
||||
RUN apt-get update
|
||||
RUN apt-get install -yy python3 python3-pip python3-dev git
|
||||
RUN pip3 install -U setuptools
|
||||
RUN ln -s /usr/bin/pip3 /usr/bin/pip''',
|
||||
containers = ((u'thefuck/python3-bash',
|
||||
u'FROM python:3',
|
||||
u'bash'),
|
||||
(u'thefuck/ubuntu-python2-bash',
|
||||
u'''FROM ubuntu:latest
|
||||
RUN apt-get update
|
||||
RUN apt-get install -yy python python-pip python-dev git
|
||||
RUN pip2 install -U pip setuptools''',
|
||||
(u'thefuck/python2-bash',
|
||||
u'FROM python:2',
|
||||
u'bash'))
|
||||
|
||||
|
||||
|
||||
@@ -2,19 +2,20 @@ import pytest
|
||||
from tests.functional.plots import with_confirmation, without_confirmation, \
|
||||
refuse_with_confirmation, select_command_with_arrows
|
||||
|
||||
containers = (('thefuck/ubuntu-python3-fish',
|
||||
u'''FROM ubuntu:latest
|
||||
containers = (('thefuck/python3-fish',
|
||||
u'''FROM python:3
|
||||
# Use jessie-backports since it has the fish package. See here for details:
|
||||
# https://github.com/tianon/docker-brew-debian/blob/88ae21052affd8a14553bb969f9d41c464032122/jessie/backports/Dockerfile
|
||||
RUN awk '$1 ~ "^deb" { $3 = $3 "-backports"; print; exit }' /etc/apt/sources.list > /etc/apt/sources.list.d/backports.list
|
||||
RUN apt-get update
|
||||
RUN apt-get install -yy python3 python3-pip python3-dev fish git
|
||||
RUN pip3 install -U setuptools
|
||||
RUN ln -s /usr/bin/pip3 /usr/bin/pip
|
||||
RUN apt-get install -yy fish''',
|
||||
u'fish'),
|
||||
('thefuck/ubuntu-python2-fish',
|
||||
u'''FROM ubuntu:latest
|
||||
('thefuck/python2-fish',
|
||||
u'''FROM python:2
|
||||
# Use jessie-backports since it has the fish package. See here for details:
|
||||
# https://github.com/tianon/docker-brew-debian/blob/88ae21052affd8a14553bb969f9d41c464032122/jessie/backports/Dockerfile
|
||||
RUN awk '$1 ~ "^deb" { $3 = $3 "-backports"; print; exit }' /etc/apt/sources.list > /etc/apt/sources.list.d/backports.list
|
||||
RUN apt-get update
|
||||
RUN apt-get install -yy python python-pip python-dev git
|
||||
RUN pip2 install -U pip setuptools
|
||||
RUN apt-get install -yy fish''',
|
||||
u'fish'))
|
||||
|
||||
|
||||
@@ -2,11 +2,7 @@ import pytest
|
||||
import time
|
||||
|
||||
dockerfile = u'''
|
||||
FROM ubuntu:latest
|
||||
RUN apt-get update
|
||||
RUN apt-get install -yy python3 python3-pip python3-dev git
|
||||
RUN pip3 install -U setuptools
|
||||
RUN ln -s /usr/bin/pip3 /usr/bin/pip
|
||||
FROM python:3
|
||||
RUN adduser --disabled-password --gecos '' test
|
||||
ENV SEED "{seed}"
|
||||
WORKDIR /src
|
||||
@@ -42,7 +38,7 @@ def plot(proc, TIMEOUT):
|
||||
@pytest.mark.functional
|
||||
@pytest.mark.benchmark(min_rounds=10)
|
||||
def test_performance(spawnu, TIMEOUT, benchmark):
|
||||
proc = spawnu(u'thefuck/ubuntu-python3-bash-performance',
|
||||
proc = spawnu(u'thefuck/python3-bash-performance',
|
||||
dockerfile, u'bash')
|
||||
proc.sendline(u'pip install /src')
|
||||
proc.sendline(u'su test')
|
||||
|
||||
@@ -2,19 +2,14 @@ import pytest
|
||||
from tests.functional.plots import with_confirmation, without_confirmation, \
|
||||
refuse_with_confirmation, select_command_with_arrows
|
||||
|
||||
containers = (('thefuck/ubuntu-python3-tcsh',
|
||||
u'''FROM ubuntu:latest
|
||||
containers = (('thefuck/python3-tcsh',
|
||||
u'''FROM python:3
|
||||
RUN apt-get update
|
||||
RUN apt-get install -yy python3 python3-pip python3-dev git
|
||||
RUN pip3 install -U setuptools
|
||||
RUN ln -s /usr/bin/pip3 /usr/bin/pip
|
||||
RUN apt-get install -yy tcsh''',
|
||||
u'tcsh'),
|
||||
('thefuck/ubuntu-python2-tcsh',
|
||||
u'''FROM ubuntu:latest
|
||||
('thefuck/python2-tcsh',
|
||||
u'''FROM python:2
|
||||
RUN apt-get update
|
||||
RUN apt-get install -yy python python-pip python-dev git
|
||||
RUN pip2 install -U pip setuptools
|
||||
RUN apt-get install -yy tcsh''',
|
||||
u'tcsh'))
|
||||
|
||||
|
||||
@@ -3,19 +3,14 @@ from tests.functional.plots import with_confirmation, without_confirmation, \
|
||||
refuse_with_confirmation, history_changed, history_not_changed, \
|
||||
select_command_with_arrows, how_to_configure
|
||||
|
||||
containers = (('thefuck/ubuntu-python3-zsh',
|
||||
u'''FROM ubuntu:latest
|
||||
containers = (('thefuck/python3-zsh',
|
||||
u'''FROM python:3
|
||||
RUN apt-get update
|
||||
RUN apt-get install -yy python3 python3-pip python3-dev git
|
||||
RUN pip3 install -U setuptools
|
||||
RUN ln -s /usr/bin/pip3 /usr/bin/pip
|
||||
RUN apt-get install -yy zsh''',
|
||||
u'zsh'),
|
||||
('thefuck/ubuntu-python2-zsh',
|
||||
u'''FROM ubuntu:latest
|
||||
('thefuck/python2-zsh',
|
||||
u'''FROM python:2
|
||||
RUN apt-get update
|
||||
RUN apt-get install -yy python python-pip python-dev git
|
||||
RUN pip2 install -U pip setuptools
|
||||
RUN apt-get install -yy zsh''',
|
||||
u'zsh'))
|
||||
|
||||
|
||||
25
tests/rules/test_ag_literal.py
Normal file
25
tests/rules/test_ag_literal.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import pytest
|
||||
from thefuck.rules.ag_literal import get_new_command, match
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def stderr():
|
||||
return ('ERR: Bad regex! pcre_compile() failed at position 1: missing )\n'
|
||||
'If you meant to search for a literal string, run ag with -Q\n')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script', ['ag \('])
|
||||
def test_match(script, stderr):
|
||||
assert match(Command(script=script, stderr=stderr))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script', ['ag foo'])
|
||||
def test_not_match(script):
|
||||
assert not match(Command(script=script))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script, new_cmd', [
|
||||
('ag \(', 'ag -Q \(')])
|
||||
def test_get_new_command(script, new_cmd, stderr):
|
||||
assert get_new_command((Command(script=script, stderr=stderr))) == new_cmd
|
||||
@@ -7,6 +7,8 @@ from tests.utils import Command
|
||||
(Command(script='vim', stderr='vim: command not found'),
|
||||
[('vim', 'main'), ('vim-tiny', 'main')]),
|
||||
(Command(script='sudo vim', stderr='vim: command not found'),
|
||||
[('vim', 'main'), ('vim-tiny', 'main')]),
|
||||
(Command(script='vim', stderr="The program 'vim' is currently not installed. You can install it by typing: sudo apt install vim"),
|
||||
[('vim', 'main'), ('vim-tiny', 'main')])])
|
||||
def test_match(mocker, command, packages):
|
||||
mocker.patch('thefuck.rules.apt_get.which', return_value=None)
|
||||
|
||||
82
tests/rules/test_gem_unknown_command.py
Normal file
82
tests/rules/test_gem_unknown_command.py
Normal file
@@ -0,0 +1,82 @@
|
||||
import pytest
|
||||
from six import BytesIO
|
||||
from thefuck.rules.gem_unknown_command import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
stderr = '''
|
||||
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, stderr=stderr.format(command)))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script, stderr', [
|
||||
('gem install jekyll', ''),
|
||||
('git log', stderr.format('log'))])
|
||||
def test_not_match(script, stderr):
|
||||
assert not match(Command(script, stderr=stderr))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script, stderr, result', [
|
||||
('gem isntall jekyll', stderr.format('isntall'), 'gem install jekyll'),
|
||||
('gem last --local', stderr.format('last'), 'gem list --local')])
|
||||
def test_get_new_command(script, stderr, result):
|
||||
new_command = get_new_command(Command(script, stderr=stderr))
|
||||
assert new_command[0] == result
|
||||
22
tests/rules/test_git_add_force.py
Normal file
22
tests/rules/test_git_add_force.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import pytest
|
||||
from thefuck.rules.git_add_force import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def stderr():
|
||||
return ('The following paths are ignored by one of your .gitignore files:\n'
|
||||
'dist/app.js\n'
|
||||
'dist/background.js\n'
|
||||
'dist/options.js\n'
|
||||
'Use -f if you really want to add them.\n')
|
||||
|
||||
|
||||
def test_match(stderr):
|
||||
assert match(Command('git add dist/*.js', stderr=stderr))
|
||||
assert not match(Command('git add dist/*.js'))
|
||||
|
||||
|
||||
def test_get_new_command(stderr):
|
||||
assert get_new_command(Command('git add dist/*.js', stderr=stderr)) \
|
||||
== "git add --force dist/*.js"
|
||||
31
tests/rules/test_git_flag_after_filename.py
Normal file
31
tests/rules/test_git_flag_after_filename.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import pytest
|
||||
from thefuck.rules.git_flag_after_filename import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
command1 = Command('git log README.md -p',
|
||||
stderr="fatal: bad flag '-p' used after filename")
|
||||
command2 = Command('git log README.md -p CONTRIBUTING.md',
|
||||
stderr="fatal: bad flag '-p' used after filename")
|
||||
command3 = Command('git log -p README.md --name-only',
|
||||
stderr="fatal: bad flag '--name-only' used after filename")
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
command1, command2, command3])
|
||||
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")])
|
||||
def test_get_new_command(command, result):
|
||||
assert get_new_command(command) == result
|
||||
@@ -23,6 +23,8 @@ def test_match(stderr):
|
||||
def test_get_new_command(stderr):
|
||||
assert get_new_command(Command('git push', stderr=stderr))\
|
||||
== "git push --set-upstream origin master"
|
||||
assert get_new_command(Command('git push -u', stderr=stderr))\
|
||||
== "git push --set-upstream origin master"
|
||||
assert get_new_command(Command('git push -u origin', stderr=stderr))\
|
||||
== "git push --set-upstream origin master"
|
||||
assert get_new_command(Command('git push --set-upstream origin', stderr=stderr))\
|
||||
|
||||
40
tests/rules/test_git_rebase_merge_dir.py
Normal file
40
tests/rules/test_git_rebase_merge_dir.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import pytest
|
||||
from thefuck.rules.git_rebase_merge_dir import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def stderr():
|
||||
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(stderr, script):
|
||||
assert match(Command(script=script, stderr=stderr))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script', ['git rebase master', 'git rebase -abort'])
|
||||
def test_not_match(script):
|
||||
assert not match(Command(script=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(stderr, script, result):
|
||||
assert get_new_command(Command(script=script, stderr=stderr)) == result
|
||||
28
tests/rules/test_git_rm_local_modifications.py
Normal file
28
tests/rules/test_git_rm_local_modifications.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import pytest
|
||||
from thefuck.rules.git_rm_local_modifications import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def stderr(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(stderr, script, target):
|
||||
assert match(Command(script=script, stderr=stderr))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script', ['git rm foo', 'git rm foo bar', 'git rm'])
|
||||
def test_not_match(script):
|
||||
assert not match(Command(script=script, stderr=''))
|
||||
|
||||
|
||||
@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(stderr, script, target, new_command):
|
||||
assert get_new_command(Command(script=script, stderr=stderr)) == new_command
|
||||
28
tests/rules/test_git_rm_staged.py
Normal file
28
tests/rules/test_git_rm_staged.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import pytest
|
||||
from thefuck.rules.git_rm_staged import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def stderr(target):
|
||||
return ('error: the following file has changes staged in the index:\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(stderr, script, target):
|
||||
assert match(Command(script=script, stderr=stderr))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script', ['git rm foo', 'git rm foo bar', 'git rm'])
|
||||
def test_not_match(script):
|
||||
assert not match(Command(script=script, stderr=''))
|
||||
|
||||
|
||||
@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(stderr, script, target, new_command):
|
||||
assert get_new_command(Command(script=script, stderr=stderr)) == new_command
|
||||
18
tests/rules/test_git_stash_pop.py
Normal file
18
tests/rules/test_git_stash_pop.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import pytest
|
||||
from thefuck.rules.git_stash_pop import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def stderr():
|
||||
return '''error: Your local changes to the following files would be overwritten by merge:'''
|
||||
|
||||
|
||||
def test_match(stderr):
|
||||
assert match(Command('git stash pop', stderr=stderr))
|
||||
assert not match(Command('git stash'))
|
||||
|
||||
|
||||
def test_get_new_command(stderr):
|
||||
assert get_new_command(Command('git stash pop', stderr=stderr)) \
|
||||
== "git add . && git stash pop && git reset ."
|
||||
18
tests/rules/test_git_tag_force.py
Normal file
18
tests/rules/test_git_tag_force.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import pytest
|
||||
from thefuck.rules.git_tag_force import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def stderr():
|
||||
return '''fatal: tag 'alert' already exists'''
|
||||
|
||||
|
||||
def test_match(stderr):
|
||||
assert match(Command('git tag alert', stderr=stderr))
|
||||
assert not match(Command('git tag alert'))
|
||||
|
||||
|
||||
def test_get_new_command(stderr):
|
||||
assert get_new_command(Command('git tag alert', stderr=stderr)) \
|
||||
== "git tag --force alert"
|
||||
53
tests/rules/test_ifconfig_device_not_found.py
Normal file
53
tests/rules/test_ifconfig_device_not_found.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import pytest
|
||||
from six import BytesIO
|
||||
from thefuck.rules.ifconfig_device_not_found import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
stderr = '{}: 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, stderr', [
|
||||
('ifconfig wlan0', stderr.format('wlan0')),
|
||||
('ifconfig -s eth0', stderr.format('eth0')),
|
||||
])
|
||||
def test_match(script, stderr):
|
||||
assert match(Command(script, stderr=stderr))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script, stderr', [
|
||||
('config wlan0',
|
||||
'wlan0: error fetching interface information: Device not found'),
|
||||
('ifconfig eth0', ''),
|
||||
])
|
||||
def test_not_match(script, stderr):
|
||||
assert not match(Command(script, stderr=stderr))
|
||||
|
||||
|
||||
@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, stderr=stderr.format('wlan0')))
|
||||
assert new_command == result
|
||||
12
tests/rules/test_ls_all.py
Normal file
12
tests/rules/test_ls_all.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from thefuck.rules.ls_all import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
def test_match():
|
||||
assert match(Command(script='ls'))
|
||||
assert not match(Command(script='ls', stdout='file.py\n'))
|
||||
|
||||
|
||||
def test_get_new_command():
|
||||
assert get_new_command(Command(script='ls empty_dir')) == 'ls -A empty_dir'
|
||||
assert get_new_command(Command(script='ls')) == 'ls -A'
|
||||
@@ -23,7 +23,8 @@ def test_not_match(command):
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('man read'), ['man 3 read', 'man 2 read']),
|
||||
(Command('man read'), ['man 3 read', 'man 2 read', 'read --help']),
|
||||
(Command('man missing', stderr="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'),
|
||||
|
||||
46
tests/rules/test_scm_correction.py
Normal file
46
tests/rules/test_scm_correction.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import pytest
|
||||
from thefuck.rules.scm_correction import match, get_new_command
|
||||
from tests.utils 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, stderr, 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, stderr, actual_scm):
|
||||
get_actual_scm_mock.return_value = actual_scm
|
||||
assert match(Command(script, stderr=stderr))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script, stderr, 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, stderr, actual_scm):
|
||||
get_actual_scm_mock.return_value = actual_scm
|
||||
assert not match(Command(script, stderr=stderr))
|
||||
|
||||
|
||||
@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
|
||||
39
tests/rules/test_sudo_command_from_user_path.py
Normal file
39
tests/rules/test_sudo_command_from_user_path.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import pytest
|
||||
from thefuck.rules.sudo_command_from_user_path import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
stderr = '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, stderr', [
|
||||
('sudo npm install -g react-native-cli', stderr.format('npm')),
|
||||
('sudo -u app appcfg update .', stderr.format('appcfg'))])
|
||||
def test_match(script, stderr):
|
||||
assert match(Command(script, stderr=stderr))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script, stderr, which_result', [
|
||||
('npm --version', stderr.format('npm'), '/usr/bin/npm'),
|
||||
('sudo npm --version', '', '/usr/bin/npm'),
|
||||
('sudo npm --version', stderr.format('npm'), None)])
|
||||
def test_not_match(which, script, stderr, which_result):
|
||||
which.return_value = which_result
|
||||
assert not match(Command(script, stderr=stderr))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script, stderr, result', [
|
||||
('sudo npm install -g react-native-cli',
|
||||
stderr.format('npm'),
|
||||
'sudo env "PATH=$PATH" npm install -g react-native-cli'),
|
||||
('sudo -u app appcfg update .',
|
||||
stderr.format('appcfg'),
|
||||
'sudo -u app env "PATH=$PATH" appcfg update .')])
|
||||
def test_get_new_command(script, stderr, result):
|
||||
assert get_new_command(Command(script, stderr=stderr)) == result
|
||||
22
tests/rules/test_yarn_alias.py
Normal file
22
tests/rules/test_yarn_alias.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import pytest
|
||||
from thefuck.rules.yarn_alias import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
stderr_remove = 'error Did you mean `yarn remove`?'
|
||||
|
||||
stderr_list = 'error Did you mean `yarn list`?'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='yarn rm', stderr=stderr_remove),
|
||||
Command(script='yarn ls', stderr=stderr_list)])
|
||||
def test_match(command):
|
||||
assert match(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('yarn rm', stderr=stderr_remove), 'yarn remove'),
|
||||
(Command('yarn ls', stderr=stderr_list), 'yarn list')])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert get_new_command(command) == new_command
|
||||
111
tests/rules/test_yarn_command_not_found.py
Normal file
111
tests/rules/test_yarn_command_not_found.py
Normal file
@@ -0,0 +1,111 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
from io import BytesIO
|
||||
import pytest
|
||||
from tests.utils import Command
|
||||
from thefuck.rules.yarn_command_not_found import match, get_new_command
|
||||
|
||||
stderr = '''
|
||||
error Command "{}" not found.
|
||||
'''.format
|
||||
|
||||
yarn_help_stdout = b'''
|
||||
|
||||
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
|
||||
|
||||
Commands:
|
||||
|
||||
- access
|
||||
- add
|
||||
- bin
|
||||
- cache
|
||||
- check
|
||||
- clean
|
||||
- config
|
||||
- generate-lock-entry
|
||||
- global
|
||||
- import
|
||||
- info
|
||||
- init
|
||||
- install
|
||||
- licenses
|
||||
- link
|
||||
- list
|
||||
- login
|
||||
- logout
|
||||
- outdated
|
||||
- owner
|
||||
- pack
|
||||
- publish
|
||||
- remove
|
||||
- run
|
||||
- tag
|
||||
- team
|
||||
- unlink
|
||||
- upgrade
|
||||
- upgrade-interactive
|
||||
- version
|
||||
- versions
|
||||
- why
|
||||
|
||||
Run `yarn help COMMAND` for more information on specific commands.
|
||||
Visit https://yarnpkg.com/en/docs/cli/ to learn more about Yarn.
|
||||
'''
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def yarn_help(mocker):
|
||||
patch = mocker.patch('thefuck.rules.yarn_command_not_found.Popen')
|
||||
patch.return_value.stdout = BytesIO(yarn_help_stdout)
|
||||
return patch
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command('yarn whyy webpack', stderr=stderr('whyy'))])
|
||||
def test_match(command):
|
||||
assert match(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command('npm nuild', stderr=stderr('nuild')),
|
||||
Command('yarn install')])
|
||||
def test_not_match(command):
|
||||
assert not match(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, result', [
|
||||
(Command('yarn whyy webpack', stderr=stderr('whyy')), 'yarn why webpack')])
|
||||
def test_get_new_command(command, result):
|
||||
assert get_new_command(command)[0] == result
|
||||
@@ -56,3 +56,8 @@ class TestBash(object):
|
||||
def test_get_history(self, history_lines, shell):
|
||||
history_lines(['ls', 'rm'])
|
||||
assert list(shell.get_history()) == ['ls', 'rm']
|
||||
|
||||
def test_split_command(self, shell):
|
||||
command = 'git log -p'
|
||||
command_parts = ['git', 'log', '-p']
|
||||
assert shell.split_command(command) == command_parts
|
||||
|
||||
@@ -76,11 +76,11 @@ class TestFish(object):
|
||||
|
||||
def test_app_alias_alter_history(self, settings, shell):
|
||||
settings.alter_history = True
|
||||
assert 'history --delete' in shell.app_alias('FUCK')
|
||||
assert 'history --merge' in shell.app_alias('FUCK')
|
||||
assert 'builtin history delete' in shell.app_alias('FUCK')
|
||||
assert 'builtin history merge' in shell.app_alias('FUCK')
|
||||
settings.alter_history = False
|
||||
assert 'history --delete' not in shell.app_alias('FUCK')
|
||||
assert 'history --merge' not in shell.app_alias('FUCK')
|
||||
assert 'builtin history delete' not in shell.app_alias('FUCK')
|
||||
assert 'builtin history merge' not in shell.app_alias('FUCK')
|
||||
|
||||
def test_get_history(self, history_lines, shell):
|
||||
history_lines(['- cmd: ls', ' when: 1432613911',
|
||||
|
||||
Reference in New Issue
Block a user