mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-30 22:54:14 +00:00 
			
		
		
		
	Move all app/os specific utils to specific package
				
					
				
			This commit is contained in:
		| @@ -29,7 +29,7 @@ def test_match(command): | ||||
| @pytest.mark.parametrize('command, return_value', [ | ||||
|     (Command(script='vim', stderr='vim: command not found'), PKGFILE_OUTPUT_VIM), | ||||
|     (Command(script='sudo vim', stderr='sudo: vim: command not found'), PKGFILE_OUTPUT_VIM)]) | ||||
| @patch('thefuck.utils.subprocess') | ||||
| @patch('thefuck.specific.archlinux.subprocess') | ||||
| @patch.multiple(pacman, create=True, pacman=pacman_cmd) | ||||
| def test_match_mocked(subp_mock, command, return_value): | ||||
|     subp_mock.check_output.return_value = return_value | ||||
| @@ -75,7 +75,7 @@ def test_get_new_command(command, new_command, mocker): | ||||
|     (Command('convert'), ['{} -S extra/imagemagick && convert'.format(pacman_cmd)], PKGFILE_OUTPUT_CONVERT), | ||||
|     (Command('sudo'), ['{} -S core/sudo && sudo'.format(pacman_cmd)], PKGFILE_OUTPUT_SUDO), | ||||
|     (Command('sudo convert'), ['{} -S extra/imagemagick && sudo convert'.format(pacman_cmd)], PKGFILE_OUTPUT_CONVERT)]) | ||||
| @patch('thefuck.utils.subprocess') | ||||
| @patch('thefuck.specific.archlinux.subprocess') | ||||
| @patch.multiple(pacman, create=True, pacman=pacman_cmd) | ||||
| def test_get_new_command_mocked(subp_mock, command, new_command, return_value): | ||||
|     subp_mock.check_output.return_value = return_value | ||||
|   | ||||
| @@ -22,7 +22,7 @@ def test_match(command): | ||||
|     Command(script='yaourt -S llc', stderr='error: target not found: llc'), | ||||
|     Command(script='pacman llc', stderr='error: target not found: llc'), | ||||
|     Command(script='sudo pacman llc', stderr='error: target not found: llc')]) | ||||
| @patch('thefuck.utils.subprocess') | ||||
| @patch('thefuck.specific.archlinux.subprocess') | ||||
| def test_match_mocked(subp_mock, command): | ||||
|     subp_mock.check_output.return_value = PKGFILE_OUTPUT_LLC | ||||
|     assert match(command, None) | ||||
| @@ -42,7 +42,7 @@ def test_get_new_command(command, fixed): | ||||
|     (Command(script='yaourt -S llc', stderr='error: target not found: llc'), ['yaourt -S extra/llvm', 'yaourt -S extra/llvm35']), | ||||
|     (Command(script='pacman -S llc', stderr='error: target not found: llc'), ['pacman -S extra/llvm', 'pacman -S extra/llvm35']), | ||||
|     (Command(script='sudo pacman -S llc', stderr='error: target not found: llc'), ['sudo pacman -S extra/llvm', 'sudo pacman -S extra/llvm35'])]) | ||||
| @patch('thefuck.utils.subprocess') | ||||
| @patch('thefuck.specific.archlinux.subprocess') | ||||
| def test_get_new_command_mocked(subp_mock, command, fixed): | ||||
|     subp_mock.check_output.return_value = PKGFILE_OUTPUT_LLC | ||||
|     assert get_new_command(command, None) == fixed | ||||
|   | ||||
							
								
								
									
										0
									
								
								tests/specific/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/specific/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										29
									
								
								tests/specific/test_git.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								tests/specific/test_git.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| import pytest | ||||
