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-22 23:04:22 +02:00
|
|
|
from thefuck.types import Command, Settings
|
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__='')
|
|
|
|
assert sudo_support(fn)(Command('sudo ls', 'out', 'err'), None)
|
|
|
|
fn.assert_called_once_with(Command('ls', 'out', 'err'), None)
|
|
|
|
|
|
|
|
fn.return_value = False
|
|
|
|
assert not sudo_support(fn)(Command('sudo ls', 'out', 'err'), None)
|
|
|
|
|
|
|
|
fn.return_value = 'pwd'
|
|
|
|
assert sudo_support(fn)(Command('sudo ls', 'out', 'err'), None) == 'sudo pwd'
|
|
|
|
|
|
|
|
assert sudo_support(fn)(Command('ls', 'out', 'err'), None) == 'pwd'
|