<s> from robot import utils <EOL> from robot . common import BaseTestSuite , BaseTestCase <EOL> from robot . parsing import TestData <EOL> from robot . errors import ExecutionFailed , DataError <EOL> from robot . variables import GLOBAL_VARIABLES <EOL> from robot . output import LOGGER <EOL> from . fixture import ( Setup , Teardown , SuiteSetupListener , SuiteTearDownListener , <EOL> TestSetupListener , TestTeardownListener ) <EOL> from . keywords import Keywords <EOL> from . namespace import Namespace <EOL> from . runerrors import SuiteRunErrors , TestRunErrors <EOL> from . userkeyword import UserLibrary <EOL> from . context import EXECUTION_CONTEXTS <EOL> from . defaultvalues import DefaultValues <EOL> def TestSuite ( datasources , settings ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( datasources , basestring ) : <EOL> datasources = [ datasources ] <EOL> datasources = [ utils . abspath ( path ) for path in datasources ] <EOL> suite = _get_suite ( datasources , settings [ '<STR_LIT>' ] , settings [ '<STR_LIT>' ] ) <EOL> suite . set_options ( settings ) <EOL> _check_suite_contains_tests ( suite , settings [ '<STR_LIT>' ] ) <EOL> return suite <EOL> def _get_suite ( datasources , include_suites , warn_on_skipped ) : <EOL> if not datasources : <EOL> raise DataError ( "<STR_LIT>" ) <EOL> if len ( datasources ) > <NUM_LIT:1> : <EOL> return _get_multisource_suite ( datasources , include_suites , warn_on_skipped ) <EOL> return RunnableTestSuite ( _parse_suite ( datasources [ <NUM_LIT:0> ] , include_suites , warn_on_skipped ) ) <EOL> def _parse_suite ( path , include_suites , warn_on_skipped ) : <EOL> try : <EOL> return TestData ( source = path , include_suites = include_suites , warn_on_skipped = warn_on_skipped ) <EOL> except DataError , err : <EOL> raise DataError ( "<STR_LIT>" % ( path , unicode ( err ) ) ) <EOL> def _get_multisource_suite ( datasources , include_suites , warn_on_skipped ) : <EOL> suitedatas = [ ] <EOL> for datasource in datasources : <EOL> try : <EOL> suitedatas . append ( _parse_suite ( datasource , include_suites , warn_on_skipped ) ) <EOL> except DataError , err : <EOL> LOGGER . warn ( err ) <EOL> suite = RunnableMultiTestSuite ( suitedatas ) <EOL> if suite . get_test_count ( ) == <NUM_LIT:0> : <EOL> raise DataError ( "<STR_LIT>" <EOL> % utils . seq2str ( datasources ) ) <EOL> return suite <EOL> def _check_suite_contains_tests ( suite , run_empty_suites = False ) : <EOL> suite . filter_empty_suites ( ) <EOL> if not suite . get_test_count ( ) and not run_empty_suites : <EOL> raise DataError ( "<STR_LIT>" % ( suite . source ) ) <EOL> class RunnableTestSuite ( BaseTestSuite ) : <EOL> def __init__ ( self , data , parent = None , defaults = None ) : <EOL> BaseTestSuite . __init__ ( self , data . name , data . source , parent ) <EOL> self . variables = GLOBAL_VARIABLES . copy ( ) <EOL> self . variables . set_from_variable_table ( data . variable_table ) <EOL> self . source = data . source <EOL> self . doc = data . setting_table . doc . value <EOL> self . metadata = self . _get_metadata ( data . setting_table . metadata ) <EOL> self . imports = data . imports <EOL> self . user_keywords = UserLibrary ( data . keywords ) <EOL> self . setup = Setup ( data . setting_table . suite_setup . name , <EOL> data . setting_table . suite_setup . args ) <EOL> self . teardown = Teardown ( data . setting_table . suite_teardown . name , <EOL> data . setting_table . suite_teardown . args ) <EOL> defaults = DefaultValues ( data . setting_table , defaults ) <EOL> for suite in data . children : <EOL> RunnableTestSuite ( suite , parent = self , defaults = defaults ) <EOL> for test in data . testcase_table : <EOL> RunnableTestCase ( test , parent = self , defaults = defaults ) <EOL> self . _run_mode_exit_on_failure = False <EOL> self . _run_mode_dry_run = False <EOL> self . _run_mode_skip_teardowns_on_exit = False <EOL> def filter_empty_suites ( self ) : <EOL> for suite in self . suites [ : ] : <EOL> suite . filter_empty_suites ( ) <EOL> if suite . get_test_count ( ) == <NUM_LIT:0> : <EOL> self . suites . remove ( suite ) <EOL> LOGGER . info ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( suite . source ) ) <EOL> def _get_metadata ( self , metadata ) : <EOL> meta = utils . NormalizedDict ( ) <EOL> for item in metadata : <EOL> meta [ item . name ] = item . value <EOL> return meta <EOL> def run ( self , output , parent = None , errors = None ) : <EOL> context = self . _start_run ( output , parent , errors ) <EOL> self . _run_setup ( context ) <EOL> self . _run_sub_suites ( context ) <EOL> self . _run_tests ( context ) <EOL> self . _report_status ( context ) <EOL> self . _run_teardown ( context ) <EOL> self . _end_run ( context ) <EOL> def _start_run ( self , output , parent , errors ) : <EOL> if not errors : <EOL> errors = SuiteRunErrors ( self . _run_mode_exit_on_failure , self . _run_mode_skip_teardowns_on_exit ) <EOL> self . run_errors = errors <EOL> self . run_errors . start_suite ( ) <EOL> self . status = '<STR_LIT>' <EOL> self . starttime = utils . get_timestamp ( ) <EOL> parent_vars = parent . context . get_current_vars ( ) if parent else None <EOL> ns = Namespace ( self , parent_vars ) <EOL> self . context = EXECUTION_CONTEXTS . start_suite ( ns , output , self . _run_mode_dry_run ) <EOL> if not errors . exit : <EOL> ns . handle_imports ( ) <EOL> self . _set_variable_dependent_metadata ( self . context ) <EOL> output . start_suite ( self ) <EOL> return self . context <EOL> def _set_variable_dependent_metadata ( self , context ) : <EOL> errors = [ ] <EOL> self . doc = context . replace_vars_from_setting ( '<STR_LIT>' , self . doc , <EOL> errors ) <EOL> self . setup . replace_variables ( context . get_current_vars ( ) , errors ) <EOL> self . teardown . replace_variables ( context . get_current_vars ( ) , errors ) <EOL> for name , value in self . metadata . items ( ) : <EOL> self . metadata [ name ] = context . replace_vars_from_setting ( name , value , <EOL> errors ) <EOL> if errors : <EOL> self . run_errors . suite_init_err ( '<STR_LIT>' <EOL> % '<STR_LIT:\n>' . join ( errors ) ) <EOL> def _run_setup ( self , context ) : <EOL> if self . run_errors . is_suite_setup_allowed ( ) : <EOL> self . setup . run ( context , SuiteSetupListener ( self ) ) <EOL> self . run_errors . setup_executed ( ) <EOL> def _run_teardown ( self , context ) : <EOL> if self . run_errors . is_suite_teardown_allowed ( ) : <EOL> self . teardown . run ( context , SuiteTearDownListener ( self ) ) <EOL> def _run_sub_suites ( self , context ) : <EOL> for suite in self . suites : <EOL> suite . run ( context . output , self , self . run_errors ) <EOL> def _run_tests ( self , context ) : <EOL> executed_tests = [ ] <EOL> for test in self . tests : <EOL> normname = utils . normalize ( test . name ) <EOL> if normname in executed_tests : <EOL> LOGGER . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( test . name , self . longname ) ) <EOL> executed_tests . append ( normname ) <EOL> test . run ( context , self . run_errors ) <EOL> context . set_prev_test_variables ( test ) <EOL> def _report_status ( self , context ) : <EOL> self . set_status ( ) <EOL> self . message = self . run_errors . suite_error ( ) <EOL> context . report_suite_status ( self . status , self . get_full_message ( ) ) <EOL> def _end_run ( self , context ) : <EOL> self . endtime = utils . get_timestamp ( ) <EOL> self . elapsedtime = utils . get_elapsed_time ( self . starttime , self . endtime ) <EOL> context . copy_prev_test_vars_to_global ( ) <EOL> context . end_suite ( self ) <EOL> self . run_errors . end_suite ( ) <EOL> class RunnableMultiTestSuite ( RunnableTestSuite ) : <EOL> def __init__ ( self , suitedatas ) : <EOL> BaseTestSuite . __init__ ( self , name = '<STR_LIT>' ) <EOL> self . variables = GLOBAL_VARIABLES . copy ( ) <EOL> self . doc = '<STR_LIT>' <EOL> self . imports = [ ] <EOL> self . setup = Setup ( None , None ) <EOL> self . teardown = Teardown ( None , None ) <EOL> for suite in suitedatas : <EOL> RunnableTestSuite ( suite , parent = self ) <EOL> self . _run_mode_exit_on_failure = False <EOL> self . _run_mode_dry_run = False <EOL> self . _run_mode_skip_teardowns_on_exit = False <EOL> class RunnableTestCase ( BaseTestCase ) : <EOL> def __init__ ( self , tc_data , parent , defaults ) : <EOL> BaseTestCase . __init__ ( self , tc_data . name , parent ) <EOL> self . doc = tc_data . doc . value <EOL> self . setup = defaults . get_setup ( tc_data . setup ) <EOL> self . teardown = defaults . get_teardown ( tc_data . teardown ) <EOL> self . tags = defaults . get_tags ( tc_data . tags ) <EOL> self . timeout = defaults . get_timeout ( tc_data . timeout ) <EOL> self . template = defaults . get_template ( tc_data . template ) <EOL> self . keywords = Keywords ( tc_data . steps , self . template ) <EOL> def run ( self , context , suite_errors ) : <EOL> self . _suite_errors = suite_errors <EOL> self . _start_run ( context ) <EOL> if self . run_errors . is_allowed_to_run ( ) : <EOL> self . _run ( context ) <EOL> else : <EOL> self . _not_allowed_to_run ( ) <EOL> self . _end_run ( context ) <EOL> def _start_run ( self , context ) : <EOL> self . run_errors = TestRunErrors ( self . _suite_errors ) <EOL> self . status = '<STR_LIT>' <EOL> self . starttime = utils . get_timestamp ( ) <EOL> self . run_errors . init_err ( self . _init_test ( context ) ) <EOL> context . start_test ( self ) <EOL> def _init_test ( self , context ) : <EOL> errors = [ ] <EOL> self . doc = context . replace_vars_from_setting ( '<STR_LIT>' , self . doc , <EOL> errors ) <EOL> self . setup . replace_variables ( context . get_current_vars ( ) , errors ) <EOL> self . teardown . replace_variables ( context . get_current_vars ( ) , errors ) <EOL> tags = context . replace_vars_from_setting ( '<STR_LIT>' , self . tags , errors ) <EOL> self . tags = utils . normalize_tags ( tags ) <EOL> self . timeout . replace_variables ( context . get_current_vars ( ) ) <EOL> if errors : <EOL> return '<STR_LIT>' % '<STR_LIT:\n>' . join ( errors ) <EOL> if not self . name : <EOL> return '<STR_LIT>' <EOL> if not self . keywords : <EOL> return '<STR_LIT>' <EOL> return None <EOL> def _run ( self , context ) : <EOL> self . timeout . start ( ) <EOL> self . _run_setup ( context ) <EOL> if not self . run_errors . setup_failed ( ) : <EOL> try : <EOL> self . keywords . run ( context ) <EOL> except ExecutionFailed , err : <EOL> self . run_errors . kw_err ( unicode ( err ) ) <EOL> self . keyword_failed ( err ) <EOL> context . set_test_status_before_teardown ( * self . _report_status ( ) ) <EOL> self . _run_teardown ( context ) <EOL> self . _report_status_after_teardown ( ) <EOL> def keyword_failed ( self , err ) : <EOL> self . timeout . set_keyword_timeout ( err . timeout ) <EOL> self . _suite_errors . test_failed ( exit = err . exit , critical = self . critical ) <EOL> def _run_setup ( self , context ) : <EOL> self . setup . run ( context , TestSetupListener ( self ) ) <EOL> def _report_status ( self ) : <EOL> message = self . run_errors . get_message ( ) <EOL> if message : <EOL> self . status = '<STR_LIT>' <EOL> self . message = message <EOL> else : <EOL> self . status = '<STR_LIT>' <EOL> return self . message , self . status <EOL> def _run_teardown ( self , context ) : <EOL> if self . _suite_errors . is_test_teardown_allowed ( ) : <EOL> self . teardown . run ( context , TestTeardownListener ( self ) ) <EOL> def _report_status_after_teardown ( self ) : <EOL> if self . run_errors . teardown_failed ( ) : <EOL> self . status = '<STR_LIT>' <EOL> self . message = self . run_errors . get_teardown_message ( self . message ) <EOL> if self . status == '<STR_LIT>' and self . timeout . timed_out ( ) : <EOL> self . status = '<STR_LIT>' <EOL> self . message = self . timeout . get_message ( ) <EOL> if self . status == '<STR_LIT>' : <EOL> self . _suite_errors . test_failed ( critical = self . critical ) <EOL> def _not_allowed_to_run ( self ) : <EOL> self . status = '<STR_LIT>' <EOL> self . message = self . run_errors . parent_or_init_error ( ) <EOL> def _end_run ( self , context ) : <EOL> self . endtime = utils . get_timestamp ( ) <EOL> self . elapsedtime = utils . get_elapsed_time ( self . starttime , self . endtime ) <EOL> context . end_test ( self ) </s>
