2015-04-22 16:45:38 +02:00
|
|
|
from mock import Mock
|
2015-04-22 20:18:53 +02:00
|
|
|
from thefuck.utils import sudo_support, wrap_settings
|
2015-04-25 02:35:26 +02:00
|
|
|
from thefuck.types import Settings
|
|
|
|
from tests.utils import Command
|
2015-04-22 20:18:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_wrap_settings():
|
2015-04-22 23:04:22 +02:00
|
|
|
fn = lambda _, settings: settings
|
2015-04-22 22:29:23 +02:00
|
|
|
assert wrap_settings({'key': 'val'})(fn)(None, Settings({})) \
|
2015-04-22 20:18:53 +02:00
|
|
|
== {'key': 'val'}
|
|
|
|
assert wrap_settings({'key': 'new-val'})(fn)(
|
2015-04-22 22:29:23 +02:00
|
|
|
None, Settings({'key': 'val'})) == {'key': 'new-val'}
|
2015-04-22 16:45:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_sudo_support():
|
|
|
|
fn = Mock(return_value=True, __name__='')
|
2015-04-25 02:35:26 +02:00
|
|
|
assert sudo_support(fn)(Command('sudo ls'), None)
|
|
|
|
fn.assert_called_once_with(Command('ls'), None)
|
2015-04-22 16:45:38 +02:00
|
|
|
|
|
|
|
fn.return_value = False
|
2015-04-25 02:35:26 +02:00
|
|
|
assert not sudo_support(fn)(Command('sudo ls'), None)
|
2015-04-22 16:45:38 +02:00
|
|
|
|
|
|
|
fn.return_value = 'pwd'
|
2015-04-25 02:35:26 +02:00
|
|
|
assert sudo_support(fn)(Command('sudo ls'), None) == 'sudo pwd'
|
2015-04-22 16:45:38 +02:00
|
|
|
|
2015-04-25 02:35:26 +02:00
|
|
|
assert sudo_support(fn)(Command('ls'), None) == 'pwd'
|