mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-31 02:01:13 +00:00
Use parametrized tests where it possible
This commit is contained in:
parent
b7cb407637
commit
698451f65d
@ -1,19 +1,25 @@
|
||||
from mock import Mock
|
||||
import pytest
|
||||
from thefuck.rules.cd_mkdir import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
def test_match():
|
||||
assert match(Mock(script='cd foo', stderr='cd: foo: No such file or directory'),
|
||||
None)
|
||||
assert match(Mock(script='cd foo/bar/baz', stderr='cd: foo: No such file or directory'),
|
||||
None)
|
||||
assert match(Mock(script='cd foo/bar/baz', stderr='cd: can\'t cd to foo/bar/baz'),
|
||||
None)
|
||||
assert not match(Mock(script='cd foo',
|
||||
stderr=''), None)
|
||||
assert not match(Mock(script='', stderr=''), None)
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='cd foo', stderr='cd: foo: No such file or directory'),
|
||||
Command(script='cd foo/bar/baz',
|
||||
stderr='cd: foo: No such file or directory'),
|
||||
Command(script='cd foo/bar/baz', stderr='cd: can\'t cd to foo/bar/baz')])
|
||||
def test_match(command):
|
||||
assert match(command, None)
|
||||
|
||||
|
||||
def test_get_new_command():
|
||||
assert get_new_command(Mock(script='cd foo'), None) == 'mkdir -p foo && cd foo'
|
||||
assert get_new_command(Mock(script='cd foo/bar/baz'), None) == 'mkdir -p foo/bar/baz && cd foo/bar/baz'
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='cd foo', stderr=''), Command()])
|
||||
def test_not_match(command):
|
||||
assert not match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('cd foo'), 'mkdir -p foo && cd foo'),
|
||||
(Command('cd foo/bar/baz'), 'mkdir -p foo/bar/baz && cd foo/bar/baz')])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert get_new_command(command, None) == new_command
|
||||
|
@ -1,3 +1,4 @@
|
||||
import pytest
|
||||
from thefuck.rules.mkdir_p import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
@ -6,9 +7,14 @@ def test_match():
|
||||
assert match(Command('mkdir foo/bar/baz',
|
||||
stderr='mkdir: foo/bar: No such file or directory'),
|
||||
None)
|
||||
assert not match(Command('mkdir foo/bar/baz'), None)
|
||||
assert not match(Command('mkdir foo/bar/baz', stderr='foo bar baz'), None)
|
||||
assert not match(Command(), None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command('mkdir foo/bar/baz'),
|
||||
Command('mkdir foo/bar/baz', stderr='foo bar baz'),
|
||||
Command()])
|
||||
def test_not_match(command):
|
||||
assert not match(command, None)
|
||||
|
||||
|
||||
def test_get_new_command():
|
||||
|
@ -1,13 +1,20 @@
|
||||
import pytest
|
||||
from thefuck.rules.rm_dir import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
def test_match():
|
||||
assert match(Command('rm foo', stderr='rm: foo: is a directory'), None)
|
||||
assert match(Command('rm foo', stderr='rm: foo: Is a directory'), None)
|
||||
assert not match(Command('rm foo'), None)
|
||||
assert not match(Command('rm foo', stderr='foo bar baz'), None)
|
||||
assert not match(Command(), None)
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command('rm foo', stderr='rm: foo: is a directory'),
|
||||
Command('rm foo', stderr='rm: foo: Is a directory')])
|
||||
def test_match(command):
|
||||
assert match(command, None)
|
||||
assert match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command('rm foo'), Command('rm foo'), Command()])
|
||||
def test_not_match(command):
|
||||
assert not match(command, None)
|
||||
|
||||
|
||||
def test_get_new_command():
|
||||
|
@ -1,18 +1,21 @@
|
||||
from mock import Mock
|
||||
import pytest
|
||||
from thefuck.rules.rm_root import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
def test_match():
|
||||
assert match(Mock(script='rm -rf /',
|
||||
assert match(Command(script='rm -rf /',
|
||||
stderr='add --no-preserve-root'), None)
|
||||
assert not match(Mock(script='ls',
|
||||
stderr='add --no-preserve-root'), None)
|
||||
assert not match(Mock(script='rm --no-preserve-root /',
|
||||
stderr='add --no-preserve-root'), None)
|
||||
assert not match(Mock(script='rm -rf /',
|
||||
stderr=''), None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='ls', stderr='add --no-preserve-root'),
|
||||
Command(script='rm --no-preserve-root /', stderr='add --no-preserve-root'),
|
||||
Command(script='rm -rf /', stderr='')])
|
||||
def test_not_match(command):
|
||||
assert not match(command, None)
|
||||
|
||||
|
||||
def test_get_new_command():
|
||||
assert get_new_command(Mock(script='rm -rf /'), None) \
|
||||
assert get_new_command(Command(script='rm -rf /'), None) \
|
||||
== 'rm -rf / --no-preserve-root'
|
||||
|
@ -1,11 +1,16 @@
|
||||
import pytest
|
||||
from thefuck.rules.sudo import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
def test_match():
|
||||
assert match(Command(stderr='Permission denied'), None)
|
||||
assert match(Command(stderr='permission denied'), None)
|
||||
assert match(Command(stderr="npm ERR! Error: EACCES, unlink"), None)
|
||||
@pytest.mark.parametrize('stderr', ['Permission denied',
|
||||
'permission denied',
|
||||
"npm ERR! Error: EACCES, unlink"])
|
||||
def test_match(stderr):
|
||||
assert match(Command(stderr=stderr), None)
|
||||
|
||||
|
||||
def test_not_match():
|
||||
assert not match(Command(), None)
|
||||
|
||||
|
||||
|
@ -1,25 +1,27 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
from mock import Mock
|
||||
import pytest
|
||||
from thefuck.rules import switch_lang
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
def test_match():
|
||||
assert switch_lang.match(Mock(stderr='command not found: фзе-пуе',
|
||||
script=u'фзе-пуе'), None)
|
||||
assert switch_lang.match(Mock(stderr='command not found: λσ',
|
||||
script=u'λσ'), None)
|
||||
|
||||
assert not switch_lang.match(Mock(stderr='command not found: pat-get',
|
||||
script=u'pat-get'), None)
|
||||
assert not switch_lang.match(Mock(stderr='command not found: ls',
|
||||
script=u'ls'), None)
|
||||
assert not switch_lang.match(Mock(stderr='some info',
|
||||
script=u'фзе-пуе'), None)
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(stderr='command not found: фзе-пуе', script=u'фзе-пуе'),
|
||||
Command(stderr='command not found: λσ', script=u'λσ')])
|
||||
def test_match(command):
|
||||
assert switch_lang.match(command, None)
|
||||
|
||||
|
||||
def test_get_new_command():
|
||||
assert switch_lang.get_new_command(
|
||||
Mock(script=u'фзе-пуе штыефдд мшь'), None) == 'apt-get install vim'
|
||||
assert switch_lang.get_new_command(
|
||||
Mock(script=u'λσ -λα'), None) == 'ls -la'
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(stderr='command not found: pat-get', script=u'pat-get'),
|
||||
Command(stderr='command not found: ls', script=u'ls'),
|
||||
Command(stderr='some info', script=u'фзе-пуе')])
|
||||
def test_not_match(command):
|
||||
assert not switch_lang.match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command(u'фзе-пуе штыефдд мшь'), 'apt-get install vim'),
|
||||
(Command(u'λσ -λα'), 'ls -la')])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert switch_lang.get_new_command(command, None) == new_command
|
||||
|
Loading…
x
Reference in New Issue
Block a user