<s> import abc <EOL> import re <EOL> import os <EOL> import json <EOL> from qisys import ui <EOL> import qisys . error <EOL> import qitest . test_queue <EOL> class TestSuiteRunner ( object ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = abc . ABCMeta <EOL> def __init__ ( self , project ) : <EOL> self . project = project <EOL> self . _patterns = list ( ) <EOL> self . _excludes = list ( ) <EOL> self . num_jobs = <NUM_LIT:1> <EOL> self . repeat_until_fail = <NUM_LIT:0> <EOL> self . cwd = os . getcwd ( ) <EOL> self . env = None <EOL> self . verbose = False <EOL> self . perf = False <EOL> self . nightly = False <EOL> self . coverage = False <EOL> self . nightmare = False <EOL> self . test_output_dir = None <EOL> self . capture = True <EOL> self . last_failed = False <EOL> self . _tests = project . tests <EOL> @ abc . abstractproperty <EOL> def launcher ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> test_queue = qitest . test_queue . TestQueue ( self . tests ) <EOL> test_queue . launcher = self . launcher <EOL> test_queue . launcher . capture = self . capture <EOL> ok = test_queue . run ( num_jobs = self . num_jobs , <EOL> repeat_until_fail = self . repeat_until_fail ) <EOL> return ok <EOL> @ property <EOL> def patterns ( self ) : <EOL> return self . _patterns <EOL> @ patterns . setter <EOL> def patterns ( self , value ) : <EOL> if value : <EOL> try : <EOL> [ re . compile ( x ) for x in value ] <EOL> except Exception as e : <EOL> raise qisys . error . Error ( str ( e ) ) <EOL> self . _patterns = value <EOL> @ property <EOL> def excludes ( self ) : <EOL> return self . _excludes <EOL> @ excludes . setter <EOL> def excludes ( self , value ) : <EOL> if value : <EOL> [ re . compile ( x ) for x in value ] <EOL> self . _excludes = value <EOL> @ property <EOL> def tests ( self ) : <EOL> res = [ x for x in self . _tests if <EOL> match_patterns ( self . patterns , x [ "<STR_LIT:name>" ] , default = True ) ] <EOL> res = [ x for x in res if not <EOL> match_patterns ( self . excludes , x [ "<STR_LIT:name>" ] , default = False ) ] <EOL> res = [ x for x in res if x . get ( "<STR_LIT>" , False ) == self . perf ] <EOL> if not self . nightly : <EOL> res = [ x for x in res if x . get ( "<STR_LIT>" , False ) is False ] <EOL> if self . last_failed : <EOL> failed_names = self . get_last_failed_names ( ) <EOL> res = [ x for x in res if x [ "<STR_LIT:name>" ] in failed_names ] <EOL> if not res : <EOL> ui . warning ( "<STR_LIT>" ) <EOL> return res <EOL> def get_last_failed_names ( self ) : <EOL> """<STR_LIT>""" <EOL> path = self . launcher . project . sdk_directory <EOL> fail_json = os . path . join ( path , "<STR_LIT>" ) <EOL> names = list ( ) <EOL> if not os . path . exists ( fail_json ) : <EOL> return names <EOL> with open ( fail_json , "<STR_LIT:r>" ) as fp : <EOL> names = json . load ( fp ) <EOL> return names <EOL> class TestLauncher ( object ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = abc . ABCMeta <EOL> def __init__ ( self ) : <EOL> self . worker_index = None <EOL> self . capture = True <EOL> @ abc . abstractmethod <EOL> def launch ( self , test ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def match_patterns ( patterns , name , default = True ) : <EOL> if not patterns : <EOL> return default <EOL> for pattern in patterns : <EOL> res = re . search ( pattern , name ) <EOL> if res : <EOL> return True <EOL> return False </s>
