forked from robotframework/robotframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestcase.py
More file actions
88 lines (71 loc) · 2.85 KB
/
testcase.py
File metadata and controls
88 lines (71 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Copyright 2008-2015 Nokia Networks
# Copyright 2016- Robot Framework Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from robot.utils import setter
from .itemlist import ItemList
from .keyword import Keyword, Keywords
from .modelobject import ModelObject
from .tags import Tags
class TestCase(ModelObject):
"""Base model for a single test case.
Extended by :class:`robot.running.model.TestCase` and
:class:`robot.result.model.TestCase`.
"""
__slots__ = ['parent', 'name', 'doc', 'timeout']
keyword_class = Keyword #: Internal usage only
def __init__(self, name='', doc='', tags=None, timeout=None):
self.parent = None #: Parent suite.
self.name = name #: Test case name.
self.doc = doc #: Test case documentation.
self.timeout = timeout #: Test case timeout.
self.tags = tags
self.keywords = None
@setter
def tags(self, tags):
"""Test tags as a :class:`~.model.tags.Tags` object."""
return Tags(tags)
@setter
def keywords(self, keywords):
"""Keywords as a :class:`~.Keywords` object.
Contains also possible setup and teardown keywords.
"""
return Keywords(self.keyword_class, self, keywords)
@property
def id(self):
"""Test case id in format like ``s1-t3``.
See :attr:`TestSuite.id <robot.model.testsuite.TestSuite.id>` for
more information.
"""
if not self.parent:
return 't1'
return '%s-t%d' % (self.parent.id, self.parent.tests.index(self)+1)
@property
def longname(self):
"""Test name prefixed with the long name of the parent suite."""
if not self.parent:
return self.name
return '%s.%s' % (self.parent.longname, self.name)
def visit(self, visitor):
""":mod:`Visitor interface <robot.model.visitor>` entry-point."""
visitor.visit_test(self)
class TestCases(ItemList):
__slots__ = []
def __init__(self, test_class=TestCase, parent=None, tests=None):
ItemList.__init__(self, test_class, {'parent': parent}, tests)
def _check_type_and_set_attrs(self, *tests):
tests = ItemList._check_type_and_set_attrs(self, *tests)
for test in tests:
for visitor in test.parent._visitors:
test.visit(visitor)
return tests