mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-30 22:54:14 +00:00 
			
		
		
		
	| @@ -7,6 +7,18 @@ from tests.utils import Command | |||||||
|  |  | ||||||
| pacman_cmd = getattr(pacman, 'pacman', 'pacman') | pacman_cmd = getattr(pacman, 'pacman', 'pacman') | ||||||
|  |  | ||||||
|  | PKGFILE_OUTPUT_CONVERT = ''' | ||||||
|  | extra/imagemagick 6.9.1.0-1\t/usr/bin/convert | ||||||
|  | ''' | ||||||
|  |  | ||||||
|  | PKGFILE_OUTPUT_VIM = ''' | ||||||
|  | extra/gvim 7.4.712-1        \t/usr/bin/vim | ||||||
|  | extra/gvim-python3 7.4.712-1\t/usr/bin/vim | ||||||
|  | extra/vim 7.4.712-1         \t/usr/bin/vim | ||||||
|  | extra/vim-minimal 7.4.712-1 \t/usr/bin/vim | ||||||
|  | extra/vim-python3 7.4.712-1 \t/usr/bin/vim | ||||||
|  | ''' | ||||||
|  |  | ||||||
|  |  | ||||||
| @pytest.mark.skipif(not getattr(pacman, 'enabled_by_default', True), | @pytest.mark.skipif(not getattr(pacman, 'enabled_by_default', True), | ||||||
|                     reason='Skip if pacman is not available') |                     reason='Skip if pacman is not available') | ||||||
| @@ -17,7 +29,7 @@ def test_match(command): | |||||||
|  |  | ||||||
|  |  | ||||||
| @pytest.mark.parametrize('command, return_value', [ | @pytest.mark.parametrize('command, return_value', [ | ||||||
|     (Command(script='vim', stderr='vim: command not found'), 'vim foo bar')]) |     (Command(script='vim', stderr='vim: command not found'), PKGFILE_OUTPUT_VIM)]) | ||||||
| @patch('thefuck.rules.pacman.subprocess') | @patch('thefuck.rules.pacman.subprocess') | ||||||
| @patch.multiple(pacman, create=True, pacman=pacman_cmd) | @patch.multiple(pacman, create=True, pacman=pacman_cmd) | ||||||
| def test_match_mocked(subp_mock, command, return_value): | def test_match_mocked(subp_mock, command, return_value): | ||||||
| @@ -35,16 +47,17 @@ def test_not_match(command): | |||||||
| @pytest.mark.skipif(not getattr(pacman, 'enabled_by_default', True), | @pytest.mark.skipif(not getattr(pacman, 'enabled_by_default', True), | ||||||
|                     reason='Skip if pacman is not available') |                     reason='Skip if pacman is not available') | ||||||
| @pytest.mark.parametrize('command, new_command', [ | @pytest.mark.parametrize('command, new_command', [ | ||||||
|     (Command('vim'), '{} -S vim && vim'.format(pacman_cmd)), |     (Command('vim'), '{} -S extra/gvim && vim'.format(pacman_cmd)), | ||||||
|     (Command('convert'), '{} -S imagemagick && convert'.format(pacman_cmd))]) |     (Command('convert'), '{} -S extra/imagemagick && convert'.format(pacman_cmd))]) | ||||||
| def test_get_new_command(command, new_command, mocker): | def test_get_new_command(command, new_command, mocker): | ||||||
|     assert get_new_command(command, None) == new_command |     assert get_new_command(command, None) == new_command | ||||||
|  |  | ||||||
|  |  | ||||||
| @pytest.mark.parametrize('command, new_command, return_value', [ | @pytest.mark.parametrize('command, new_command, return_value', [ | ||||||
|     (Command('vim'), '{} -S vim && vim'.format(pacman_cmd), 'vim foo bar'), |     (Command('vim'), '{} -S extra/gvim && vim'.format(pacman_cmd), | ||||||
|     (Command('convert'), '{} -S imagemagick && convert'.format(pacman_cmd), |         PKGFILE_OUTPUT_VIM), | ||||||
|      'imagemagick foo bar')]) |     (Command('convert'), '{} -S extra/imagemagick && convert'.format(pacman_cmd), | ||||||
|  |         PKGFILE_OUTPUT_CONVERT)]) | ||||||
| @patch('thefuck.rules.pacman.subprocess') | @patch('thefuck.rules.pacman.subprocess') | ||||||
| @patch.multiple(pacman, create=True, pacman=pacman_cmd) | @patch.multiple(pacman, create=True, pacman=pacman_cmd) | ||||||
| def test_get_new_command_mocked(subp_mock, command, new_command, return_value): | def test_get_new_command_mocked(subp_mock, command, new_command, return_value): | ||||||
|   | |||||||
| @@ -1,17 +1,6 @@ | |||||||
| import subprocess | import subprocess | ||||||
|  | from thefuck.utils import DEVNULL, which | ||||||
| from thefuck import shells | from thefuck import shells | ||||||
| from thefuck.utils import DEVNULL |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def __command_available(command): |  | ||||||
|     try: |  | ||||||
|         subprocess.check_output([command], stderr=DEVNULL) |  | ||||||
|         return True |  | ||||||
|     except subprocess.CalledProcessError: |  | ||||||
|         # command exists but is not happy to be called without any argument |  | ||||||
|         return True |  | ||||||
|     except OSError: |  | ||||||
|         return False |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def __get_pkgfile(command): | def __get_pkgfile(command): | ||||||
| @@ -35,11 +24,11 @@ def get_new_command(command, settings): | |||||||
|     return formatme.format(pacman, package, command.script) |     return formatme.format(pacman, package, command.script) | ||||||
|  |  | ||||||
|  |  | ||||||
| if not __command_available('pkgfile'): | if not which('pkgfile'): | ||||||
|     enabled_by_default = False |     enabled_by_default = False | ||||||
| elif __command_available('yaourt'): | elif which('yaourt'): | ||||||
|     pacman = 'yaourt' |     pacman = 'yaourt' | ||||||
| elif __command_available('pacman'): | elif which('pacman'): | ||||||
|     pacman = 'sudo pacman' |     pacman = 'sudo pacman' | ||||||
| else: | else: | ||||||
|     enabled_by_default = False |     enabled_by_default = False | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user