Best Python code snippet using yandex-tank
docs_gen.py
Source:docs_gen.py
...237 :type option_schema: dict238 """239 self.option_name, self.option_kwargs = next(iter(option_schema.items()))240 # print(option_name, option_kwargs)241 self.formatter = self.__guess_formatter()242 def format_dsc(self, renderer):243 dsc = self.option_kwargs.get(DESCRIPTION, NO_DSC).strip('. ')244 if DEFAULT in self.option_kwargs:245 default_value = self.option_kwargs.get(DEFAULT)246 if default_value == '':247 default_value = '""'248 return ' '.join([renderer.italic('- {}. Default:'.format(dsc)),249 renderer.mono(default_value)])250 elif REQUIRED in self.option_kwargs:251 return renderer.italic('- {}.'.format(dsc)) +\252 ' ' +\253 renderer.bold('Required.')254 else:255 return renderer.italic('- {}.'.format(dsc))256 def scalar_formatter(self, renderer, header=True):257 hdr = renderer.subtitle(renderer.mono(self.option_name) + ' ' + '({})'.format(self.option_kwargs.get(TYPE))) \258 if header else ''259 dsc = self.format_dsc(renderer)260 body = render_body(renderer, self.option_kwargs, [VALIDATOR, TYPE, DESCRIPTION, DEFAULT, REQUIRED], {'allowed': allowed})261 return '\n'.join([_ for _ in [hdr, dsc, body] if _])262 def scalar_with_values_description(self, renderer, header=True):263 hdr = renderer.subtitle(renderer.mono(self.option_name) + ' ' + '({})'.format(self.option_kwargs.get(TYPE))) \264 if header else ''265 dsc = self.format_dsc(renderer)266 body = render_body(renderer, self.option_kwargs, [VALIDATOR, TYPE, DESCRIPTION, DEFAULT, REQUIRED, ALLOWED, VALUES_DSC])267 values_description_block = render_values_description(renderer, self.option_kwargs)268 return '\n'.join([_ for _ in [hdr, dsc, body, values_description_block] if _])269 def dict_formatter(self, renderer, header=True):270 hdr = renderer.subtitle(renderer.mono(self.option_name) + ' ' + '({})'.format(self.option_kwargs.get(TYPE))) \271 if header else ''272 dsc = self.format_dsc(renderer)273 dict_schema = self.option_kwargs[SCHEMA]274 schema_block = renderer.field_list({275 '{} ({})'.format(renderer.mono(key), dict_schema[key].get(TYPE, 'anyof')): get_formatter({key: value})(renderer, header=False)276 for key, value in dict_schema.items()})277 body = render_body(renderer, self.option_kwargs, [VALIDATOR, TYPE, DESCRIPTION, DEFAULT, REQUIRED, SCHEMA])278 return '\n'.join([_ for _ in [hdr, dsc, schema_block, body] if _])279 def anyof_formatter(self, renderer, header=True):280 types = [case[TYPE] for case in self.option_kwargs[ANYOF] if TYPE in case]281 hdr = renderer.subtitle(renderer.mono(self.option_name) + ' ' + '({})'.format(' or '.join(types))) \282 if header else ''283 dsc = self.format_dsc(renderer)284 values_description_block = render_values_description(renderer, self.option_kwargs) \285 if VALUES_DSC in self.option_kwargs else ''286 body = render_body(renderer, self.option_kwargs, [VALIDATOR, TYPE, DESCRIPTION, DEFAULT, REQUIRED, ANYOF, VALUES_DSC])287 return '\n'.join([_ for _ in [hdr, dsc, values_description_block, body] if _])288 def list_formatter(self, renderer, header=True):289 schema = self.option_kwargs[SCHEMA]290 hdr = renderer.subtitle(renderer.mono(self.option_name) + ' '291 + '({} of {})'.format(self.option_kwargs.get(TYPE, LIST), schema.get(TYPE, '')))292 dsc = self.format_dsc(renderer)293 body = render_body(renderer, self.option_kwargs, [VALIDATOR, TYPE, DEFAULT, REQUIRED, DESCRIPTION, SCHEMA])294 if set(schema.keys()) - {TYPE}:295 schema_block = renderer.field_list({296 '[list_element] ({})'.format(schema.get(TYPE, '')):297 get_formatter({'list_element': schema})(renderer, header=False)298 })299 return '\n'.join([_ for _ in [hdr, dsc, schema_block, body] if _])300 else:301 return '\n'.join([_ for _ in [hdr, dsc, body] if _])302 def __guess_formatter(self):303 if ANYOF in self.option_kwargs:304 return self.anyof_formatter305 elif SCHEMA in self.option_kwargs:306 return self.list_formatter if self.option_kwargs.get(TYPE) == LIST else self.dict_formatter307 elif VALUES_DSC in self.option_kwargs:308 return self.scalar_with_values_description309 else:310 return self.scalar_formatter311def get_formatter(option_schema):312 """313 :type option_schema: dict314 """315 return OptionFormatter(option_schema).formatter316def format_option(option_schema, renderer):...
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!!