mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 15:12:20 +00:00 
			
		
		
		
	#591: Add path_from_history rule
				
					
				
			This commit is contained in:
		
							
								
								
									
										43
									
								
								tests/rules/test_path_from_history.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								tests/rules/test_path_from_history.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| import pytest | ||||
| from thefuck.rules.path_from_history import match, get_new_command | ||||
| from tests.utils import Command | ||||
|  | ||||
|  | ||||
| @pytest.fixture(autouse=True) | ||||
| def history(mocker): | ||||
|     return mocker.patch( | ||||
|         'thefuck.rules.path_from_history.get_valid_history_without_current', | ||||
|         return_value=['cd /opt/java', 'ls ~/work/project/']) | ||||
|  | ||||
|  | ||||
| @pytest.fixture(autouse=True) | ||||
| def path_exists(mocker): | ||||
|     path_mock = mocker.patch('thefuck.rules.path_from_history.Path') | ||||
|     exists_mock = path_mock.return_value.expanduser.return_value.exists | ||||
|     exists_mock.return_value = True | ||||
|     return exists_mock | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('script, stderr', [ | ||||
|     ('ls project', 'no such file or directory: project'), | ||||
|     ('cd project', "can't cd to project"), | ||||
| ]) | ||||
| def test_match(script, stderr): | ||||
|     assert match(Command(script, stderr=stderr)) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('script, stderr', [ | ||||
|     ('myapp cats', 'no such file or directory: project'), | ||||
|     ('cd project', ""), | ||||
| ]) | ||||
| def test_not_match(script, stderr): | ||||
|     assert not match(Command(script, stderr=stderr)) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('script, stderr, result', [ | ||||
|     ('ls project', 'no such file or directory: project', 'ls ~/work/project'), | ||||
|     ('cd java', "can't cd to java", 'cd /opt/java'), | ||||
| ]) | ||||
| def test_get_new_command(script, stderr, result): | ||||
|     new_command = get_new_command(Command(script, stderr=stderr)) | ||||
|     assert new_command[0] == result | ||||
		Reference in New Issue
	
	Block a user