Robot Framework Integrated Development Environment (RIDE)
filter.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 from robotide.lib.robot.utils import py2to3, setter
17 
18 from .tags import TagPatterns
19 from .namepatterns import SuiteNamePatterns, TestNamePatterns
20 from .visitor import SuiteVisitor
21 
22 
24 
25  def end_suite(self, suite):
26  suite.suites = [s for s in suite.suites if s.test_count]
27 
28  def visit_test(self, test):
29  pass
30 
31  def visit_keyword(self, kw):
32  pass
33 
34 
35 @py2to3
37 
38  def __init__(self, include_suites=None, include_tests=None,
39  include_tags=None, exclude_tags=None):
40  self.include_suitesinclude_suitesinclude_suites = include_suites
41  self.include_testsinclude_testsinclude_tests = include_tests
42  self.include_tagsinclude_tagsinclude_tags = include_tags
43  self.exclude_tagsexclude_tagsexclude_tags = exclude_tags
44 
45  @setter
46  def include_suites(self, suites):
47  return SuiteNamePatterns(suites) \
48  if not isinstance(suites, SuiteNamePatterns) else suites
49 
50  @setter
51  def include_tests(self, tests):
52  return TestNamePatterns(tests) \
53  if not isinstance(tests, TestNamePatterns) else tests
54 
55  @setter
56  def include_tags(self, tags):
57  return TagPatterns(tags) if not isinstance(tags, TagPatterns) else tags
58 
59  @setter
60  def exclude_tags(self, tags):
61  return TagPatterns(tags) if not isinstance(tags, TagPatterns) else tags
62 
63  def start_suite(self, suite):
64  if not self:
65  return False
66  if hasattr(suite, 'starttime'):
67  suite.starttime = suite.endtime = None
68  if self.include_suitesinclude_suitesinclude_suites:
69  return self._filter_by_suite_name_filter_by_suite_name(suite)
70  if self.include_testsinclude_testsinclude_tests:
71  suite.tests = self._filter_filter(suite, self._included_by_test_name_included_by_test_name)
72  if self.include_tagsinclude_tagsinclude_tags:
73  suite.tests = self._filter_filter(suite, self._included_by_tags_included_by_tags)
74  if self.exclude_tagsexclude_tagsexclude_tags:
75  suite.tests = self._filter_filter(suite, self._not_excluded_by_tags_not_excluded_by_tags)
76  return bool(suite.suites)
77 
78  def _filter_by_suite_name(self, suite):
79  if self.include_suitesinclude_suitesinclude_suites.match(suite.name, suite.longname):
80  suite.visit(Filter(include_suites=[],
81  include_tests=self.include_testsinclude_testsinclude_tests,
82  include_tags=self.include_tagsinclude_tagsinclude_tags,
83  exclude_tags=self.exclude_tagsexclude_tagsexclude_tags))
84  return False
85  suite.tests = []
86  return True
87 
88  def _filter(self, suite, filter):
89  return [t for t in suite.tests if filter(t)]
90 
91  def _included_by_test_name(self, test):
92  return self.include_testsinclude_testsinclude_tests.match(test.name, test.longname)
93 
94  def _included_by_tags(self, test):
95  return self.include_tagsinclude_tagsinclude_tags.match(test.tags)
96 
97  def _not_excluded_by_tags(self, test):
98  return not self.exclude_tagsexclude_tagsexclude_tags.match(test.tags)
99 
100  def __nonzero__(self):
101  return bool(self.include_suitesinclude_suitesinclude_suites or self.include_testsinclude_testsinclude_tests or
102  self.include_tagsinclude_tagsinclude_tags or self.exclude_tagsexclude_tagsexclude_tags)
def visit_test(self, test)
Implements traversing through the test and its keywords.
Definition: filter.py:28
def end_suite(self, suite)
Called when suite ends.
Definition: filter.py:25
def visit_keyword(self, kw)
Implements traversing through the keyword and its child keywords.
Definition: filter.py:31
def _filter(self, suite, filter)
Definition: filter.py:88
def _filter_by_suite_name(self, suite)
Definition: filter.py:78
def start_suite(self, suite)
Called when suite starts.
Definition: filter.py:63
def include_suites(self, suites)
Definition: filter.py:46
def _not_excluded_by_tags(self, test)
Definition: filter.py:97
def __init__(self, include_suites=None, include_tests=None, include_tags=None, exclude_tags=None)
Definition: filter.py:39
def _included_by_test_name(self, test)
Definition: filter.py:91
Interface to ease traversing through a test suite structure.
Definition: visitor.py:75