mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-30 22:54:14 +00:00 
			
		
		
		
	Refactor tests/rules/test_ag_literal.py
https://github.com/nvbn/thefuck/pull/561#discussion_r81894710
This commit is contained in:
		| @@ -1,26 +1,25 @@ | |||||||
| import pytest | import pytest | ||||||
| from thefuck.rules.ag_literal import match, get_new_command | from thefuck.rules.ag_literal import get_new_command, match | ||||||
| from tests.utils import Command | from tests.utils import Command | ||||||
|  |  | ||||||
| stderr = ('ERR: Bad regex! pcre_compile() failed at position 1: missing )\n' |  | ||||||
|           'If you meant to search for a literal string, run ag with -Q\n') |  | ||||||
|  |  | ||||||
| matching_command = Command(script='ag \\(', stderr=stderr) | @pytest.fixture | ||||||
|  | def stderr(): | ||||||
|  |     return ('ERR: Bad regex! pcre_compile() failed at position 1: missing )\n' | ||||||
|  |             'If you meant to search for a literal string, run ag with -Q\n') | ||||||
|  |  | ||||||
|  |  | ||||||
| @pytest.mark.parametrize('command', [ | @pytest.mark.parametrize('script', ['ag \(']) | ||||||
|     matching_command]) | def test_match(script, stderr): | ||||||
| def test_match(command): |     assert match(Command(script=script, stderr=stderr)) | ||||||
|     assert match(matching_command) |  | ||||||
|  |  | ||||||
|  |  | ||||||
| @pytest.mark.parametrize('command', [ | @pytest.mark.parametrize('script', ['ag foo']) | ||||||
|     Command(script='ag foo', stderr='')]) | def test_not_match(script): | ||||||
| def test_not_match(command): |     assert not match(Command(script=script)) | ||||||
|     assert not match(command) |  | ||||||
|  |  | ||||||
|  |  | ||||||
| @pytest.mark.parametrize('command, new_command', [ | @pytest.mark.parametrize('script, new_cmd', [ | ||||||
|     (matching_command, 'ag -Q \\(')]) |     ('ag \(', 'ag -Q \(')]) | ||||||
| def test_get_new_command(command, new_command): | def test_get_new_command(script, new_cmd, stderr): | ||||||
|     assert get_new_command(command) == new_command |     assert get_new_command((Command(script=script, stderr=stderr))) == new_cmd | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user