<s> from robot . errors import DataError <EOL> from robot . variables import GLOBAL_VARIABLES <EOL> class ExecutionContexts ( object ) : <EOL> def __init__ ( self ) : <EOL> self . _contexts = [ ] <EOL> @ property <EOL> def current ( self ) : <EOL> return self . _contexts [ - <NUM_LIT:1> ] if self . _contexts else None <EOL> def __iter__ ( self ) : <EOL> return iter ( self . _contexts ) <EOL> @ property <EOL> def namespaces ( self ) : <EOL> return ( context . namespace for context in self ) <EOL> def start_suite ( self , namespace , output , dry_run = False ) : <EOL> self . _contexts . append ( _ExecutionContext ( namespace , output , dry_run ) ) <EOL> return self . current <EOL> def end_suite ( self ) : <EOL> self . _contexts . pop ( ) <EOL> EXECUTION_CONTEXTS = ExecutionContexts ( ) <EOL> class _ExecutionContext ( object ) : <EOL> _started_keywords_threshold = <NUM_LIT> <EOL> def __init__ ( self , namespace , output , dry_run = False ) : <EOL> self . namespace = namespace <EOL> self . output = output <EOL> self . dry_run = dry_run <EOL> self . _in_teardown = <NUM_LIT:0> <EOL> self . _started_keywords = <NUM_LIT:0> <EOL> @ property <EOL> def teardown ( self ) : <EOL> if self . _in_teardown : <EOL> return True <EOL> test_or_suite = self . namespace . test or self . namespace . suite <EOL> return test_or_suite . status != '<STR_LIT>' <EOL> def start_keyword_teardown ( self , error ) : <EOL> self . namespace . variables [ '<STR_LIT>' ] = '<STR_LIT>' if error else '<STR_LIT>' <EOL> self . namespace . variables [ '<STR_LIT>' ] = unicode ( error or '<STR_LIT>' ) <EOL> self . _in_teardown += <NUM_LIT:1> <EOL> def end_keyword_teardown ( self ) : <EOL> self . _in_teardown -= <NUM_LIT:1> <EOL> def get_current_vars ( self ) : <EOL> return self . namespace . variables <EOL> def end_test ( self , test ) : <EOL> self . output . end_test ( test ) <EOL> self . namespace . end_test ( ) <EOL> def end_suite ( self , suite ) : <EOL> self . output . end_suite ( suite ) <EOL> self . namespace . end_suite ( ) <EOL> EXECUTION_CONTEXTS . end_suite ( ) <EOL> def output_file_changed ( self , filename ) : <EOL> self . _set_global_variable ( '<STR_LIT>' , filename ) <EOL> def replace_vars_from_setting ( self , name , value , errors ) : <EOL> return self . namespace . variables . replace_meta ( name , value , errors ) <EOL> def log_file_changed ( self , filename ) : <EOL> self . _set_global_variable ( '<STR_LIT>' , filename ) <EOL> def set_prev_test_variables ( self , test ) : <EOL> self . _set_prev_test_variables ( self . get_current_vars ( ) , test . name , <EOL> test . status , test . message ) <EOL> def copy_prev_test_vars_to_global ( self ) : <EOL> varz = self . get_current_vars ( ) <EOL> name , status , message = varz [ '<STR_LIT>' ] , varz [ '<STR_LIT>' ] , varz [ '<STR_LIT>' ] <EOL> self . _set_prev_test_variables ( GLOBAL_VARIABLES , name , status , message ) <EOL> def _set_prev_test_variables ( self , destination , name , status , message ) : <EOL> destination [ '<STR_LIT>' ] = name <EOL> destination [ '<STR_LIT>' ] = status <EOL> destination [ '<STR_LIT>' ] = message <EOL> def _set_global_variable ( self , name , value ) : <EOL> self . namespace . variables . set_global ( name , value ) <EOL> def report_suite_status ( self , status , message ) : <EOL> self . get_current_vars ( ) [ '<STR_LIT>' ] = status <EOL> self . get_current_vars ( ) [ '<STR_LIT>' ] = message <EOL> def start_test ( self , test ) : <EOL> self . namespace . start_test ( test ) <EOL> self . output . start_test ( test ) <EOL> def set_test_status_before_teardown ( self , message , status ) : <EOL> self . namespace . set_test_status_before_teardown ( message , status ) <EOL> def get_handler ( self , name ) : <EOL> return self . namespace . get_handler ( name ) <EOL> def start_keyword ( self , keyword ) : <EOL> self . _started_keywords += <NUM_LIT:1> <EOL> if self . _started_keywords > self . _started_keywords_threshold : <EOL> raise DataError ( '<STR_LIT>' ) <EOL> self . output . start_keyword ( keyword ) <EOL> def end_keyword ( self , keyword ) : <EOL> self . output . end_keyword ( keyword ) <EOL> self . _started_keywords -= <NUM_LIT:1> <EOL> def start_user_keyword ( self , kw ) : <EOL> self . namespace . start_user_keyword ( kw ) <EOL> def end_user_keyword ( self ) : <EOL> self . namespace . end_user_keyword ( ) <EOL> def warn ( self , message ) : <EOL> self . output . warn ( message ) <EOL> def trace ( self , message ) : <EOL> self . output . trace ( message ) </s>
