Best Python code snippet using autotest_python
prebuild.py
Source:prebuild.py
...3# Eric Li <ericli@google.com>4import logging, os, pickle, re, sys5import common6from autotest_lib.client.bin import setup_job as client_setup_job7def touch_init(parent_dir, child_dir):8 """9 Touch __init__.py file all alone through from dir_patent to child_dir.10 So client tests could be loaded as Python modules. Assume child_dir is a11 subdirectory of parent_dir.12 """13 if not child_dir.startswith(parent_dir):14 logging.error('%s is not a subdirectory of %s' % (child_dir,15 parent_dir))16 return17 sub_parent_dirs = parent_dir.split(os.path.sep)18 sub_child_dirs = child_dir.split(os.path.sep)19 for sub_dir in sub_child_dirs[len(sub_parent_dirs):]:20 sub_parent_dirs.append(sub_dir)21 path = os.path.sep.join(sub_parent_dirs)22 init_py = os.path.join(path, '__init__.py')23 open(init_py, 'a').close()24def init_test(testdir):25 """26 Instantiate a client test object from a given test directory.27 @param testdir The test directory.28 @returns A test object or None if failed to instantiate.29 """30 class options:31 tag = ''32 verbose = None33 cont = False34 harness = 'autoserv'35 hostname = None36 user = None37 log = True38 return client_setup_job.init_test(options, testdir)39def setup(autotest_client_dir, client_test_dir):40 """41 Setup prebuild of a client test.42 @param autotest_client_dir: The autotest/client base directory.43 @param client_test_dir: The actual test directory under client.44 """45 os.environ['AUTODIR'] = autotest_client_dir46 touch_init(autotest_client_dir, client_test_dir)47 # instantiate a client_test instance.48 client_test = init_test(client_test_dir)...
genmodules.py
Source:genmodules.py
1import os2import shutil3D = os.path.dirname(os.path.realpath(__file__))4directory = os.path.join(D, '../')5def touch_init(d):6 with open(os.path.join(d, '__init__.py'), 'w') as fh:7 fh.write('\n')8def gen_module_examples():9 d0 = os.path.join(directory, 'image')10 if os.path.isdir(d0):11 shutil.rmtree(d0)12 os.makedirs(d0)13 touch_init(d0)14 d1 = os.path.join(d0, 'filetypes')15 os.makedirs(d1)16 touch_init(d1)17 for f in ('jpg.py', 'pdf.py', 'png.py'):18 with open(os.path.join(d1, f), 'w') as fh:19 fh.write("""20def open_image(filename):21 print 'opening {0}'.format(filename)""")22 d2 = os.path.join(d0, 'manipulate')23 os.makedirs(d2)24 touch_init(d2)25 for f in ('convert.py', 'crop.py', 'filter.py'):26 fun = f.split('.')[0]27 with open(os.path.join(d2, f), 'w') as fh:28 fh.write("""29def {0}(filename):...
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!!