<s> from robotide . lib . robot . errors import ExecutionFailed , PassExecution <EOL> class Failure ( object ) : <EOL> def __init__ ( self ) : <EOL> self . setup = None <EOL> self . test = None <EOL> self . teardown = None <EOL> def __nonzero__ ( self ) : <EOL> return bool ( self . setup or self . test or self . teardown ) <EOL> class Exit ( object ) : <EOL> def __init__ ( self , failure_mode = False , error_mode = False , <EOL> skip_teardown_mode = False ) : <EOL> self . failure_mode = failure_mode <EOL> self . error_mode = error_mode <EOL> self . skip_teardown_mode = skip_teardown_mode <EOL> self . failure = False <EOL> self . error = False <EOL> self . fatal = False <EOL> def failure_occurred ( self , failure = None , critical = False ) : <EOL> if isinstance ( failure , ExecutionFailed ) and failure . exit : <EOL> self . fatal = True <EOL> if critical and self . failure_mode : <EOL> self . failure = True <EOL> def error_occurred ( self ) : <EOL> if self . error_mode : <EOL> self . error = True <EOL> @ property <EOL> def teardown_allowed ( self ) : <EOL> return not ( self . skip_teardown_mode and self ) <EOL> def __nonzero__ ( self ) : <EOL> return self . failure or self . error or self . fatal <EOL> class _ExecutionStatus ( object ) : <EOL> def __init__ ( self , parent = None , * exit_modes ) : <EOL> self . parent = parent <EOL> self . children = [ ] <EOL> self . failure = Failure ( ) <EOL> self . exit = parent . exit if parent else Exit ( * exit_modes ) <EOL> self . _teardown_allowed = False <EOL> if parent : <EOL> parent . children . append ( self ) <EOL> def setup_executed ( self , failure = None ) : <EOL> if failure and not isinstance ( failure , PassExecution ) : <EOL> self . failure . setup = unicode ( failure ) <EOL> self . exit . failure_occurred ( failure ) <EOL> self . _teardown_allowed = True <EOL> def teardown_executed ( self , failure = None ) : <EOL> if failure and not isinstance ( failure , PassExecution ) : <EOL> self . failure . teardown = unicode ( failure ) <EOL> self . exit . failure_occurred ( failure ) <EOL> def critical_failure_occurred ( self ) : <EOL> self . exit . failure_occurred ( critical = True ) <EOL> def error_occurred ( self ) : <EOL> self . exit . error_occurred ( ) <EOL> @ property <EOL> def teardown_allowed ( self ) : <EOL> return self . exit . teardown_allowed and self . _teardown_allowed <EOL> @ property <EOL> def failures ( self ) : <EOL> return bool ( self . parent and self . parent . failures or <EOL> self . failure or self . exit ) <EOL> def _parent_failures ( self ) : <EOL> return self . parent and self . parent . failures <EOL> @ property <EOL> def status ( self ) : <EOL> return '<STR_LIT>' if self . failures else '<STR_LIT>' <EOL> @ property <EOL> def message ( self ) : <EOL> if self . failure or self . exit : <EOL> return self . _my_message ( ) <EOL> if self . parent and self . parent . failures : <EOL> return self . _parent_message ( ) <EOL> return '<STR_LIT>' <EOL> def _my_message ( self ) : <EOL> raise NotImplementedError <EOL> def _parent_message ( self ) : <EOL> return ParentMessage ( self . parent ) . message <EOL> class SuiteStatus ( _ExecutionStatus ) : <EOL> def __init__ ( self , parent = None , exit_on_failure_mode = False , <EOL> exit_on_error_mode = False , <EOL> skip_teardown_on_exit_mode = False ) : <EOL> _ExecutionStatus . __init__ ( self , parent , exit_on_failure_mode , <EOL> exit_on_error_mode , <EOL> skip_teardown_on_exit_mode ) <EOL> def _my_message ( self ) : <EOL> return SuiteMessage ( self ) . message <EOL> class TestStatus ( _ExecutionStatus ) : <EOL> def __init__ ( self , parent , critical ) : <EOL> _ExecutionStatus . __init__ ( self , parent ) <EOL> self . exit = parent . exit <EOL> self . _critical = critical <EOL> def test_failed ( self , failure ) : <EOL> self . failure . test = unicode ( failure ) <EOL> self . exit . failure_occurred ( failure , self . _critical ) <EOL> def _my_message ( self ) : <EOL> return TestMessage ( self ) . message <EOL> class _Message ( object ) : <EOL> setup_message = NotImplemented <EOL> teardown_message = NotImplemented <EOL> also_teardown_message = NotImplemented <EOL> def __init__ ( self , status ) : <EOL> self . failure = status . failure <EOL> @ property <EOL> def message ( self ) : <EOL> msg = self . _get_message_before_teardown ( ) <EOL> return self . _get_message_after_teardown ( msg ) <EOL> def _get_message_before_teardown ( self ) : <EOL> if self . failure . setup : <EOL> return self . setup_message % self . failure . setup <EOL> return self . failure . test or '<STR_LIT>' <EOL> def _get_message_after_teardown ( self , msg ) : <EOL> if not self . failure . teardown : <EOL> return msg <EOL> if not msg : <EOL> return self . teardown_message % self . failure . teardown <EOL> return self . also_teardown_message % ( msg , self . failure . teardown ) <EOL> class TestMessage ( _Message ) : <EOL> setup_message = '<STR_LIT>' <EOL> teardown_message = '<STR_LIT>' <EOL> also_teardown_message = '<STR_LIT>' <EOL> exit_on_fatal_message = '<STR_LIT>' <EOL> exit_on_failure_message = '<STR_LIT>' <EOL> exit_on_error_message = '<STR_LIT>' <EOL> def __init__ ( self , status ) : <EOL> _Message . __init__ ( self , status ) <EOL> self . exit = status . exit <EOL> @ property <EOL> def message ( self ) : <EOL> message = super ( TestMessage , self ) . message <EOL> if message : <EOL> return message <EOL> if self . exit . failure : <EOL> return self . exit_on_failure_message <EOL> if self . exit . fatal : <EOL> return self . exit_on_fatal_message <EOL> if self . exit . error : <EOL> return self . exit_on_error_message <EOL> return '<STR_LIT>' <EOL> class SuiteMessage ( _Message ) : <EOL> setup_message = '<STR_LIT>' <EOL> teardown_message = '<STR_LIT>' <EOL> also_teardown_message = '<STR_LIT>' <EOL> class ParentMessage ( SuiteMessage ) : <EOL> setup_message = '<STR_LIT>' <EOL> teardown_message = '<STR_LIT>' <EOL> also_teardown_message = '<STR_LIT>' <EOL> def __init__ ( self , status ) : <EOL> while status . parent and status . parent . failures : <EOL> status = status . parent <EOL> SuiteMessage . __init__ ( self , status ) </s>
