How to use add_boilerplate_to_nested_steps method in autotest

Best Python code snippet using autotest_python

control_file.py

Source:control_file.py Github

copy

Full Screen

...147 else:148 template = CLIENT_KERNEL_TEMPLATE149 template_args['client_kernel_list'] = repr(new_kernel_list)150 return template % template_args151def add_boilerplate_to_nested_steps(lines):152 # Look for a line that begins with 'def step_init():' while153 # being flexible on spacing. If it's found, this will be154 # a nested set of steps, so add magic to make it work.155 # See client/bin/job.py's step_engine for more info.156 if re.search(r'^(.*\n)*def\s+step_init\s*\(\s*\)\s*:', lines):157 lines += '\nreturn locals() '158 lines += '# Boilerplate magic for nested sets of steps'159 return lines160def format_step(item, lines):161 lines = indent_text(lines, ' ')162 lines = 'def step%d():\n%s' % (item, lines)163 return lines164def get_tests_stanza(tests, is_server, prepend=None, append=None,165 client_control_file=''):166 """ Constructs the control file test step code from a list of tests.167 @param tests A sequence of test control files to run.168 @param is_server bool, Is this a server side test?169 @param prepend A list of steps to prepend to each client test.170 Defaults to [].171 @param append A list of steps to append to each client test.172 Defaults to [].173 @param client_control_file If specified, use this text as the body of a174 final client control file to run after tests. is_server must be False.175 @returns The control file test code to be run.176 """177 assert not (client_control_file and is_server)178 if not prepend:179 prepend = []180 if not append:181 append = []182 raw_control_files = [read_control_file(test) for test in tests]183 return _get_tests_stanza(raw_control_files, is_server, prepend, append,184 client_control_file=client_control_file)185def _get_tests_stanza(raw_control_files, is_server, prepend, append,186 client_control_file=''):187 """188 Implements the common parts of get_test_stanza.189 A site_control_file that wants to implement its own get_tests_stanza190 likely wants to call this in the end.191 @param raw_control_files A list of raw control file data to be combined192 into a single control file.193 @param is_server bool, Is this a server side test?194 @param prepend A list of steps to prepend to each client test.195 @param append A list of steps to append to each client test.196 @param client_control_file If specified, use this text as the body of a197 final client control file to append to raw_control_files after fixups.198 @returns The combined mega control file.199 """200 if client_control_file:201 # 'return locals()' is always appended incase the user forgot, it202 # is necessary to allow for nested step engine execution to work.203 raw_control_files.append(client_control_file + '\nreturn locals()')204 raw_steps = prepend + [add_boilerplate_to_nested_steps(step)205 for step in raw_control_files] + append206 steps = [format_step(index, step)207 for index, step in enumerate(raw_steps)]208 if is_server:209 step_template = SERVER_STEP_TEMPLATE210 footer = '\n\nstep_init()\n'211 else:212 step_template = CLIENT_STEP_TEMPLATE213 footer = ''214 header = ''.join(step_template % i for i in xrange(len(steps)))215 return header + '\n' + '\n\n'.join(steps) + footer216def indent_text(text, indent):217 """Indent given lines of python code avoiding indenting multiline218 quoted content (only for triple " and ' quoting for now)."""...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful