Robot Framework Integrated Development Environment (RIDE)
configurer.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 seq2str
17 from robotide.lib.robot.errors import DataError
18 
19 from .visitor import SuiteVisitor
20 
21 
23 
24  def __init__(self, name=None, doc=None, metadata=None, set_tags=None,
25  include_tags=None, exclude_tags=None, include_suites=None,
26  include_tests=None, empty_suite_ok=False):
27  self.namename = name
28  self.docdoc = doc
29  self.metadatametadata = metadata
30  self.set_tagsset_tags = set_tags or []
31  self.include_tagsinclude_tags = include_tags
32  self.exclude_tagsexclude_tags = exclude_tags
33  self.include_suitesinclude_suites = include_suites
34  self.include_testsinclude_tests = include_tests
35  self.empty_suite_okempty_suite_ok = empty_suite_ok
36 
37  @property
38  add_tags = property
39 
40  def add_tags(self):
41  return [t for t in self.set_tagsset_tags if not t.startswith('-')]
42 
43  @property
44  remove_tags = property
45 
46  def remove_tags(self):
47  return [t[1:] for t in self.set_tagsset_tags if t.startswith('-')]
48 
49  def visit_suite(self, suite):
50  self._set_suite_attributes_set_suite_attributes(suite)
51  self._filter_filter(suite)
52  suite.set_tags(self.add_tagsadd_tagsadd_tags, self.remove_tagsremove_tagsremove_tags)
53 
54  def _set_suite_attributes(self, suite):
55  if self.namename:
56  suite.name = self.namename
57  if self.docdoc:
58  suite.doc = self.docdoc
59  if self.metadatametadata:
60  suite.metadata.update(self.metadatametadata)
61 
62  def _filter(self, suite):
63  name = suite.name
64  suite.filter(self.include_suitesinclude_suites, self.include_testsinclude_tests,
65  self.include_tagsinclude_tags, self.exclude_tagsexclude_tags)
66  if not (suite.test_count or self.empty_suite_okempty_suite_ok):
67  self._raise_no_tests_error_raise_no_tests_error(name, suite.rpa)
68 
69  def _raise_no_tests_error(self, suite, rpa=False):
70  parts = ['tests' if not rpa else 'tasks',
71  self._get_test_selector_msgs_get_test_selector_msgs(),
72  self._get_suite_selector_msg_get_suite_selector_msg()]
73  raise DataError("Suite '%s' contains no %s."
74  % (suite, ' '.join(p for p in parts if p)))
75 
77  parts = []
78  for explanation, selector in [('matching tags', self.include_tagsinclude_tags),
79  ('not matching tags', self.exclude_tagsexclude_tags),
80  ('matching name', self.include_testsinclude_tests)]:
81  if selector:
82  parts.append(self._format_selector_msg_format_selector_msg(explanation, selector))
83  return seq2str(parts, quote='')
84 
85  def _format_selector_msg(self, explanation, selector):
86  if len(selector) == 1 and explanation[-1] == 's':
87  explanation = explanation[:-1]
88  return '%s %s' % (explanation, seq2str(selector, lastsep=' or '))
89 
91  if not self.include_suitesinclude_suites:
92  return ''
93  return self._format_selector_msg_format_selector_msg('in suites', self.include_suitesinclude_suites)
Used when variable does not exist.
Definition: errors.py:67
def _raise_no_tests_error(self, suite, rpa=False)
Definition: configurer.py:69
def _format_selector_msg(self, explanation, selector)
Definition: configurer.py:85
def visit_suite(self, suite)
Implements traversing through the suite and its direct children.
Definition: configurer.py:49
def __init__(self, name=None, doc=None, metadata=None, set_tags=None, include_tags=None, exclude_tags=None, include_suites=None, include_tests=None, empty_suite_ok=False)
Definition: configurer.py:26
Interface to ease traversing through a test suite structure.
Definition: visitor.py:75
def seq2str(sequence, quote="'", sep=', ', lastsep=' and ')
Returns sequence in format ‘'item 1’, 'item 2' and 'item 3'`.
Definition: misc.py:115