def test_get(self, monkeypatch, glob, conf_rules, rules): glob.return_value = [PosixPath('bash.py'), PosixPath('lisp.py')] monkeypatch.setattr('thefuck.corrector.load_source', lambda x, _: Rule(x)) assert self._compare_names( corrector.get_rules(Path('~'), Mock(rules=conf_rules, priority={})), rules)
def test_get_rules(self, glob, settings, paths, conf_rules, exclude_rules, loaded_rules): glob([Path(path) for path in paths]) settings.update(rules=conf_rules, priority={}, exclude_rules=exclude_rules) rules = corrector.get_rules() self._compare_names(rules, loaded_rules)
def get_new_command(command): script = command.script[5:] output = command.output newCommand = Command(script, output) corrected_commands = list( corrected for rule in get_rules() if rule.is_match(newCommand) for corrected in rule.get_corrected_commands(newCommand)) if len(corrected_commands) > 0: return [ cc.script if cc.script[:4] == 'sudo' else u'sudo ' + str(cc.script) for cc in corrected_commands ] else: return []
def test_get_rules_rule_exception(mocker, glob): load_source = mocker.patch('thefuck.types.load_source', side_effect=ImportError("No module named foo...")) glob([Path('git.py')]) assert not corrector.get_rules() load_source.assert_called_once_with('git', 'git.py')