1
0
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:
nvbn 2015-04-25 02:54:39 +02:00
parent b7cb407637
commit 698451f65d
6 changed files with 85 additions and 56 deletions

View File

@ -1,19 +1,25 @@
from mock import Mock import pytest
from thefuck.rules.cd_mkdir import match, get_new_command from thefuck.rules.cd_mkdir import match, get_new_command
from tests.utils import Command
def test_match(): @pytest.mark.parametrize('command', [
assert match(Mock(script='cd foo', stderr='cd: foo: No such file or directory'), Command(script='cd foo', stderr='cd: foo: No such file or directory'),
None) Command(script='cd foo/bar/baz',
assert match(Mock(script='cd foo/bar/baz', stderr='cd: foo: No such file or directory'), stderr='cd: foo: No such file or directory'),
None) Command(script='cd foo/bar/baz', stderr='cd: can\'t cd to foo/bar/baz')])
assert match(Mock(script='cd foo/bar/baz', stderr='cd: can\'t cd to foo/bar/baz'), def test_match(command):
None) assert match(command, None)
assert not match(Mock(script='cd foo',
stderr=''), None)
assert not match(Mock(script='', stderr=''), None)
def test_get_new_command(): @pytest.mark.parametrize('command', [
assert get_new_command(Mock(script='cd foo'), None) == 'mkdir -p foo && cd foo' Command(script='cd foo', stderr=''), Command()])
assert get_new_command(Mock(script='cd foo/bar/baz'), None) == 'mkdir -p foo/bar/baz && cd foo/bar/baz' 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

View File

@ -1,3 +1,4 @@
import pytest
from thefuck.rules.mkdir_p import match, get_new_command from thefuck.rules.mkdir_p import match, get_new_command
from tests.utils import Command from tests.utils import Command
@ -6,9 +7,14 @@ def test_match():
assert match(Command('mkdir foo/bar/baz', assert match(Command('mkdir foo/bar/baz',
stderr='mkdir: foo/bar: No such file or directory'), stderr='mkdir: foo/bar: No such file or directory'),
None) 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(): def test_get_new_command():

View File

@ -1,13 +1,20 @@
import pytest
from thefuck.rules.rm_dir import match, get_new_command from thefuck.rules.rm_dir import match, get_new_command
from tests.utils import Command from tests.utils import Command
def test_match(): @pytest.mark.parametrize('command', [
assert match(Command('rm foo', stderr='rm: foo: is a directory'), None) Command('rm foo', stderr='rm: foo: is a directory'),
assert match(Command('rm foo', stderr='rm: foo: Is a directory'), None) Command('rm foo', stderr='rm: foo: Is a directory')])
assert not match(Command('rm foo'), None) def test_match(command):
assert not match(Command('rm foo', stderr='foo bar baz'), None) assert match(command, None)
assert not 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(): def test_get_new_command():

View File

@ -1,18 +1,21 @@
from mock import Mock import pytest
from thefuck.rules.rm_root import match, get_new_command from thefuck.rules.rm_root import match, get_new_command
from tests.utils import Command
def test_match(): def test_match():
assert match(Mock(script='rm -rf /', assert match(Command(script='rm -rf /',
stderr='add --no-preserve-root'), None) 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 /', @pytest.mark.parametrize('command', [
stderr='add --no-preserve-root'), None) Command(script='ls', stderr='add --no-preserve-root'),
assert not match(Mock(script='rm -rf /', Command(script='rm --no-preserve-root /', stderr='add --no-preserve-root'),
stderr=''), None) Command(script='rm -rf /', stderr='')])
def test_not_match(command):
assert not match(command, None)
def test_get_new_command(): 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' == 'rm -rf / --no-preserve-root'

View File

@ -1,11 +1,16 @@
import pytest
from thefuck.rules.sudo import match, get_new_command from thefuck.rules.sudo import match, get_new_command
from tests.utils import Command from tests.utils import Command
def test_match(): @pytest.mark.parametrize('stderr', ['Permission denied',
assert match(Command(stderr='Permission denied'), None) 'permission denied',
assert match(Command(stderr='permission denied'), None) "npm ERR! Error: EACCES, unlink"])
assert match(Command(stderr="npm ERR! Error: EACCES, unlink"), None) def test_match(stderr):
assert match(Command(stderr=stderr), None)
def test_not_match():
assert not match(Command(), None) assert not match(Command(), None)

View File

@ -1,25 +1,27 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
from mock import Mock import pytest
from thefuck.rules import switch_lang from thefuck.rules import switch_lang
from tests.utils import Command
def test_match(): @pytest.mark.parametrize('command', [
assert switch_lang.match(Mock(stderr='command not found: фзе-пуе', Command(stderr='command not found: фзе-пуе', script=u'фзе-пуе'),
script=u'фзе-пуе'), None) Command(stderr='command not found: λσ', script=u'λσ')])
assert switch_lang.match(Mock(stderr='command not found: λσ', def test_match(command):
script=u'λσ'), None) assert switch_lang.match(command, 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)
def test_get_new_command(): @pytest.mark.parametrize('command', [
assert switch_lang.get_new_command( Command(stderr='command not found: pat-get', script=u'pat-get'),
Mock(script=u'фзе-пуе штыефдд мшь'), None) == 'apt-get install vim' Command(stderr='command not found: ls', script=u'ls'),
assert switch_lang.get_new_command( Command(stderr='some info', script=u'фзе-пуе')])
Mock(script=u'λσ -λα'), None) == 'ls -la' 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