<s> from robot . output import LEVELS <EOL> from . jsbuildingcontext import JsBuildingContext <EOL> from . jsexecutionresult import JsExecutionResult <EOL> class JsModelBuilder ( object ) : <EOL> def __init__ ( self , log_path = None , split_log = False , <EOL> prune_input_to_save_memory = False ) : <EOL> self . _context = JsBuildingContext ( log_path , split_log , <EOL> prune_input_to_save_memory ) <EOL> def build_from ( self , result_from_xml ) : <EOL> return JsExecutionResult ( <EOL> statistics = StatisticsBuilder ( ) . build ( result_from_xml . statistics ) , <EOL> suite = SuiteBuilder ( self . _context ) . build ( result_from_xml . suite ) , <EOL> errors = ErrorsBuilder ( self . _context ) . build ( result_from_xml . errors ) , <EOL> strings = self . _context . strings , <EOL> basemillis = self . _context . basemillis , <EOL> split_results = self . _context . split_results , <EOL> min_level = self . _context . min_level <EOL> ) <EOL> class _Builder ( object ) : <EOL> _statuses = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> } <EOL> def __init__ ( self , context ) : <EOL> self . _context = context <EOL> self . _string = self . _context . string <EOL> self . _html = self . _context . html <EOL> self . _timestamp = self . _context . timestamp <EOL> def _get_status ( self , item ) : <EOL> model = ( self . _statuses [ item . status ] , <EOL> self . _timestamp ( item . starttime ) , <EOL> item . elapsedtime ) <EOL> msg = getattr ( item , '<STR_LIT:message>' , '<STR_LIT>' ) <EOL> if not msg : <EOL> return model <EOL> elif msg . startswith ( '<STR_LIT>' ) : <EOL> msg = self . _string ( msg [ <NUM_LIT:6> : ] . lstrip ( ) , escape = False ) <EOL> else : <EOL> msg = self . _string ( msg ) <EOL> return model + ( msg , ) <EOL> def _build_keywords ( self , kws , split = False ) : <EOL> splitting = self . _context . start_splitting_if_needed ( split ) <EOL> model = tuple ( self . _build_keyword ( k ) for k in kws ) <EOL> return model if not splitting else self . _context . end_splitting ( model ) <EOL> class SuiteBuilder ( _Builder ) : <EOL> def __init__ ( self , context ) : <EOL> _Builder . __init__ ( self , context ) <EOL> self . _build_suite = self . build <EOL> self . _build_test = TestBuilder ( context ) . build <EOL> self . _build_keyword = KeywordBuilder ( context ) . build <EOL> def build ( self , suite ) : <EOL> with self . _context . prune_input ( suite . suites , suite . tests , suite . keywords ) : <EOL> stats = self . _get_statistics ( suite ) <EOL> return ( self . _string ( suite . name , attr = True ) , <EOL> self . _string ( suite . source ) , <EOL> self . _context . relative_source ( suite . source ) , <EOL> self . _html ( suite . doc ) , <EOL> tuple ( self . _yield_metadata ( suite ) ) , <EOL> self . _get_status ( suite ) , <EOL> tuple ( self . _build_suite ( s ) for s in suite . suites ) , <EOL> tuple ( self . _build_test ( t ) for t in suite . tests ) , <EOL> tuple ( self . _build_keyword ( k , split = True ) for k in suite . keywords ) , <EOL> stats ) <EOL> def _yield_metadata ( self , suite ) : <EOL> for name , value in suite . metadata . items ( ) : <EOL> yield self . _string ( name ) <EOL> yield self . _html ( value ) <EOL> def _get_statistics ( self , suite ) : <EOL> stats = suite . statistics <EOL> return ( stats . all . total , <EOL> stats . all . passed , <EOL> stats . critical . total , <EOL> stats . critical . passed ) <EOL> class TestBuilder ( _Builder ) : <EOL> def __init__ ( self , context ) : <EOL> _Builder . __init__ ( self , context ) <EOL> self . _build_keyword = KeywordBuilder ( context ) . build <EOL> def build ( self , test ) : <EOL> with self . _context . prune_input ( test . keywords ) : <EOL> return ( self . _string ( test . name , attr = True ) , <EOL> self . _string ( test . timeout ) , <EOL> int ( test . critical ) , <EOL> self . _html ( test . doc ) , <EOL> tuple ( self . _string ( t ) for t in test . tags ) , <EOL> self . _get_status ( test ) , <EOL> self . _build_keywords ( test . keywords , split = True ) ) <EOL> class KeywordBuilder ( _Builder ) : <EOL> _types = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:4> } <EOL> def __init__ ( self , context ) : <EOL> _Builder . __init__ ( self , context ) <EOL> self . _build_keyword = self . build <EOL> self . _build_message = MessageBuilder ( context ) . build <EOL> def build ( self , kw , split = False ) : <EOL> with self . _context . prune_input ( kw . messages , kw . keywords ) : <EOL> return ( self . _types [ kw . type ] , <EOL> self . _string ( kw . kwname , attr = True ) , <EOL> self . _string ( kw . libname , attr = True ) , <EOL> self . _string ( kw . timeout ) , <EOL> self . _html ( kw . doc ) , <EOL> self . _string ( '<STR_LIT:U+002CU+0020>' . join ( kw . args ) ) , <EOL> self . _string ( '<STR_LIT:U+002CU+0020>' . join ( kw . assign ) ) , <EOL> self . _string ( '<STR_LIT:U+002CU+0020>' . join ( kw . tags ) ) , <EOL> self . _get_status ( kw ) , <EOL> self . _build_keywords ( kw . keywords , split ) , <EOL> tuple ( self . _build_message ( m ) for m in kw . messages ) ) <EOL> class MessageBuilder ( _Builder ) : <EOL> def build ( self , msg ) : <EOL> if msg . level in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . _context . create_link_target ( msg ) <EOL> self . _context . message_level ( msg . level ) <EOL> return self . _build ( msg ) <EOL> def _build ( self , msg ) : <EOL> return ( self . _timestamp ( msg . timestamp ) , <EOL> LEVELS [ msg . level ] , <EOL> self . _string ( msg . html_message , escape = False ) ) <EOL> class StatisticsBuilder ( object ) : <EOL> def build ( self , statistics ) : <EOL> return ( self . _build_stats ( statistics . total ) , <EOL> self . _build_stats ( statistics . tags ) , <EOL> self . _build_stats ( statistics . suite ) ) <EOL> def _build_stats ( self , stats ) : <EOL> return tuple ( stat . get_attributes ( include_label = True , <EOL> include_elapsed = True , <EOL> html_escape = True ) <EOL> for stat in stats ) <EOL> class ErrorsBuilder ( _Builder ) : <EOL> def __init__ ( self , context ) : <EOL> _Builder . __init__ ( self , context ) <EOL> self . _build_message = ErrorMessageBuilder ( context ) . build <EOL> def build ( self , errors ) : <EOL> with self . _context . prune_input ( errors . messages ) : <EOL> return tuple ( self . _build_message ( msg ) for msg in errors ) <EOL> class ErrorMessageBuilder ( MessageBuilder ) : <EOL> def build ( self , msg ) : <EOL> model = self . _build ( msg ) <EOL> link = self . _context . link ( msg ) <EOL> return model if link is None else model + ( link , ) </s>
