import pytest from thefrick.rules.cd_correction import match from thefrick.types import Command @pytest.mark.parametrize('command', [ Command('cd foo', 'cd: foo: No such file or directory'), Command('cd foo/bar/baz', 'cd: foo: No such file or directory'), Command('cd foo/bar/baz', 'cd: can\'t cd to foo/bar/baz'), Command('cd /foo/bar/', 'cd: The directory "/foo/bar/" does not exist') ]) def test_match(command): assert match(command) @pytest.mark.parametrize('command', [Command('cd foo', ''), Command('', '')]) def test_not_match(command): assert not match(command) # Note that get_new_command uses local filesystem, so not testing it here. # Instead, see the functional test `functional.test_cd_correction`
def test_match(): assert match(Command('gulp srve', output('srve')))
def test_match(): assert match(Command('git merge test', output)) assert not match(Command('git merge master', '')) assert not match(Command('ls', output))
def test_match(): assert match(Command('mandiff', 'mandiff: command not found')) assert not match(Command('', ''))
import pytest from thefrick.rules.javac import match, get_new_command from thefrick.types import Command @pytest.mark.parametrize('command', [Command('javac foo', ''), Command('javac bar', '')]) def test_match(command): assert match(command) @pytest.mark.parametrize('command, new_command', [(Command('javac foo', ''), 'javac foo.java'), (Command('javac bar', ''), 'javac bar.java')]) def test_get_new_command(command, new_command): assert get_new_command(command) == new_command
def test_get_new_command(output, new_command, script, formula): assert get_new_command(Command(script, output)) == new_command
def test_not_match(script, output): assert not match(Command(script, output))
import pytest from thefrick.rules.no_such_file import match, get_new_command from thefrick.types import Command @pytest.mark.parametrize('command', [ Command('mv foo bar/foo', "mv: cannot move 'foo' to 'bar/foo': No such file or directory"), Command('mv foo bar/', "mv: cannot move 'foo' to 'bar/': No such file or directory"), ]) def test_match(command): assert match(command) @pytest.mark.parametrize('command', [ Command('mv foo bar/', ""), Command('mv foo bar/foo', "mv: permission denied"), ]) def test_not_match(command): assert not match(command) @pytest.mark.parametrize('command, new_command', [ (Command('mv foo bar/foo', "mv: cannot move 'foo' to 'bar/foo': No such file or directory"), 'mkdir -p bar && mv foo bar/foo'), (Command('mv foo bar/', "mv: cannot move 'foo' to 'bar/': No such file or directory"), 'mkdir -p bar && mv foo bar/'), ])
def test_not_match(): assert not match(Command('', ''))
Task '{}' is ambiguous in root project 'org.rerenderer_example.snake'. Candidates are: 'assembleRelease', 'assembleReleaseUnitTest'. * Try: Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. '''.format @pytest.fixture(autouse=True) def tasks(mocker): patch = mocker.patch('thefrick.rules.gradle_no_task.Popen') patch.return_value.stdout = BytesIO(gradle_tasks) return patch @pytest.mark.parametrize('command', [ Command('./gradlew assembler', output_ambiguous('assembler')), Command('./gradlew instar', output_not_found('instar')), Command('gradle assembler', output_ambiguous('assembler')), Command('gradle instar', output_not_found('instar'))]) def test_match(command): assert match(command) @pytest.mark.parametrize('command', [ Command('./gradlew assemble', ''), Command('gradle assemble', ''), Command('npm assembler', output_ambiguous('assembler')), Command('npm instar', output_not_found('instar'))]) def test_not_match(command): assert not match(command)
def test_get_new_command(): """ Replace the Alt+Space character by a simple space """ assert (get_new_command(Command(u'ps -ef | grep foo', '')) == 'ps -ef | grep foo')
def test_match(script, result): output = get_output('source') assert match(Command(script, output)) assert get_new_command(Command(script, output)) == result
def test_not_match(file_exists, script, output, exists): file_exists.return_value = exists assert not match(Command(script, output))
import pytest from thefrick.rules.git_flag_after_filename import match, get_new_command from thefrick.types import Command command1 = Command('git log README.md -p', "fatal: bad flag '-p' used after filename") command2 = Command('git log README.md -p CONTRIBUTING.md', "fatal: bad flag '-p' used after filename") command3 = Command('git log -p README.md --name-only', "fatal: bad flag '--name-only' used after filename") command4 = Command('git log README.md -p', "fatal: option '-p' must come before non-option arguments") command5 = Command('git log README.md -p CONTRIBUTING.md', "fatal: option '-p' must come before non-option arguments") command6 = Command( 'git log -p README.md --name-only', "fatal: option '--name-only' must come before non-option arguments") @pytest.mark.parametrize( 'command', [command1, command2, command3, command4, command5, command6]) def test_match(command): assert match(command) @pytest.mark.parametrize( 'command', [Command('git log README.md', ''), Command('git log -p README.md', '')]) def test_not_match(command): assert not match(command)
def test_match(output, script): assert match(Command(script, output))
def test_get_new_command(before, after): assert get_new_command(Command(before, '')) == after
def test_not_match(script): assert not match(Command(script, ''))
def test_match(output): assert match(Command('grep -h', output))
def test_match(cmd): assert match( Command('heroku {}'.format(cmd), suggest_output))
def test_get_new_command(): assert get_new_command(Command('main --help', '')) == './main --help'
def test_get_new_command(cmd, result): command = Command('heroku {}'.format(cmd), suggest_output) assert get_new_command(command) == result
# -*- encoding: utf-8 -*- import pytest from thefrick.rules import switch_lang from thefrick.types import Command @pytest.mark.parametrize('command', [ Command(u'фзе-пуе', 'command not found: фзе-пуе'), Command(u'λσ', 'command not found: λσ'), Command(u'שפא-עקא', 'command not found: שפא-עקא'), Command(u'ךד', 'command not found: ךד'), Command(u'녀애 ㅣㄴ', 'command not found: 녀애 ㅣㄴ') ]) def test_match(command): assert switch_lang.match(command) @pytest.mark.parametrize('command', [ Command(u'pat-get', 'command not found: pat-get'), Command(u'ls', 'command not found: ls'), Command(u'агсл', 'command not found: агсл'), Command(u'фзе-пуе', 'some info'), Command(u'שפא-עקא', 'some info'), Command(u'녀애 ㅣㄴ', 'some info') ]) def test_not_match(command): assert not switch_lang.match(command)
def test_get_new_command(): assert get_new_command(Command('mandiff', '')) == 'man diff'
def test_get_new_command(output, script, target, new_command): assert get_new_command(Command(script, output)) == new_command
lsof_stdout = b'''COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME node 18233 nvbn 16u IPv4 557134 0t0 TCP localhost:http-alt (LISTEN) ''' @pytest.fixture(autouse=True) def lsof(mocker): patch = mocker.patch('thefrick.rules.port_already_in_use.Popen') patch.return_value.stdout = BytesIO(lsof_stdout) return patch @pytest.mark.usefixtures('no_memoize') @pytest.mark.parametrize('command', [Command('./app', output) for output in outputs] + [Command('./app', output) for output in outputs]) def test_match(command): assert match(command) @pytest.mark.usefixtures('no_memoize') @pytest.mark.parametrize('command, lsof_output', [(Command('./app', ''), lsof_stdout), (Command('./app', outputs[1]), b''), (Command('./app', outputs[2]), b'')]) def test_not_match(lsof, command, lsof_output): lsof.return_value.stdout = BytesIO(lsof_output) assert not match(command)
import pytest from thefrick.rules.cat_dir import match, get_new_command from thefrick.types import Command @pytest.fixture def isdir(mocker): return mocker.patch('thefrick.rules.cat_dir' '.os.path.isdir') @pytest.mark.parametrize('command', [ Command('cat foo', 'cat: foo: Is a directory\n'), Command('cat /foo/bar/', 'cat: /foo/bar/: Is a directory\n'), Command('cat cat/', 'cat: cat/: Is a directory\n'), ]) def test_match(command, isdir): isdir.return_value = True assert match(command) @pytest.mark.parametrize('command', [ Command('cat foo', 'foo bar baz'), Command('cat foo bar', 'foo bar baz'), Command('notcat foo bar', 'some output'), ]) def test_not_match(command, isdir): isdir.return_value = False assert not match(command)
def test_not_march(script, stdout): assert not match(Command(script, stdout))
import pytest from thefrick.rules.git_merge_unrelated import match, get_new_command from thefrick.types import Command output = 'fatal: refusing to merge unrelated histories' def test_match(): assert match(Command('git merge test', output)) assert not match(Command('git merge master', '')) assert not match(Command('ls', output)) @pytest.mark.parametrize( 'command, new_command', [(Command('git merge local', output), 'git merge local --allow-unrelated-histories'), (Command('git merge -m "test" local', output), 'git merge -m "test" local --allow-unrelated-histories'), (Command('git merge -m "test local" local', output), 'git merge -m "test local" local --allow-unrelated-histories')]) def test_get_new_command(command, new_command): assert get_new_command(command) == new_command