def test_get_new_command(script, output, result): command = Command(script, output) assert get_new_command(command)[0] == result
import pytest from theheck.rules.cat_dir import match, get_new_command from theheck.types import Command @pytest.fixture def isdir(mocker): return mocker.patch('theheck.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)
import pytest from theheck.rules.git_remote_seturl_add import match, get_new_command from theheck.types import Command @pytest.mark.parametrize( 'command', [Command('git remote set-url origin url', "fatal: No such remote")]) def test_match(command): assert match(command) @pytest.mark.parametrize('command', [ Command('git remote set-url origin url', ""), Command('git remote add origin url', ''), Command('git remote remove origin', ''), Command('git remote prune origin', ''), Command('git remote set-branches origin branch', '') ]) def test_not_match(command): assert not match(command) @pytest.mark.parametrize( 'command, new_command', [(Command('git remote set-url origin [email protected]:nvbn/theheck.git', ''), 'git remote add origin [email protected]:nvbn/theheck.git')]) def test_get_new_command(command, new_command): assert get_new_command(command) == new_command
import pytest from theheck.rules.php_s import get_new_command, match from theheck.types import Command @pytest.mark.parametrize('command', [ Command('php -s localhost:8000', ''), Command('php -t pub -s 0.0.0.0:8080', '') ]) def test_match(command): assert match(command) @pytest.mark.parametrize( 'command', [Command('php -S localhost:8000', ''), Command('vim php -s', '')]) def test_not_match(command): assert not match(command) @pytest.mark.parametrize('command, new_command', [ (Command('php -s localhost:8000', ''), 'php -S localhost:8000'), (Command('php -t pub -s 0.0.0.0:8080', ''), 'php -t pub -S 0.0.0.0:8080') ]) def test_get_new_command(command, new_command): assert get_new_command(command) == new_command
def test_not_match(file_exists, file_access, script, output, exists, callable): file_exists.return_value = exists file_access.return_value = callable assert not match(Command(script, output))
def test_get_new_command(): assert get_new_command(Command('main --help', '')) == './main --help'
def test_for_app(script, names, result): @for_app(*names) def match(command): return True assert match(Command(script, '')) == result
def test_get_new_command(before, after): assert get_new_command(Command(before, '')) == after
def test_match(output): assert match(Command('grep -h', output))
def test_get_new_command(is_not_task): assert (get_new_command(Command('lein rpl --help', is_not_task)) == ['lein repl --help', 'lein jar --help'])
def test_not_match(): assert not match(Command('', ''))
def test_match(is_not_task): assert match(Command('lein rpl', is_not_task)) assert not match(Command('ls', is_not_task))
def test_get_new_command(script, output, result): new_command = get_new_command(Command(script, output)) assert new_command[0] == result
def test_match(script, command): assert match(Command(script, output.format(command)))
def test_match(script, is_bsd): command = Command(script, output(is_bsd)) assert match(command)
def test_match(cmd): assert match(Command('heroku {}'.format(cmd), suggest_output))
def test_get_new_command(script, is_bsd): command = Command(script, output(is_bsd)) fixed_command = get_new_command(command) assert fixed_command == 'mkdir -p /a/b && touch /a/b/c'
def test_get_new_command(cmd, result): command = Command('heroku {}'.format(cmd), suggest_output) assert get_new_command(command) == result
def test_is_app(script, names, result): assert is_app(Command(script, ''), *names) == result
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_get_valid_history_without_current(self, script, result): command = Command(script, '') assert get_valid_history_without_current(command) == result
def test_match(output): assert match(Command('./manage.py migrate', output)) assert match(Command('python manage.py migrate', output)) assert not match(Command('./manage.py migrate', '')) assert not match(Command('app migrate', output)) assert not match(Command('./manage.py test', output))
def test_match(script, output): assert match(Command(script, output))
def test_get_new_command(): assert (get_new_command(Command('./manage.py migrate auth', '')) == './manage.py migrate auth --merge')
def test_get_new_command(script, result): assert get_new_command(Command(script, '')) == result
import pytest from theheck.rules.apt_get import match, get_new_command from theheck.types import Command @pytest.mark.parametrize('command, packages', [ (Command('vim', 'vim: command not found'), [('vim', 'main'), ('vim-tiny', 'main')]), (Command('sudo vim', 'vim: command not found'), [('vim', 'main'), ('vim-tiny', 'main')]), (Command( 'vim', "The program 'vim' is currently not installed. You can install it by typing: sudo apt install vim" ), [('vim', 'main'), ('vim-tiny', 'main')]) ]) def test_match(mocker, command, packages): mocker.patch('theheck.rules.apt_get.which', return_value=None) mocker.patch('theheck.rules.apt_get._get_packages', create=True, return_value=packages) assert match(command) @pytest.mark.parametrize( 'command, packages, which', [(Command('a_bad_cmd', 'a_bad_cmd: command not found'), [], None), (Command('vim', ''), [], None), (Command('', ''), [], None), (Command('vim', 'vim: command not found'), ['vim'], '/usr/bin/vim'), (Command('sudo vim', 'vim: command not found'), ['vim'], '/usr/bin/vim')]) def test_not_match(mocker, command, packages, which):
import pytest from theheck.rules.javac import match, get_new_command from theheck.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
from theheck.types import Command def output(is_bsd): if is_bsd: return "touch: /a/b/c: No such file or directory" return "touch: cannot touch '/a/b/c': No such file or directory" @pytest.mark.parametrize('script, is_bsd', [('touch /a/b/c', False), ('touch /a/b/c', True)]) def test_match(script, is_bsd): command = Command(script, output(is_bsd)) assert match(command) @pytest.mark.parametrize( 'command', [Command('touch /a/b/c', ''), Command('ls /a/b/c', output(False))]) def test_not_match(command): assert not match(command) @pytest.mark.parametrize('script, is_bsd', [('touch /a/b/c', False), ('touch /a/b/c', True)]) def test_get_new_command(script, is_bsd): command = Command(script, output(is_bsd)) fixed_command = get_new_command(command) assert fixed_command == 'mkdir -p /a/b && touch /a/b/c'
import pytest from theheck.rules.git_merge import match, get_new_command from theheck.types import Command output = 'merge: local - not something we can merge\n\n' \ 'Did you mean this?\n\tremote/local' 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 remote/local'), (Command('git merge -m "test" local', output), 'git merge -m "test" remote/local'), (Command('git merge -m "test local" local', output), 'git merge -m "test local" remote/local')]) def test_get_new_command(command, new_command): assert get_new_command(command) == new_command
cp node_modules/ace-builds/src/ -a resources/ace/ && webpack-dev-server --progress --colors watch-test jest --verbose --watch ''' @pytest.fixture(autouse=True) def run_script(mocker): patch = mocker.patch('theheck.specific.npm.Popen') patch.return_value.stdout = BytesIO(run_script_stdout) return patch.return_value @pytest.mark.parametrize('command', [ Command('npm ru wach', output('wach')), Command('npm run live-tes', output('live-tes')), Command('npm run-script sahare', output('sahare'))]) def test_match(command): assert match(command) @pytest.mark.parametrize('command', [ Command('npm wach', output('wach')), Command('vim live-tes', output('live-tes')), Command('npm run-script sahare', '')]) def test_not_match(command): assert not match(command) @pytest.mark.parametrize('script, output, result', [