mirror of
https://github.com/nvbn/thefuck.git
synced 2025-09-18 19:22:32 +01:00
#154 Add ability to override priority in settings
This commit is contained in:
@@ -40,12 +40,14 @@ class TestSettingsFromFile(object):
|
||||
load_source.return_value = Mock(rules=['test'],
|
||||
wait_command=10,
|
||||
require_confirmation=True,
|
||||
no_colors=True)
|
||||
no_colors=True,
|
||||
priority={'vim': 100})
|
||||
settings = conf.get_settings(Mock())
|
||||
assert settings.rules == ['test']
|
||||
assert settings.wait_command == 10
|
||||
assert settings.require_confirmation is True
|
||||
assert settings.no_colors is True
|
||||
assert settings.priority == {'vim': 100}
|
||||
|
||||
def test_from_file_with_DEFAULT(self, load_source):
|
||||
load_source.return_value = Mock(rules=conf.DEFAULT_RULES + ['test'],
|
||||
@@ -62,12 +64,14 @@ class TestSettingsFromEnv(object):
|
||||
environ.update({'THEFUCK_RULES': 'bash:lisp',
|
||||
'THEFUCK_WAIT_COMMAND': '55',
|
||||
'THEFUCK_REQUIRE_CONFIRMATION': 'true',
|
||||
'THEFUCK_NO_COLORS': 'false'})
|
||||
'THEFUCK_NO_COLORS': 'false',
|
||||
'THEFUCK_PRIORITY': 'bash=10:lisp=wrong:vim=15'})
|
||||
settings = conf.get_settings(Mock())
|
||||
assert settings.rules == ['bash', 'lisp']
|
||||
assert settings.wait_command == 55
|
||||
assert settings.require_confirmation is True
|
||||
assert settings.no_colors is False
|
||||
assert settings.priority == {'bash': 10, 'vim': 15}
|
||||
|
||||
def test_from_env_with_DEFAULT(self, environ):
|
||||
environ.update({'THEFUCK_RULES': 'DEFAULT_RULES:bash:lisp'})
|
||||
|
@@ -38,17 +38,25 @@ class TestGetRules(object):
|
||||
monkeypatch.setattr('thefuck.main.load_source',
|
||||
lambda x, _: Rule(x))
|
||||
assert self._compare_names(
|
||||
main.get_rules(Path('~'), Mock(rules=conf_rules)), rules)
|
||||
main.get_rules(Path('~'), Mock(rules=conf_rules, priority={})),
|
||||
rules)
|
||||
|
||||
@pytest.mark.parametrize('unordered, ordered', [
|
||||
([Rule('bash', priority=100), Rule('python', priority=5)],
|
||||
@pytest.mark.parametrize('priority, unordered, ordered', [
|
||||
({},
|
||||
[Rule('bash', priority=100), Rule('python', priority=5)],
|
||||
['python', 'bash']),
|
||||
([Rule('lisp', priority=9999), Rule('c', priority=conf.DEFAULT_PRIORITY)],
|
||||
['c', 'lisp'])])
|
||||
def test_ordered_by_priority(self, monkeypatch, unordered, ordered):
|
||||
({},
|
||||
[Rule('lisp', priority=9999), Rule('c', priority=conf.DEFAULT_PRIORITY)],
|
||||
['c', 'lisp']),
|
||||
({'python': 9999},
|
||||
[Rule('bash', priority=100), Rule('python', priority=5)],
|
||||
['bash', 'python'])])
|
||||
def test_ordered_by_priority(self, monkeypatch, priority, unordered, ordered):
|
||||
monkeypatch.setattr('thefuck.main._get_loaded_rules',
|
||||
lambda *_: unordered)
|
||||
assert self._compare_names(main.get_rules(Path('~'), Mock()), ordered)
|
||||
assert self._compare_names(
|
||||
main.get_rules(Path('~'), Mock(priority=priority)),
|
||||
ordered)
|
||||
|
||||
|
||||
class TestGetCommand(object):
|
||||
|
Reference in New Issue
Block a user