mirror of
https://github.com/nvbn/thefuck.git
synced 2025-09-18 19:22:32 +01:00
Fix tests
This commit is contained in:
@@ -16,7 +16,7 @@ def test_load_rule(mocker):
|
||||
enabled_by_default=True,
|
||||
priority=900,
|
||||
requires_output=True))
|
||||
assert corrector.load_rule(Path('/rules/bash.py'), settings=Mock(priority={})) \
|
||||
assert corrector.load_rule(Path('/rules/bash.py')) \
|
||||
== Rule('bash', match, get_new_command, priority=900)
|
||||
load_source.assert_called_once_with('bash', '/rules/bash.py')
|
||||
|
||||
@@ -48,29 +48,30 @@ class TestGetRules(object):
|
||||
(['git.py', 'bash.py'], ['git'], [], ['git']),
|
||||
(['git.py', 'bash.py'], conf.DEFAULT_RULES, ['git'], ['bash']),
|
||||
(['git.py', 'bash.py'], ['git'], ['git'], [])])
|
||||
def test_get_rules(self, glob, paths, conf_rules, exclude_rules, loaded_rules):
|
||||
def test_get_rules(self, glob, settings, paths, conf_rules, exclude_rules,
|
||||
loaded_rules):
|
||||
glob([PosixPath(path) for path in paths])
|
||||
settings = Mock(rules=self._prepare_rules(conf_rules),
|
||||
settings.update(rules=self._prepare_rules(conf_rules),
|
||||
priority={},
|
||||
exclude_rules=self._prepare_rules(exclude_rules))
|
||||
rules = corrector.get_rules(Path('~'), settings)
|
||||
rules = corrector.get_rules(Path('~'))
|
||||
self._compare_names(rules, loaded_rules)
|
||||
|
||||
|
||||
class TestIsRuleMatch(object):
|
||||
def test_no_match(self, settings):
|
||||
def test_no_match(self):
|
||||
assert not corrector.is_rule_match(
|
||||
Command('ls'), Rule('', lambda *_: False), settings)
|
||||
Command('ls'), Rule('', lambda *_: False))
|
||||
|
||||
def test_match(self, settings):
|
||||
def test_match(self):
|
||||
rule = Rule('', lambda x, _: x.script == 'cd ..')
|
||||
assert corrector.is_rule_match(Command('cd ..'), rule, settings)
|
||||
assert corrector.is_rule_match(Command('cd ..'), rule)
|
||||
|
||||
def test_when_rule_failed(self, capsys, settings):
|
||||
@pytest.mark.usefixtures('no_colors')
|
||||
def test_when_rule_failed(self, capsys):
|
||||
rule = Rule('test', Mock(side_effect=OSError('Denied')),
|
||||
requires_output=False)
|
||||
assert not corrector.is_rule_match(
|
||||
Command('ls'), rule, settings)
|
||||
assert not corrector.is_rule_match(Command('ls'), rule)
|
||||
assert capsys.readouterr()[1].split('\n')[0] == '[WARN] Rule test:'
|
||||
|
||||
|
||||
@@ -78,14 +79,14 @@ class TestMakeCorrectedCommands(object):
|
||||
def test_with_rule_returns_list(self):
|
||||
rule = Rule(get_new_command=lambda x, _: [x.script + '!', x.script + '@'],
|
||||
priority=100)
|
||||
assert list(make_corrected_commands(Command(script='test'), rule, None)) \
|
||||
assert list(make_corrected_commands(Command(script='test'), rule)) \
|
||||
== [CorrectedCommand(script='test!', priority=100),
|
||||
CorrectedCommand(script='test@', priority=200)]
|
||||
|
||||
def test_with_rule_returns_command(self):
|
||||
rule = Rule(get_new_command=lambda x, _: x.script + '!',
|
||||
priority=100)
|
||||
assert list(make_corrected_commands(Command(script='test'), rule, None)) \
|
||||
assert list(make_corrected_commands(Command(script='test'), rule)) \
|
||||
== [CorrectedCommand(script='test!', priority=100)]
|
||||
|
||||
def test_get_corrected_commands(mocker):
|
||||
@@ -97,5 +98,5 @@ def test_get_corrected_commands(mocker):
|
||||
get_new_command=lambda x, _: [x.script + '@', x.script + ';'],
|
||||
priority=60)]
|
||||
mocker.patch('thefuck.corrector.get_rules', return_value=rules)
|
||||
assert [cmd.script for cmd in get_corrected_commands(command, None, Mock(debug=False))] \
|
||||
assert [cmd.script for cmd in get_corrected_commands(command, None)] \
|
||||
== ['test!', 'test@', 'test;']
|
||||
|
Reference in New Issue
Block a user