Robot Framework Integrated Development Environment (RIDE)
testsuite.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 setter
17 
18 from .configurer import SuiteConfigurer
19 from .filter import Filter, EmptySuiteRemover
20 from .itemlist import ItemList
21 from .keyword import Keyword, Keywords
22 from .metadata import Metadata
23 from .modelobject import ModelObject
24 from .tagsetter import TagSetter
25 from .testcase import TestCase, TestCases
26 
27 
28 
34  __slots__ = ['parent', 'source', '_name', 'doc', '_my_visitors', 'rpa']
35  test_class = TestCase #: Internal usage only.
36  keyword_class = Keyword #: Internal usage only.
37 
38  def __init__(self, name='', doc='', metadata=None, source=None, rpa=False):
39  self.parentparent = None #: Parent suite. ``None`` with the root suite.
40  self._name_name = name
41  self.docdoc = doc #: Test suite documentation.
42  self.metadatametadatametadata = metadata
43  self.sourcesource = source #: Path to the source file or directory.
44  self.rparpa = rpa
45  self.suitessuitessuites = None
46  self.teststeststests = None
47  self.keywordskeywordskeywords = None
48  self._my_visitors_my_visitors = []
49 
50  @property
51  _visitors = property
52 
53  def _visitors(self):
54  parent_visitors = self.parentparent._visitors if self.parentparent else []
55  return self._my_visitors_my_visitors + parent_visitors
56 
57  @property
58 
59  name = property
60 
61  def name(self):
62  return self._name_name or ' & '.join(s.name for s in self.suitessuitessuites)
63 
64  @name.setter
65 
66  def name(self, name):
67  self._name_name = name
68 
69  @property
70 
71  longname = property
72 
73  def longname(self):
74  if not self.parentparent:
75  return self.namenamenamename
76  return '%s.%s' % (self.parentparent.longname, self.namenamenamename)
77 
78  @setter
79 
80  def metadata(self, metadata):
81  return Metadata(metadata)
82 
83  @setter
84 
85  def suites(self, suites):
86  return TestSuites(self.__class__, self, suites)
87 
88  @setter
89 
90  def tests(self, tests):
91  return TestCases(self.test_classtest_class, self, tests)
92 
93  @setter
94 
95  def keywords(self, keywords):
96  return Keywords(self.keyword_classkeyword_class, self, keywords)
97 
98  @property
99 
109  id = property
110 
111  def id(self):
112  if not self.parentparent:
113  return 's1'
114  return '%s-s%d' % (self.parentparent.id, self.parentparent.suites.index(self)+1)
115 
116  @property
117 
118  test_count = property
119 
120  def test_count(self):
121  return len(self.teststeststests) + sum(suite.test_count for suite in self.suitessuitessuites)
122 
123 
132  def set_tags(self, add=None, remove=None, persist=False):
133  setter = TagSetter(add, remove)
134  self.visitvisit(setter)
135  if persist:
136  self._my_visitors_my_visitors.append(setter)
137 
138 
153  def filter(self, included_suites=None, included_tests=None,
154  included_tags=None, excluded_tags=None):
155  self.visitvisit(Filter(included_suites, included_tests,
156  included_tags, excluded_tags))
157 
158 
166  def configure(self, **options):
167  if self.parentparent is not None:
168  raise ValueError("'TestSuite.configure()' can only be used with "
169  "the root test suite.")
170  if options:
171  self.visitvisit(SuiteConfigurer(**options))
172 
173 
175  self.visitvisit(EmptySuiteRemover())
176 
177 
178  def visit(self, visitor):
179  visitor.visit_suite(self)
180 
181 
183  __slots__ = []
184 
185  def __init__(self, suite_class=TestSuite, parent=None, suites=None):
186  ItemList.__init__(self, suite_class, {'parent': parent}, suites)
A list-like object representing keywords in a suite, a test or a keyword.
Definition: keyword.py:135
Base model for single suite.
Definition: testsuite.py:33
test_count
Number of the tests in this suite, recursively.
Definition: testsuite.py:118
def configure(self, **options)
A shortcut to configure a suite using one method call.
Definition: testsuite.py:166
def metadata(self, metadata)
Free test suite metadata as a dictionary.
Definition: testsuite.py:80
def remove_empty_suites(self)
Removes all child suites not containing any tests, recursively.
Definition: testsuite.py:174
def visit(self, visitor)
:mod:Visitor interface <robot.model.visitor> entry-point.
Definition: testsuite.py:178
def suites(self, suites)
Child suites as a :class:~.TestSuites object.
Definition: testsuite.py:85
def filter(self, included_suites=None, included_tests=None, included_tags=None, excluded_tags=None)
Select test cases and remove others from this suite.
Definition: testsuite.py:154
longname
Suite name prefixed with the long name of the parent suite.
Definition: testsuite.py:71
def keywords(self, keywords)
Suite setup and teardown as a :class:~.Keywords object.
Definition: testsuite.py:95
id
An automatically generated unique id.
Definition: testsuite.py:109
def __init__(self, name='', doc='', metadata=None, source=None, rpa=False)
Definition: testsuite.py:38
def set_tags(self, add=None, remove=None, persist=False)
Add and/or remove specified tags to the tests in this suite.
Definition: testsuite.py:132
def tests(self, tests)
Tests as a :class:~.TestCases object.
Definition: testsuite.py:90
def __init__(self, suite_class=TestSuite, parent=None, suites=None)
Definition: testsuite.py:185