| from thefuck.specific.git import git_support | ||||
| from tests.utils import Command | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('called, command, stderr', [ | ||||
|     ('git co', 'git checkout', "19:22:36.299340 git.c:282   trace: alias expansion: co => 'checkout'"), | ||||
|     ('git com file', 'git commit --verbose file', | ||||
|      "19:23:25.470911 git.c:282   trace: alias expansion: com => 'commit' '--verbose'")]) | ||||
| def test_git_support(called, command, stderr): | ||||
|     @git_support | ||||
|     def fn(command, settings): return command.script | ||||
|  | ||||
|     assert fn(Command(script=called, stderr=stderr), None) == command | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('command, is_git', [ | ||||
|     ('git pull', True), | ||||
|     ('hub pull', True), | ||||
|     ('git push --set-upstream origin foo', True), | ||||
|     ('hub push --set-upstream origin foo', True), | ||||
|     ('ls', False), | ||||
|     ('cat git', False), | ||||
|     ('cat hub', False)]) | ||||
| def test_git_support_match(command, is_git): | ||||
|     @git_support | ||||
|     def fn(command, settings): return True | ||||
|  | ||||
|     assert fn(Command(script=command), None) == is_git | ||||
							
								
								
									
										18
									
								
								tests/specific/test_sudo.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								tests/specific/test_sudo.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| import pytest | ||||
| from mock import Mock | ||||
| from thefuck.specific.sudo import sudo_support | ||||
| from tests.utils import Command | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('return_value, command, called, result', [ | ||||
|     ('ls -lah', 'sudo ls', 'ls', 'sudo ls -lah'), | ||||
|     ('ls -lah', 'ls', 'ls', 'ls -lah'), | ||||
|     (['ls -lah'], 'sudo ls', 'ls', ['sudo ls -lah']), | ||||
|     (True, 'sudo ls', 'ls', True), | ||||
|     (True, 'ls', 'ls', True), | ||||
|     (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__='') | ||||
|     assert sudo_support(fn)(Command(command), None) == result | ||||
|     fn.assert_called_once_with(Command(called), None) | ||||
| @@ -1,10 +1,9 @@ | ||||
| import pytest | ||||
| from mock import Mock | ||||
| from thefuck.utils import git_support, sudo_support, wrap_settings,\ | ||||
| from thefuck.utils import wrap_settings,\ | ||||
|     memoize, get_closest, get_all_executables, replace_argument, \ | ||||
|     get_all_matched_commands | ||||
| from thefuck.types import Settings | ||||
| from tests.utils import Command | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('override, old, new', [ | ||||
| @@ -16,43 +15,6 @@ def test_wrap_settings(override, old, new): | ||||
|     assert wrap_settings(override)(fn)(None, Settings(old)) == new | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('return_value, command, called, result', [ | ||||
|     ('ls -lah', 'sudo ls', 'ls', 'sudo ls -lah'), | ||||
|     ('ls -lah', 'ls', 'ls', 'ls -lah'), | ||||
|     (['ls -lah'], 'sudo ls', 'ls', ['sudo ls -lah']), | ||||
|     (True, 'sudo ls', 'ls', True), | ||||
|     (True, 'ls', 'ls', True), | ||||
|     (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__='') | ||||
|     assert sudo_support(fn)(Command(command), None) == result | ||||
|     fn.assert_called_once_with(Command(called), None) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('called, command, stderr', [ | ||||
|     ('git co', 'git checkout', "19:22:36.299340 git.c:282   trace: alias expansion: co => 'checkout'"), | ||||
|     ('git com file', 'git commit --verbose file', "19:23:25.470911 git.c:282   trace: alias expansion: com => 'commit' '--verbose'")]) | ||||
| def test_git_support(called, command, stderr): | ||||
|     @git_support | ||||
|     def fn(command, settings): return command.script | ||||
|     assert fn(Command(script=called, stderr=stderr), None) == command | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('command, is_git', [ | ||||
|     ('git pull', True), | ||||
|     ('hub pull', True), | ||||
|     ('git push --set-upstream origin foo', True), | ||||
|     ('hub push --set-upstream origin foo', True), | ||||
|     ('ls', False), | ||||
|     ('cat git', False), | ||||
|     ('cat hub', False)]) | ||||
| def test_git_support_match(command, is_git): | ||||
|     @git_support | ||||
|     def fn(command, settings): return True | ||||
|     assert fn(Command(script=command), None) == is_git | ||||
|  | ||||
|  | ||||
| def test_memoize(): | ||||
|     fn = Mock(__name__='fn') | ||||
|     memoized = memoize(fn) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user