Best Python code snippet using prospector_python
quickstart.py
Source:quickstart.py
...11DEPLOY_DIR = os.path.join(ROOT_DIR, 'deploy')12VENV_DIR = os.path.abspath(os.path.join(DEPLOY_DIR, 'env'))13PYVER = "%d.%d" % (sys.version_info[0], sys.version_info[1])14MERCURIAL_WIN_BINARY = "http://mercurial.selenic.com/release/windows/mercurial-2.5.2.win32-py%s.exe" % PYVER15def find_python():16 for bindir in ['Scripts', 'bin']:17 for suffix in ['.exe', '']:18 python_bin = os.path.join(VENV_DIR, bindir, 'python' + suffix)19 easy_install_bin = os.path.join(VENV_DIR, bindir, 'easy_install' + suffix)20 if os.path.exists(python_bin) and os.path.exists(easy_install_bin):21 return python_bin, easy_install_bin22 raise RuntimeError("Something went wrong in virtualenv creation: "23 "python and pip not found!")24def run_cmd(cmd):25 print("$ %s" % " ".join(cmd))26 ret = subprocess.call(cmd)27 if ret != 0:28 print("ERROR: command failed!")29 sys.exit(1)30def main():31 p = argparse.ArgumentParser(usage=__doc__.strip())32 args = p.parse_args()33 try:34 import virtualenv35 except ImportError:36 print("ERROR: You need to install Virtualenv (https://pypi.python.org/pypi/virtualenv) first")37 sys.exit(0)38 try:39 find_python()40 except RuntimeError:41 print("\n-- Creating virtualenv in deploy/env")42 print("$ virtualenv %s" % VENV_DIR)43 virtualenv.create_environment(VENV_DIR)44 python_bin, easy_install_bin = find_python()45 os.chdir(ROOT_DIR)46 print("\n-- Installing required modules")47 with open('requirements.txt', 'r') as f:48 requirements = [x.strip() for x in f.read().splitlines() if x.strip()]49 if sys.platform.startswith('win'):50 # Download the windows binary51 requirements = [MERCURIAL_WIN_BINARY if x.lower().startswith('mercurial')52 else x for x in requirements]53 run_cmd([easy_install_bin] + requirements)54 print("\n-- Setting up development database")55 print("$ cd deploy")56 os.chdir(DEPLOY_DIR)57 run_cmd([python_bin, 'manage.py', 'syncdb'])58 run_cmd([python_bin, 'manage.py', 'migrate'])...
run.py
Source:run.py
...5def run_tests(test_folder, runner):6 if not exists(test_folder):7 raise click.BadParameter('No such folder %s' % test_folder)8 if runner == 'unittest':9 shell(find_python() + ' -m unittest discover ' + str(test_folder), silent=False)10 elif runner == 'pytest':11 shell(find_python() + ' -m pip install --upgrade pytest')12 shell(find_python() + ' -m pytest ' + str(test_folder), silent=False)13 else:14 raise click.BadParameter('No such test runner: %s' % runner)15def run_coverage(source, test_dir, runner):16 if not exists(test_dir):17 raise click.BadParameter('No such folder or file: %s' % test_dir)18 if not exists(source):19 raise click.BadParameter('No such folder %s' % source)20 if runner == 'unittest':21 shell(find_python() + ' -m pip install --upgrade coverage')22 shell(find_python() + ' -m coverage run --source=%s -m unittest discover %s' %23 (source, test_dir), silent=False)24 elif runner == 'pytest':25 shell(find_python() + ' -m pip install --upgrade coverage pytest')26 shell(find_python() + ' -m coverage run --source=%s -m pytest %s' %27 (source, test_dir), silent=False)28 else:29 raise click.BadParameter('No such test runner: %s' % runner)30 shell(find_python() + ' -m coverage report -m', silent=False)31def run_docs():32 """Build the documentation and show it in the browser."""33 cwd = Path.cwd()34 if not exists(cwd / 'docs'):35 raise click.BadParameter('Cannot find docs folder.')36 shell('make clean', root=str(cwd / 'docs'), silent=False)37 shell(find_python() + ' -m sphinx.cmd.build -M html . _build', root=str(cwd / 'docs'), silent=False)38 click.launch(str(cwd / 'docs' / '_build' / 'html' / 'index.html'))39def run_flake8(dirs):40 """Run flake8 style enforcement in specified directories.41 Parameters42 ----------43 dirs: list of str44 The directories to scan for style violations.45 """46 shell(find_python() + ' -m pip install --upgrade flake8')...
test_model.py
Source:test_model.py
1import os2from time import sleep3from model_part import find_log, find_model, read_txt4def find_python():5 python_path = os.getcwd()6 return python_path7def test_open():8 math_path = find_python()9 mode_list = find_log(math_path)10 find_model(math_path, mode_list)11def test_check():12 13 while True :14 read_txt(find_python())15 # print('é裡æ¯è¨ç·´æ¨¡å')16 sleep(2)17def model_main():18 test_check()19 ...
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!!