Best Python code snippet using grail_python
step_info.py
Source:step_info.py
...32 args = args[1:]33 return args, self.kwargs34 def _get_name_based_description(self):35 return ' '.join(self.function.func_name.split('_'))36 def _get_arguments_string(self):37 args, kwargs = self._get_clean_params()38 if settings.export_mode:39 args = [arg for arg in args if arg]40 kwargs = {k: v for k, v in kwargs.items() if v}41 if len(args) == 0 and len(kwargs) == 0:42 return ''43 args = map(unicode_replace, args)44 kw_arguments = ['{0}={1}'.format(k, v) for k, v in kwargs.items()]45 return ' (' + ', '.join(args + kw_arguments) + ')'46 def run_function(self):47 start = time.time()48 result = self.function(*self.args, **self.kwargs)49 self.elapsed_time = time.time() - start50 return result51 def get_description(self, output, result, exception_instance):52 message = ''53 if settings.export_mode:54 if result == StepResults.FAILED:55 raise RuntimeError('Unexpected failure during export')56 else:57 if settings.print_step_time:58 message += settings.step_time_template.format(self.elapsed_time)59 message += result + ' '60 if self.format_description:61 args, kwargs = self._get_clean_params()62 message += self.description.format(*args, **kwargs)63 else:64 message += self.description or self._get_name_based_description()65 if self.log_input:66 message += self._get_arguments_string()67 if self.log_output and output:68 message += ' -> ' + unicode_replace(output)69 if exception_instance:70 message += ': %s' % unicode_replace(exception_instance)...
_gql_type.py
Source:_gql_type.py
...10 def generate_query_lines(cls) -> Iterator[str]:11 fields = typing.get_type_hints(cls)12 for field_name, field_type in fields.items():13 field = cls.__fields__[field_name]14 arguments_str = _get_arguments_string(field.field_info.extra)15 if typing.get_origin(field_type) is list:16 args = typing.get_args(field_type)17 if len(args) != 1:18 raise QueryGenerationError(19 f"Type '{field_type}' has unexpected amount of arguments"20 )21 field_type = args[0]22 if typing.get_origin(field_type) is UnionType:23 sub_types = typing.get_args(field_type)24 yield field.alias + arguments_str + " {"25 for sub_type in sub_types:26 if sub_type is object:27 continue28 if not issubclass(sub_type, GQLType):29 raise QueryGenerationError(30 f"Member '{sub_type}' of a union type"31 f"must be a subtype of '{GQLType.__name__}'"32 )33 yield " " + "... on " + sub_type.__name__ + " {"34 for line in sub_type.generate_query_lines():35 yield " " * 2 + line36 yield " " + "}"37 yield "}"38 continue39 if not inspect.isclass(field_type):40 raise QueryGenerationError(f"Type {field_type} is not supported")41 if issubclass(field_type, GQLType):42 field_type.update_forward_refs()43 yield field.alias + arguments_str + " {"44 for line in field_type.generate_query_lines():45 yield " " + line46 yield "}"47 continue48 yield field.alias + arguments_str49 continue50 class Config:51 alias_generator = key_to_graphql52 allow_population_by_field_name = True53def _get_arguments_string(arguments: dict[str, Any]) -> str:54 if not arguments:55 return ""56 def _generate():57 for name, value in arguments.items():58 yield key_to_graphql(name) + ": " + value_to_graphql(value)...
logger_wrapper.py
Source:logger_wrapper.py
1'''Reviewed version of logger_wrapper.py from lesson 6'''2def _get_arguments_string(*args, **kwargs):3 return ', '.join(4 ['{0!r}'.format(i) for i in args] +5 ['{0}={1!r}'.format(k, v) for k, v in kwargs.items()]6 )7def logger_wrapper(foo, *args, **kwargs):8 print('--log: {0}({1})'9 .format(foo.__name__, _get_arguments_string(*args, **kwargs)))10 foo(*args, **kwargs)11if __name__ == '__main__':12 def buz(a, b, c, d, e):13 print('In buz() function')14 buz(1, 2, 3, d=12, e=11)...
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!!