mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-30 22:54:14 +00:00 
			
		
		
		
	#942: Improve git_branch_0flag rule - with a new name
This commit is contained in:
		
				
					committed by
					
						 Pablo Aguiar
						Pablo Aguiar
					
				
			
			
				
	
			
			
			
						parent
						
							fe1942866b
						
					
				
				
					commit
					799f4127ca
				
			
							
								
								
									
										70
									
								
								tests/rules/test_git_branch_0flag.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								tests/rules/test_git_branch_0flag.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,70 @@ | ||||
| import pytest | ||||
|  | ||||
| from thefuck.rules.git_branch_0flag import get_new_command, match | ||||
| from thefuck.types import Command | ||||
|  | ||||
|  | ||||
| @pytest.fixture | ||||
| def output_branch_exists(): | ||||
|     return "fatal: A branch named 'bar' already exists." | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize( | ||||
|     "script", | ||||
|     [ | ||||
|         "git branch 0a", | ||||
|         "git branch 0d", | ||||
|         "git branch 0f", | ||||
|         "git branch 0r", | ||||
|         "git branch 0v", | ||||
|         "git branch 0d foo", | ||||
|         "git branch 0D foo", | ||||
|     ], | ||||
| ) | ||||
| def test_match(script, output_branch_exists): | ||||
|     assert match(Command(script, output_branch_exists)) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize( | ||||
|     "script", | ||||
|     [ | ||||
|         "git branch -a", | ||||
|         "git branch -r", | ||||
|         "git branch -v", | ||||
|         "git branch -d foo", | ||||
|         "git branch -D foo", | ||||
|     ], | ||||
| ) | ||||
| def test_not_match(script, output_branch_exists): | ||||
|     assert not match(Command(script, "")) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize( | ||||
|     "script, new_command", | ||||
|     [ | ||||
|         ("git branch 0a", "git branch -D 0a && git branch -a"), | ||||
|         ("git branch 0v", "git branch -D 0v && git branch -v"), | ||||
|         ("git branch 0d foo", "git branch -D 0d && git branch -d foo"), | ||||
|         ("git branch 0D foo", "git branch -D 0D && git branch -D foo"), | ||||
|         ("git branch 0l 'maint-*'", "git branch -D 0l && git branch -l 'maint-*'"), | ||||
|         ("git branch 0u upstream", "git branch -D 0u && git branch -u upstream"), | ||||
|     ], | ||||
| ) | ||||
| def test_get_new_command_branch_exists(script, output_branch_exists, new_command): | ||||
|     assert get_new_command(Command(script, output_branch_exists)) == new_command | ||||
|  | ||||
|  | ||||
| @pytest.fixture | ||||
| def output_not_valid_object(): | ||||
|     return "fatal: Not a valid object name: 'bar'." | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize( | ||||
|     "script, new_command", | ||||
|     [ | ||||
|         ("git branch 0l 'maint-*'", "git branch -l 'maint-*'"), | ||||
|         ("git branch 0u upstream", "git branch -u upstream"), | ||||
|     ], | ||||
| ) | ||||
| def test_get_new_command_not_valid_object(script, output_not_valid_object, new_command): | ||||
|     assert get_new_command(Command(script, output_not_valid_object)) == new_command | ||||
| @@ -1,22 +0,0 @@ | ||||
| import pytest | ||||
| from thefuck.rules.git_branch_flag_0_to_flag_dash_v import match, get_new_command | ||||
| from thefuck.types import Command | ||||
|  | ||||
|  | ||||
| @pytest.fixture | ||||
| def output(): | ||||
|     return "" | ||||
|  | ||||
|  | ||||
| def test_match_git_branch_0v(output): | ||||
|     assert match(Command('git branch 0v', output)) | ||||
|  | ||||
|  | ||||
| def test_matches_no__git_branch_0_anything(output): | ||||
|     assert not match(Command('git branch -v', '')) | ||||
|     assert not match(Command('ls', output)) | ||||
|  | ||||
|  | ||||
| def test_get_new_command(output): | ||||
|     assert get_new_command(Command('git branch 0v', output))\ | ||||
|         == 'git branch -D 0v && git branch -v' | ||||
		Reference in New Issue
	
	Block a user