1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-09-19 11:42:33 +01:00

Refine tests

This commit is contained in:
nvbn
2015-05-02 04:29:55 +02:00
parent ba601644d6
commit dd1861955c
4 changed files with 237 additions and 191 deletions

View File

@@ -1,26 +1,26 @@
import pytest
from mock import Mock
from thefuck.utils import sudo_support, wrap_settings
from thefuck.types import Settings
from tests.utils import Command
def test_wrap_settings():
@pytest.mark.parametrize('override, old, new', [
({'key': 'val'}, {}, {'key': 'val'}),
({'key': 'new-val'}, {'key': 'val'}, {'key': 'new-val'})])
def test_wrap_settings(override, old, new):
fn = lambda _, settings: settings
assert wrap_settings({'key': 'val'})(fn)(None, Settings({})) \
== {'key': 'val'}
assert wrap_settings({'key': 'new-val'})(fn)(
None, Settings({'key': 'val'})) == {'key': 'new-val'}
assert wrap_settings(override)(fn)(None, Settings(old)) == new
def test_sudo_support():
fn = Mock(return_value=True, __name__='')
assert sudo_support(fn)(Command('sudo ls'), None)
fn.assert_called_once_with(Command('ls'), None)
fn.return_value = False
assert not sudo_support(fn)(Command('sudo ls'), None)
fn.return_value = 'pwd'
assert sudo_support(fn)(Command('sudo ls'), None) == 'sudo pwd'
assert sudo_support(fn)(Command('ls'), None) == 'pwd'
@pytest.mark.parametrize('return_value, command, called, result', [
('ls -lah', 'sudo ls', 'ls', 'sudo ls -lah'),
('ls -lah', 'ls', 'ls', 'ls -lah'),
(True, 'sudo ls', 'ls', True),
(True, 'ls', 'ls', True),
(False, 'sudo ls', 'ls', False),
(False, 'ls', 'ls', False)])
def test_sudo_support(return_value, command, called, result):
fn = Mock(return_value=return_value, __name__='')
assert sudo_support(fn)(Command(command), None) == result
fn.assert_called_once_with(Command(called), None)