mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 15:12:20 +00:00 
			
		
		
		
	| @@ -8,14 +8,15 @@ from thefuck.types import Command | |||||||
| from thefuck.corrector import get_corrected_commands, organize_commands | from thefuck.corrector import get_corrected_commands, organize_commands | ||||||
|  |  | ||||||
|  |  | ||||||
| class TestGetRules(object): |  | ||||||
| @pytest.fixture | @pytest.fixture | ||||||
|     def glob(self, mocker): | def glob(mocker): | ||||||
|     results = {} |     results = {} | ||||||
|     mocker.patch('thefuck.system.Path.glob', |     mocker.patch('thefuck.system.Path.glob', | ||||||
|                  new_callable=lambda: lambda *_: results.pop('value', [])) |                  new_callable=lambda: lambda *_: results.pop('value', [])) | ||||||
|     return lambda value: results.update({'value': value}) |     return lambda value: results.update({'value': value}) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class TestGetRules(object): | ||||||
|     @pytest.fixture(autouse=True) |     @pytest.fixture(autouse=True) | ||||||
|     def load_source(self, monkeypatch): |     def load_source(self, monkeypatch): | ||||||
|         monkeypatch.setattr('thefuck.types.load_source', |         monkeypatch.setattr('thefuck.types.load_source', | ||||||
| @@ -39,6 +40,14 @@ class TestGetRules(object): | |||||||
|         self._compare_names(rules, loaded_rules) |         self._compare_names(rules, loaded_rules) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 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') | ||||||
|  |  | ||||||
|  |  | ||||||
| def test_get_corrected_commands(mocker): | def test_get_corrected_commands(mocker): | ||||||
|     command = Command('test', 'test') |     command = Command('test', 'test') | ||||||
|     rules = [Rule(match=lambda _: False), |     rules = [Rule(match=lambda _: False), | ||||||
|   | |||||||
| @@ -45,6 +45,12 @@ class TestCorrectedCommand(object): | |||||||
|  |  | ||||||
|  |  | ||||||
| class TestRule(object): | class TestRule(object): | ||||||
|  |     def test_from_path_rule_exception(self, mocker): | ||||||
|  |         load_source = mocker.patch('thefuck.types.load_source', | ||||||
|  |                                    side_effect=ImportError("No module named foo...")) | ||||||
|  |         assert Rule.from_path(Path('git.py')) is None | ||||||
|  |         load_source.assert_called_once_with('git', 'git.py') | ||||||
|  |  | ||||||
|     def test_from_path(self, mocker): |     def test_from_path(self, mocker): | ||||||
|         match = object() |         match = object() | ||||||
|         get_new_command = object() |         get_new_command = object() | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ def get_loaded_rules(rules_paths): | |||||||
|     for path in rules_paths: |     for path in rules_paths: | ||||||
|         if path.name != '__init__.py': |         if path.name != '__init__.py': | ||||||
|             rule = Rule.from_path(path) |             rule = Rule.from_path(path) | ||||||
|             if rule.is_enabled: |             if rule and rule.is_enabled: | ||||||
|                 yield rule |                 yield rule | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -137,7 +137,11 @@ class Rule(object): | |||||||
|         """ |         """ | ||||||
|         name = path.name[:-3] |         name = path.name[:-3] | ||||||
|         with logs.debug_time(u'Importing rule: {};'.format(name)): |         with logs.debug_time(u'Importing rule: {};'.format(name)): | ||||||
|  |             try: | ||||||
|                 rule_module = load_source(name, str(path)) |                 rule_module = load_source(name, str(path)) | ||||||
|  |             except Exception: | ||||||
|  |                 logs.exception(u"Rule {} failed to load".format(name), sys.exc_info()) | ||||||
|  |                 return | ||||||
|         priority = getattr(rule_module, 'priority', DEFAULT_PRIORITY) |         priority = getattr(rule_module, 'priority', DEFAULT_PRIORITY) | ||||||
|         return cls(name, rule_module.match, |         return cls(name, rule_module.match, | ||||||
|                    rule_module.get_new_command, |                    rule_module.get_new_command, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user