mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 15:12:20 +00:00 
			
		
		
		
	Merge branch 'master' of github.com:nvbn/thefuck into slow
This commit is contained in:
		| @@ -1,6 +1,12 @@ | ||||
| import pytest | ||||
| from mock import Mock | ||||
|  | ||||
|  | ||||
| @pytest.fixture | ||||
| def no_memoize(monkeypatch): | ||||
|     monkeypatch.setattr('thefuck.utils.memoize.disabled', True) | ||||
|  | ||||
|  | ||||
| @pytest.fixture | ||||
| def settings(): | ||||
|     return Mock(debug=False, no_colors=True) | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| import pytest | ||||
| from mock import Mock | ||||
| from thefuck.rules.lein_not_task import match, get_new_command | ||||
| from tests.utils import Command | ||||
|  | ||||
|  | ||||
| @pytest.fixture | ||||
| @@ -14,10 +14,10 @@ Did you mean this? | ||||
|  | ||||
|  | ||||
| def test_match(is_not_task): | ||||
|     assert match(Mock(script='lein rpl', stderr=is_not_task), None) | ||||
|     assert not match(Mock(script='ls', stderr=is_not_task), None) | ||||
|     assert match(Command(script='lein rpl', stderr=is_not_task), None) | ||||
|     assert not match(Command(script='ls', stderr=is_not_task), None) | ||||
|  | ||||
|  | ||||
| def test_get_new_command(is_not_task): | ||||
|     assert get_new_command(Mock(script='lein rpl --help', stderr=is_not_task), | ||||
|     assert get_new_command(Command(script='lein rpl --help', stderr=is_not_task), | ||||
|                            None) == ['lein repl --help', 'lein jar --help'] | ||||
|   | ||||
| @@ -1,16 +1,16 @@ | ||||
| from mock import patch, Mock | ||||
| from thefuck.rules.ls_lah import match, get_new_command | ||||
| from tests.utils import Command | ||||
|  | ||||
|  | ||||
| def test_match(): | ||||
|     assert match(Mock(script='ls'), None) | ||||
|     assert match(Mock(script='ls file.py'), None) | ||||
|     assert match(Mock(script='ls /opt'), None) | ||||
|     assert not match(Mock(script='ls -lah /opt'), None) | ||||
|     assert not match(Mock(script='pacman -S binutils'), None) | ||||
|     assert not match(Mock(script='lsof'), None) | ||||
|     assert match(Command(script='ls'), None) | ||||
|     assert match(Command(script='ls file.py'), None) | ||||
|     assert match(Command(script='ls /opt'), None) | ||||
|     assert not match(Command(script='ls -lah /opt'), None) | ||||
|     assert not match(Command(script='pacman -S binutils'), None) | ||||
|     assert not match(Command(script='lsof'), None) | ||||
|  | ||||
|  | ||||
| def test_get_new_command(): | ||||
|     assert get_new_command(Mock(script='ls file.py'), None) == 'ls -lah file.py' | ||||
|     assert get_new_command(Mock(script='ls'), None) == 'ls -lah' | ||||
|     assert get_new_command(Command(script='ls file.py'), None) == 'ls -lah file.py' | ||||
|     assert get_new_command(Command(script='ls'), None) == 'ls -lah' | ||||
|   | ||||
							
								
								
									
										40
									
								
								tests/rules/test_mvn_no_command.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								tests/rules/test_mvn_no_command.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| import pytest | ||||
| from thefuck.rules.mvn_no_command import match, get_new_command | ||||
| from tests.utils import Command | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('command', [ | ||||
|     Command(script='mvn', stdout='[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]')]) | ||||
| def test_match(command): | ||||
|     assert match(command, None) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('command', [ | ||||
|     Command(script='mvn clean', stdout=""" | ||||
| [INFO] Scanning for projects...[INFO]                                                                          | ||||
| [INFO] ------------------------------------------------------------------------ | ||||
| [INFO] Building test 0.2 | ||||
| [INFO] ------------------------------------------------------------------------ | ||||
| [INFO]  | ||||
| [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ test --- | ||||
| [INFO] Deleting /home/mlk/code/test/target | ||||
| [INFO] ------------------------------------------------------------------------ | ||||
| [INFO] BUILD SUCCESS | ||||
| [INFO] ------------------------------------------------------------------------ | ||||
| [INFO] Total time: 0.477s | ||||
| [INFO] Finished at: Wed Aug 26 13:05:47 BST 2015 | ||||
| [INFO] Final Memory: 6M/240M | ||||
| [INFO] ------------------------------------------------------------------------ | ||||
| """), | ||||
|     Command(script='mvn --help'), | ||||
|     Command(script='mvn -v') | ||||
| ]) | ||||
| def test_not_match(command): | ||||
|     assert not match(command, None) | ||||
|  | ||||
| @pytest.mark.parametrize('command, new_command', [ | ||||
|     (Command(script='mvn', stdout='[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]'), ['mvn clean package', 'mvn clean install']), | ||||
|     (Command(script='mvn -N', stdout='[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]'), ['mvn -N clean package', 'mvn -N clean install'])]) | ||||
| def test_get_new_command(command, new_command): | ||||
|     assert get_new_command(command, None) == new_command | ||||
|  | ||||
							
								
								
									
										40
									
								
								tests/rules/test_mvn_unknown_lifecycle_phase.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								tests/rules/test_mvn_unknown_lifecycle_phase.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| import pytest | ||||
| from thefuck.rules.mvn_unknown_lifecycle_phase import match, get_new_command | ||||
| from tests.utils import Command | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('command', [ | ||||
|     Command(script='mvn cle', stdout='[ERROR] Unknown lifecycle phase "cle". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]')]) | ||||
| def test_match(command): | ||||
|     assert match(command, None) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('command', [ | ||||
|     Command(script='mvn clean', stdout=""" | ||||
| [INFO] Scanning for projects...[INFO]                                                                          | ||||
| [INFO] ------------------------------------------------------------------------ | ||||
| [INFO] Building test 0.2 | ||||
| [INFO] ------------------------------------------------------------------------ | ||||
| [INFO]  | ||||
| [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ test --- | ||||
| [INFO] Deleting /home/mlk/code/test/target | ||||
| [INFO] ------------------------------------------------------------------------ | ||||
| [INFO] BUILD SUCCESS | ||||
| [INFO] ------------------------------------------------------------------------ | ||||
| [INFO] Total time: 0.477s | ||||
| [INFO] Finished at: Wed Aug 26 13:05:47 BST 2015 | ||||
| [INFO] Final Memory: 6M/240M | ||||
| [INFO] ------------------------------------------------------------------------ | ||||
| """), | ||||
|     Command(script='mvn --help'), | ||||
|     Command(script='mvn -v') | ||||
| ]) | ||||
| def test_not_match(command): | ||||
|     assert not match(command, None) | ||||
|  | ||||
| @pytest.mark.parametrize('command, new_command', [ | ||||
|     (Command(script='mvn cle', stdout='[ERROR] Unknown lifecycle phase "cle". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]'), ['mvn clean', 'mvn compile']), | ||||
|     (Command(script='mvn claen package', stdout='[ERROR] Unknown lifecycle phase "claen". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]'), ['mvn clean package'])]) | ||||
| def test_get_new_command(command, new_command): | ||||
|     assert get_new_command(command, None) == new_command | ||||
|  | ||||
| @@ -13,6 +13,8 @@ from tests.utils import Command | ||||
|     (False, 'sudo ls', 'ls', False), | ||||
|     (False, 'ls', 'ls', False)]) | ||||
| def test_sudo_support(return_value, command, called, result): | ||||
|     fn = Mock(return_value=return_value, __name__='') | ||||
|     def fn(command, settings): | ||||
|         assert command == Command(called) | ||||
|         return return_value | ||||
|  | ||||
|     assert sudo_support(fn)(Command(command), None) == result | ||||
|     fn.assert_called_once_with(Command(called), None) | ||||
|   | ||||
| @@ -3,7 +3,7 @@ from pathlib import PosixPath, Path | ||||
| from mock import Mock | ||||
| from thefuck import corrector, conf, types | ||||
| from tests.utils import Rule, Command, CorrectedCommand | ||||
| from thefuck.corrector import make_corrected_commands, get_corrected_commands, remove_duplicates | ||||
| from thefuck.corrector import make_corrected_commands, get_corrected_commands | ||||
|  | ||||
|  | ||||
| def test_load_rule(mocker): | ||||
| @@ -75,15 +75,6 @@ class TestGetCorrectedCommands(object): | ||||
|                == [CorrectedCommand(script='test!', priority=100)] | ||||
|  | ||||
|  | ||||
| def test_remove_duplicates(): | ||||
|     side_effect = lambda *_: None | ||||
|     assert set(remove_duplicates([CorrectedCommand('ls', priority=100), | ||||
|                                   CorrectedCommand('ls', priority=200), | ||||
|                                   CorrectedCommand('ls', side_effect, 300)])) \ | ||||
|            == {CorrectedCommand('ls', priority=100), | ||||
|                CorrectedCommand('ls', side_effect, 300)} | ||||
|  | ||||
|  | ||||
| def test_get_corrected_commands(mocker): | ||||
|     command = Command('test', 'test', 'test') | ||||
|     rules = [Rule(match=lambda *_: False), | ||||
| @@ -94,4 +85,4 @@ def test_get_corrected_commands(mocker): | ||||
|                   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))] \ | ||||
|            == ['test@', 'test!', 'test;'] | ||||
|            == ['test!', 'test@', 'test;'] | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| from thefuck.types import RulesNamesList, Settings | ||||
| from tests.utils import Rule | ||||
| from thefuck.types import RulesNamesList, Settings, \ | ||||
|     SortedCorrectedCommandsSequence | ||||
| from tests.utils import Rule, CorrectedCommand | ||||
|  | ||||
|  | ||||
| def test_rules_names_list(): | ||||
| @@ -15,3 +16,44 @@ def test_update_settings(): | ||||
|     assert new_settings.key == 'val' | ||||
|     assert new_settings.unset == 'unset-value' | ||||
|     assert settings.key == 'val' | ||||
|  | ||||
|  | ||||
| class TestSortedCorrectedCommandsSequence(object): | ||||
|     def test_realises_generator_only_on_demand(self, settings): | ||||
|         should_realise = False | ||||
|  | ||||
|         def gen(): | ||||
|             nonlocal should_realise | ||||
|             yield CorrectedCommand('git commit') | ||||
|             yield CorrectedCommand('git branch', priority=200) | ||||
|             assert should_realise | ||||
|             yield CorrectedCommand('git checkout', priority=100) | ||||
|  | ||||
|         commands = SortedCorrectedCommandsSequence(gen(), settings) | ||||
|         assert commands[0] == CorrectedCommand('git commit') | ||||
|         should_realise = True | ||||
|         assert commands[1] == CorrectedCommand('git checkout', priority=100) | ||||
|         assert commands[2] == CorrectedCommand('git branch', priority=200) | ||||
|  | ||||
|     def test_remove_duplicates(self, settings): | ||||
|         side_effect = lambda *_: None | ||||
|         seq = SortedCorrectedCommandsSequence( | ||||
|             iter([CorrectedCommand('ls', priority=100), | ||||
|                   CorrectedCommand('ls', priority=200), | ||||
|                   CorrectedCommand('ls', side_effect, 300)]), | ||||
|             settings) | ||||
|         assert set(seq) == {CorrectedCommand('ls', priority=100), | ||||
|                             CorrectedCommand('ls', side_effect, 300)} | ||||
|  | ||||
|  | ||||
| class TestCorrectedCommand(object): | ||||
|  | ||||
|     def test_equality(self): | ||||
|         assert CorrectedCommand('ls', None, 100) == \ | ||||
|                CorrectedCommand('ls', None, 200) | ||||
|         assert CorrectedCommand('ls', None, 100) != \ | ||||
|                CorrectedCommand('ls', lambda *_: _, 100) | ||||
|  | ||||
|     def test_hashable(self): | ||||
|         assert {CorrectedCommand('ls', None, 100), | ||||
|                 CorrectedCommand('ls', None, 200)} == {CorrectedCommand('ls')} | ||||
|   | ||||
| @@ -4,7 +4,7 @@ from mock import Mock | ||||
| import pytest | ||||
| from itertools import islice | ||||
| from thefuck import ui | ||||
| from thefuck.types import CorrectedCommand | ||||
| from thefuck.types import CorrectedCommand, SortedCorrectedCommandsSequence | ||||
|  | ||||
|  | ||||
| @pytest.fixture | ||||
| @@ -58,14 +58,18 @@ def test_command_selector(): | ||||
|  | ||||
| class TestSelectCommand(object): | ||||
|     @pytest.fixture | ||||
|     def commands_with_side_effect(self): | ||||
|         return [CorrectedCommand('ls', lambda *_: None, 100), | ||||
|                 CorrectedCommand('cd', lambda *_: None, 100)] | ||||
|     def commands_with_side_effect(self, settings): | ||||
|         return SortedCorrectedCommandsSequence( | ||||
|             iter([CorrectedCommand('ls', lambda *_: None, 100), | ||||
|                   CorrectedCommand('cd', lambda *_: None, 100)]), | ||||
|             settings) | ||||
|  | ||||
|     @pytest.fixture | ||||
|     def commands(self): | ||||
|         return [CorrectedCommand('ls', None, 100), | ||||
|                 CorrectedCommand('cd', None, 100)] | ||||
|     def commands(self, settings): | ||||
|         return SortedCorrectedCommandsSequence( | ||||
|             iter([CorrectedCommand('ls', None, 100), | ||||
|                   CorrectedCommand('cd', None, 100)]), | ||||
|             settings) | ||||
|  | ||||
|     def test_without_commands(self, capsys): | ||||
|         assert ui.select_command([], Mock(debug=False, no_color=True)) is None | ||||
| @@ -92,13 +96,6 @@ class TestSelectCommand(object): | ||||
|                                       require_confirmation=True)) == commands[0] | ||||
|         assert capsys.readouterr() == ('', u'\x1b[1K\rls [enter/↑/↓/ctrl+c]\n') | ||||
|  | ||||
|     def test_with_confirmation_one_match(self, capsys, patch_getch, commands): | ||||
|         patch_getch(['\n']) | ||||
|         assert ui.select_command((commands[0],), | ||||
|                                  Mock(debug=False, no_color=True, | ||||
|                                       require_confirmation=True)) == commands[0] | ||||
|         assert capsys.readouterr() == ('', u'\x1b[1K\rls [enter/ctrl+c]\n') | ||||
|  | ||||
|     def test_with_confirmation_abort(self, capsys, patch_getch, commands): | ||||
|         patch_getch([KeyboardInterrupt]) | ||||
|         assert ui.select_command(commands, | ||||
|   | ||||
| @@ -2,8 +2,9 @@ import pytest | ||||
| from mock import Mock | ||||
| from thefuck.utils import wrap_settings,\ | ||||
|     memoize, get_closest, get_all_executables, replace_argument, \ | ||||
|     get_all_matched_commands | ||||
|     get_all_matched_commands, is_app, for_app | ||||
| from thefuck.types import Settings | ||||
| from tests.utils import Command | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('override, old, new', [ | ||||
| @@ -93,3 +94,25 @@ def test_replace_argument(args, result): | ||||
|                             'service-status', 'service-unbind'])]) | ||||
| def test_get_all_matched_commands(stderr, result): | ||||
|     assert list(get_all_matched_commands(stderr)) == result | ||||
|  | ||||
|  | ||||
| @pytest.mark.usefixtures('no_memoize') | ||||
| @pytest.mark.parametrize('script, names, result', [ | ||||
|     ('git diff', ['git', 'hub'], True), | ||||
|     ('hub diff', ['git', 'hub'], True), | ||||
|     ('hg diff', ['git', 'hub'], False)]) | ||||
| def test_is_app(script, names, result): | ||||
|     assert is_app(Command(script), *names) == result | ||||
|  | ||||
|  | ||||
| @pytest.mark.usefixtures('no_memoize') | ||||
| @pytest.mark.parametrize('script, names, result', [ | ||||
|     ('git diff', ['git', 'hub'], True), | ||||
|     ('hub diff', ['git', 'hub'], True), | ||||
|     ('hg diff', ['git', 'hub'], False)]) | ||||
| def test_for_app(script, names, result): | ||||
|     @for_app(*names) | ||||
|     def match(command, settings): | ||||
|         return True | ||||
|  | ||||
|     assert match(Command(script), None) == result | ||||
|   | ||||
		Reference in New Issue
	
	Block a user