<s> from robot . utils import setter <EOL> from . tags import TagPatterns <EOL> from . namepatterns import SuiteNamePatterns , TestNamePatterns <EOL> from . visitor import SuiteVisitor <EOL> class Filter ( SuiteVisitor ) : <EOL> def __init__ ( self , include_suites = None , include_tests = None , <EOL> include_tags = None , exclude_tags = None ) : <EOL> self . include_suites = include_suites <EOL> self . include_tests = include_tests <EOL> self . include_tags = include_tags <EOL> self . exclude_tags = exclude_tags <EOL> @ setter <EOL> def include_suites ( self , suites ) : <EOL> return SuiteNamePatterns ( suites ) if not isinstance ( suites , SuiteNamePatterns ) else suites <EOL> @ setter <EOL> def include_tests ( self , tests ) : <EOL> return TestNamePatterns ( tests ) if not isinstance ( tests , TestNamePatterns ) else tests <EOL> @ setter <EOL> def include_tags ( self , tags ) : <EOL> return TagPatterns ( tags ) if not isinstance ( tags , TagPatterns ) else tags <EOL> @ setter <EOL> def exclude_tags ( self , tags ) : <EOL> return TagPatterns ( tags ) if not isinstance ( tags , TagPatterns ) else tags <EOL> def start_suite ( self , suite ) : <EOL> if not self : <EOL> return False <EOL> if hasattr ( suite , '<STR_LIT>' ) : <EOL> suite . starttime = suite . endtime = None <EOL> if self . include_suites : <EOL> return self . _filter_by_suite_name ( suite ) <EOL> if self . include_tests : <EOL> suite . tests = self . _filter ( suite , self . _included_by_test_name ) <EOL> if self . include_tags : <EOL> suite . tests = self . _filter ( suite , self . _included_by_tags ) <EOL> if self . exclude_tags : <EOL> suite . tests = self . _filter ( suite , self . _not_excluded_by_tags ) <EOL> return bool ( suite . suites ) <EOL> def _filter_by_suite_name ( self , suite ) : <EOL> if self . include_suites . match ( suite . name , suite . longname ) : <EOL> suite . visit ( Filter ( include_suites = [ ] , <EOL> include_tests = self . include_tests , <EOL> include_tags = self . include_tags , <EOL> exclude_tags = self . exclude_tags ) ) <EOL> return False <EOL> suite . tests = [ ] <EOL> return True <EOL> def _filter ( self , suite , filter ) : <EOL> return [ t for t in suite . tests if filter ( t ) ] <EOL> def _included_by_test_name ( self , test ) : <EOL> return self . include_tests . match ( test . name , test . longname ) <EOL> def _included_by_tags ( self , test ) : <EOL> return self . include_tags . match ( test . tags ) <EOL> def _not_excluded_by_tags ( self , test ) : <EOL> return not self . exclude_tags . match ( test . tags ) <EOL> def end_suite ( self , suite ) : <EOL> suite . suites = [ s for s in suite . suites if s . test_count ] <EOL> def visit_test ( self , test ) : <EOL> pass <EOL> def visit_keyword ( self , keyword ) : <EOL> pass <EOL> def __nonzero__ ( self ) : <EOL> return bool ( self . include_suites or self . include_tests or <EOL> self . include_tags or self . exclude_tags ) </s>
