How to use register_dynamic_providers method in Sure

Best Python code snippet using sure_python

__init__.py

Source:__init__.py Github

copy

Full Screen

...235 return # ignore dynamically declared provides236 if not attr in context.__sure_providers_of__:237 context.__sure_providers_of__[attr] = []238 context.__sure_providers_of__[attr].append(func)239 def register_dynamic_providers(func, attr, args, kwargs):240 found = re.search(r"^[{](\d+)[}]$", attr)241 if not found:242 return # ignore dynamically declared provides243 index = int(found.group(1))244 assert index < len(args), (245 "the dynamic provider index: {%d} is bigger than %d, which is "246 "the length of the positional arguments passed to %s"247 % (index, len(args), func.__name__)248 )249 attr = args[index]250 if not attr in context.__sure_providers_of__:251 context.__sure_providers_of__[attr] = []252 context.__sure_providers_of__[attr].append(func)253 def ensure_providers(func, attr, args, kwargs):254 found = re.search(r"^[{](\d+)[}]$", attr)255 if found:256 index = int(found.group(1))257 attr = args[index]258 assert attr in context, (259 'the action "%s" was supposed to provide the attribute "%s" '260 "into the context, but it did not. Please double check its "261 "implementation" % (func.__name__, attr)262 )263 dependency_error_lonely = (264 'the action "%s" defined at %s:%d '265 'depends on the attribute "%s" to be available in the'266 " context. It turns out that there are no actions providing "267 "that. Please double-check the implementation"268 )269 dependency_error_hints = (270 'the action "%s" defined at %s:%d '271 'depends on the attribute "%s" to be available in the context.'272 " You need to call one of the following actions beforehand:\n"273 )274 def check_dependencies(func):275 action = func.__name__276 filename = _get_file_name(func)277 lineno = _get_line_number(func)278 for dependency in depends_on:279 if dependency in context.__sure_providers_of__:280 providers = context.__sure_providers_of__[dependency]281 err = dependency_error_hints % (282 action,283 filename,284 lineno,285 dependency,286 )287 err += "\n".join(288 [289 " -> %s at %s:%d"290 % (p.__name__, _get_file_name(p), _get_line_number(p))291 for p in providers292 ]293 )294 else:295 err = dependency_error_lonely % (296 action,297 filename,298 lineno,299 dependency,300 )301 assert dependency in context, err302 def decorate_and_absorb(func):303 [register_providers(func, attr) for attr in provides]304 @wraps(func)305 def wrapper(*args, **kw):306 [register_dynamic_providers(func, attr, args, kw) for attr in provides]307 context.__sure_actions_ran__.append((func, args, kw))308 check_dependencies(func)309 result = func(*args, **kw)310 [ensure_providers(func, attr, args, kw) for attr in provides]311 context.__sure_action_results__.append(result)312 return context313 setattr(context, func.__name__, wrapper)314 return wrapper315 return decorate_and_absorb316def work_in_progress(func):317 @wraps(func)318 def wrapper(*args, **kwargs):319 _registry["is_running"] = True320 ret = func(*args, **kwargs)...

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 Sure 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