Best Python code snippet using avocado_python
test_runner.py
Source:test_runner.py
1import os2import pytest3import flowtool_githooks.config4import flowtool_githooks.runner5from flowtool_githooks.manager import hook_specs6from click.testing import CliRunner7runner = CliRunner()8def exec_click(command, args):9 """ A unified way of calling click commands for testing. """10 result = runner.invoke(command, args)11 return result.exit_code, result.output, None12def test_outside(nogit):13 exit_code, out, err = exec_click(14 flowtool_githooks.runner.runner_command,15 ['--git', nogit],16 )17 assert exit_code == 1, "should fail, because not in a git"18 assert out.startswith('The current directory is not under git version control: ')19 assert nogit in out20 assert not err21def test_install_activate_all(fresh_repo):22 exit_code, out, err = exec_click(23 flowtool_githooks.runner.runner_command,24 ['--git', fresh_repo.git_dir],25 )26 assert exit_code == 027 assert not err28 for hook in hook_specs:29 assert hook not in out30 exit_code, install_out, err = exec_click(31 flowtool_githooks.runner.runner_command,32 ['--git', fresh_repo.git_dir, '--install'],33 )34 assert exit_code == 035 assert install_out.startswith('Installing')36 for hook in hook_specs:37 assert hook in install_out38 exit_code, install_out, err = exec_click(39 flowtool_githooks.runner.runner_command,40 ['--git', fresh_repo.git_dir, '--deactivate'],41 )42 assert exit_code == 043 exit_code, out, err = exec_click(44 flowtool_githooks.runner.runner_command,45 ['--git', fresh_repo.git_dir, '--status'],46 )47 assert exit_code == 048 assert os.path.dirname(fresh_repo.git_dir) in out49 assert 'enabled:1' not in out50 assert not err51 exit_code, install_out, err = exec_click(52 flowtool_githooks.runner.runner_command,53 ['--git', fresh_repo.git_dir, '--activate'],54 )55 assert exit_code == 056 for hook in hook_specs:57 assert hook in out58 exit_code, install_out, err = exec_click(59 flowtool_githooks.runner.runner_command,60 ['--git', fresh_repo.git_dir, '--remove', '--yes'],61 )62 assert exit_code == 063 assert not install_out64 exit_code, out, err = exec_click(65 flowtool_githooks.runner.runner_command,66 ['--git', fresh_repo.git_dir, '--status'],67 )68 assert exit_code == 069 assert os.path.dirname(fresh_repo.git_dir) in out70 assert 'enabled:' not in out71 assert not err72 for hook in hook_specs:73 assert hook not in out74def test_install_activate_single(fresh_repo):75 exit_code, out, err = exec_click(76 flowtool_githooks.runner.runner_command,77 ['--git', fresh_repo.git_dir],78 )79 assert exit_code == 080 assert not err81 for hook in hook_specs:82 assert hook not in out83 exit_code, out, err = exec_click(84 flowtool_githooks.runner.runner_command,85 ['--git', fresh_repo.git_dir, '--status', 'pattern'],86 )87 assert exit_code == 088 assert os.path.dirname(fresh_repo.git_dir) in out89 assert 'enabled:1' not in out90 assert not err91 for hook in hook_specs:92 assert hook not in out93 exit_code, install_out, err = exec_click(94 flowtool_githooks.runner.runner_command,95 ['--git', fresh_repo.git_dir, '--install', hook],96 )97 assert exit_code == 098 assert install_out.startswith('Installing')99 exit_code, status_out, err = exec_click(100 flowtool_githooks.runner.runner_command,101 ['--git', fresh_repo.git_dir, '--status', hook],102 )103 assert hook in status_out104 assert 'enabled:1' in status_out105 assert exit_code == 0106 exit_code, activation_out, err = exec_click(107 flowtool_githooks.runner.runner_command,108 ['--git', fresh_repo.git_dir, '--deactivate', hook],109 )110 assert exit_code == 0111 assert activation_out.startswith('Deactivated')112 assert hook in activation_out113 exit_code, status_out, err = exec_click(114 flowtool_githooks.runner.runner_command,115 ['--git', fresh_repo.git_dir, '--status', hook],116 )117 assert hook in status_out118 assert 'enabled:0' in status_out119 assert exit_code == 0120 exit_code, activation_out, err = exec_click(121 flowtool_githooks.runner.runner_command,122 ['--git', fresh_repo.git_dir, '--activate', hook],123 )124 assert exit_code == 0125 assert activation_out.startswith('Activated')126 assert hook in activation_out127 exit_code, remove_out, err = exec_click(128 flowtool_githooks.runner.runner_command,129 ['--git', fresh_repo.git_dir, '--remove', hook, '--yes'],130 )131 assert not remove_out132 assert exit_code == 0133 exit_code, status_out, err = exec_click(134 flowtool_githooks.runner.runner_command,135 ['--git', fresh_repo.git_dir, '--status', hook],136 )137 assert hook not in status_out138 assert 'enabled:1' not in status_out139 assert exit_code == 0140@pytest.fixture(scope='module')141def confed_repo(permanent_repo):142 runner.invoke(143 flowtool_githooks.runner.runner_command,144 ['--git', permanent_repo.git_dir, '--install'],145 )146 return permanent_repo147def test_installed(confed_repo):148 exit_code, out, err = exec_click(149 flowtool_githooks.runner.runner_command,150 ['--git', confed_repo.git_dir],151 )152 assert exit_code == 0153 assert not err154 for hook in hook_specs:155 assert hook in out156 exit_code, out, err = exec_click(157 flowtool_githooks.runner.runner_command,158 ['--git', confed_repo.git_dir, '--status'],159 )160 assert exit_code == 0161 assert not err162 for hook in hook_specs:163 assert hook in out164def test_noop(confed_repo):165 exit_code, out, err = exec_click(166 flowtool_githooks.runner.runner_command,167 ['--noop', '--git', confed_repo.git_dir],168 )169 assert exit_code == 0170 assert not err171def test_invoke_githook(confed_repo):172 exit_code, out, err = exec_click(173 flowtool_githooks.runner.runner_command,174 ['--git', confed_repo.git_dir, 'commit'],175 )176 assert exit_code == 1177 assert out.startswith('Too many')178 assert 'pre-commit' in out179 assert 'commit-msg' in out180 assert not err181 exit_code, out, err = exec_click(182 flowtool_githooks.runner.runner_command,183 ['--git', confed_repo.git_dir, 'commit-msg', '--noop'],184 )185 assert exit_code == 0186 assert out.startswith('Invoking commit-msg')...
runner_util.py
Source:runner_util.py
1import subprocess2import os3from pipebench.schema.documents import validate4import shlex5import util6import time7def start_pipeline_runner(runner,8 runner_config,9 run_root,10 piperun_config_path,11 pipeline_root,12 systeminfo_path,13 redirect=True,14 numa_node = None,15 verbose_level=0):16 runner_root = os.path.join(pipeline_root, "runners", runner)17 18 default_run = os.path.join(runner_root, "run.sh")19 if (redirect):20 stdout_path = os.path.join(run_root, "stdout.txt")21 stderr_path = os.path.join(run_root, "stderr.txt")22 23 stdout_file = open(stdout_path,"w")24 stderr_file = open(stderr_path,"w")25 else:26 stdout_file = None27 stderr_file = None28 29 if (runner_config and "run" in runner_config):30 runner_command = shlex.split(runner_config["run"])31 else:32 runner_command = ["/bin/bash",default_run]33 34 runner_command.extend(["--systeminfo={}".format(systeminfo_path)])35 runner_command.append(piperun_config_path)36 if numa_node is not None:37 runner_command = ["numactl","--cpunodebind",str(numa_node),"--membind",str(numa_node)] + runner_command38 start_time = time.time()39 if verbose_level>0:40 util.print_action("Launching: {}".format(runner),41 ["Started: {}".format(start_time),42 "Command: {}".format(runner_command)])43 44 process = subprocess.Popen(runner_command,45 cwd=runner_root,46 stdout=stdout_file,47 stderr=stderr_file)...
test_utils.py
Source:test_utils.py
1import os2import pytest3from mamba_gator.envmanager import RUNNER_COMMAND, get_env_path4@pytest.mark.parametrize(5 "spec,expected",6 [7 (8 {9 "argv": [10 *RUNNER_COMMAND,11 "/path/to/conda",12 os.path.join("path", "to", "envs", "myenv"),13 "-m",14 "ipykernel_launcher",15 ],16 "metadata": {},17 },18 os.path.join("path", "to", "envs", "myenv"),19 ),20 (21 {22 "argv": [23 *RUNNER_COMMAND,24 "/path/to/conda",25 os.path.join("path", "to", "envs", "myenv"),26 "-m",27 "ipykernel_launcher",28 ],29 "metadata": {30 "conda_env_path": os.path.join("path", "to", "envs", "myenv")31 },32 },33 os.path.join("path", "to", "envs", "myenv"),34 ),35 (36 {37 "argv": [os.path.join("path", "to", "envs", "myenv", "bin", "python")],38 "metadata": {},39 },40 os.path.join("path", "to", "envs", "myenv"),41 ),42 ({"argv": [], "metadata": {}}, None),43 ],44)45def test_get_env_path(spec, expected):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!