How to use pending_step method in grail

Best Python code snippet using grail_python

buildorder.py

Source:buildorder.py Github

copy

Full Screen

1from debug import print2class BuildOrder:3 def __init__(self, steps):4 self.time = 05 self.steps = steps6 def is_over(self):7 return len(self.steps) == 08 def update(self, alien, dt):9 self.time += dt10 if self.is_over():11 return12 pending_step = self.steps[0]13 if self.time > pending_step.time:14 if not pending_step.triggered:15 print("trigger", str(pending_step))16 pending_step.trigger(alien)17 else:18 pending_step.update(alien, dt)19 if pending_step.done:20 print("done with", str(pending_step))21 self.steps.pop(0)22 elif pending_step.abandoned:23 print("abandoning", str(pending_step))24 self.steps.pop(0) 25class BuildOrderStep:26 name = "unimplemented"27 def __init__(self, time):28 self.time = time29 self.triggered = False30 self.done = False31 self.abandoned = False32 33 def trigger(self, alien):34 self.triggered = True35 def update(self, alien, dt):36 pass37class BOAttack(BuildOrderStep):38 name = "attack"39 ATTACK_TYPE_RANDOM = "random"40 ATTACK_TYPE_CENTRAL = "central"41 ATTACK_TYPE_OUTLYING = "outlying"42 def __init__(self, time, attack_type=None, attack_strength=1):43 super().__init__(time)44 self.attack_type = attack_type or self.ATTACK_TYPE_OUTLYING45 self.attack_strength = attack_strength46 self.duration = 047 def trigger(self, alien):48 self.done = alien.execute_attack(self.attack_type, self.attack_strength)49 return super().trigger(alien)50 # Need update in case it was impossible to attack before51 def update(self, alien, dt):52 self.duration += dt53 if self.duration > 20:54 self.abandoned = True55 return 56 if not self.done:57 self.done = alien.execute_attack(self.attack_type, self.attack_strength)58 return super().update(alien, dt)59 def __str__(self) -> str:60 return "%d: Attack %s" % (self.time, self.attack_type)61class BOExpand(BuildOrderStep):62 name = "expand"63 TARGET_TYPE_NEAR_HOME = "near_home"64 TARGET_TYPE_NEAR_ENEMY = "near_enemy"65 TARGET_TYPE_MIDDLE = "middle"66 TARGET_TYPE_RANDOM = "random"67 def __init__(self, time, target_type=None):68 super().__init__(time)69 self.target_type = target_type or self.TARGET_TYPE_NEAR_HOME70 self.duration = 071 def __str__(self) -> str:72 return "%d: Expand %s" % (self.time, self.target_type)73 def trigger(self, alien):74 self.done = alien.execute_expand(self.target_type)75 return super().trigger(alien)76 # Need update in case it was impossible to expand before77 def update(self, alien, dt):78 self.duration += dt79 if self.duration > 20:80 self.abandoned = True81 return 82 if not self.done:83 self.done = alien.execute_expand(self.target_type)84 return super().update(alien, dt)85class BOResearch(BuildOrderStep):86 name = "research"87 #TARGET_TYPE_LOW_ASSETS = "low_assets"88 TARGET_TYPE_LACKING_ASSET = "lacking_asset"89 TARGET_TYPE_RANDOM = "random"90 TARGET_TYPE_HOMEWORLD = "homeworld"91 TARGET_TYPE_UNDEFENDED = "undefended"92 def __init__(self, time, asset, backup=None, target_type=None):93 super().__init__(time)94 self.duration = 095 self.target_type = target_type or self.TARGET_TYPE_RANDOM96 self.asset = asset97 self.backup = backup98 def update(self, alien, dt):99 self.duration += dt100 if self.duration > 20:101 if self.backup:102 self.done = alien.execute_research(self.backup, self.target_type)103 if not self.done:104 self.abandoned = True105 return106 self.done = alien.execute_research(self.asset, self.target_type)107 108 return super().update(alien, dt)109 def trigger(self, alien):110 self.done = alien.execute_research(self.asset, self.target_type)111 return super().trigger(alien)112 def __str__(self) -> str:...

Full Screen

Full Screen

base_test.py

Source:base_test.py Github

copy

Full Screen

1import traceback2from functools import wraps3from unittest import TestCase4import grail.settings as settings5import grail.state as state6def handle_steps(func):7 @wraps(func)8 def wrapper(*args, **kwargs):9 try:10 state.is_test_wrapped = True11 result = func(*args, **kwargs)12 step_first_error = state.step_first_error13 pending_step = state.pending_step14 step_exception_traceback = state.step_exception_traceback15 step_stack = state.step_stack16 state.reset()17 if step_first_error is not None:18 for line in step_stack:19 print20 ' File "%s", line %i, in %s\n %s' % line21 print22 ''.join(traceback.format_tb(step_exception_traceback))23 raise step_first_error, None, step_exception_traceback24 if pending_step and not settings.export_mode:25 raise Exception('Test is failed as there are pending steps')26 return result27 finally:28 state.is_test_wrapped = False29 return wrapper30class BaseTestMeta(type):31 def __new__(mcs, name, bases, attrs):32 test_functions = {k: handle_steps(v) for k, v in attrs.iteritems() if k.startswith("test") and callable(v)}33 attrs.update(test_functions)34 cls = super(BaseTestMeta, mcs).__new__(mcs, name, bases, attrs)35 return cls36class BaseTest(TestCase):...

Full Screen

Full Screen

state.py

Source:state.py Github

copy

Full Screen

1step_first_error = None2pending_step = False3indentation = ''4step_execution_started = False5treat_nested_steps_as_methods_global = False6step_exception_traceback = None7step_stack = None8is_test_wrapped = False9def reset():10 global step_first_error11 global pending_step12 global indentation13 global step_execution_started14 global treat_nested_steps_as_methods_global15 global step_exception_traceback16 global step_stack17 global is_test_wrapped18 step_first_error = None19 pending_step = False20 indentation = ''21 step_execution_started = False22 treat_nested_steps_as_methods_global = False23 step_exception_traceback = None24 step_stack = None...

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