1 # Copyright (c) 2019 ARM Limited
4 # The license below extends only to copyright in the software and shall
5 # not be construed as granting a license to any other intellectual
6 # property including but not limited to intellectual property relating
7 # to a hardware implementation of the functionality of the software
8 # licensed hereunder. You may use the software subject to the license
9 # terms below provided that you ensure that this notice is replicated
10 # unmodified and in its entirety in all distributions of the software,
11 # modified or unmodified, in source code or in binary form.
13 # Copyright (c) 2017 Mark D. Hill and David A. Wood
14 # All rights reserved.
16 # Redistribution and use in source and binary forms, with or without
17 # modification, are permitted provided that the following conditions are
18 # met: redistributions of source code must retain the above copyright
19 # notice, this list of conditions and the following disclaimer;
20 # redistributions in binary form must reproduce the above copyright
21 # notice, this list of conditions and the following disclaimer in the
22 # documentation and/or other materials provided with the distribution;
23 # neither the name of the copyright holders nor the names of its
24 # contributors may be used to endorse or promote products derived from
25 # this software without specific prior written permission.
27 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 # Authors: Sean Wilson
42 Module contains wrappers for test items that have been
43 loaded by the testlib :class:`testlib.loader.Loader`.
47 import testlib
.uid
as uid
48 from testlib
.state
import Status
, Result
50 class TestCaseMetadata():
51 def __init__(self
, name
, uid
, path
, result
, status
, suite_uid
):
57 self
.suite_uid
= suite_uid
60 class TestSuiteMetadata():
61 def __init__(self
, name
, uid
, tags
, path
, status
, result
):
70 class LibraryMetadata():
71 def __init__(self
, name
, result
, status
):
77 class LoadedTestable(object):
79 Base class for loaded test items.
81 :property:`result` and :property:`status` setters
82 notify testlib via the :func:`log_result` and :func:`log_status`
83 of the updated status.
85 def __init__(self
, obj
):
87 self
.metadata
= self
._generate
_metadata
()
91 return self
.metadata
.status
94 def status(self
, status
):
95 self
.log_status(status
)
96 self
.metadata
.status
= status
100 return self
.metadata
.result
103 def result(self
, result
):
104 self
.log_result(result
)
105 self
.metadata
.result
= result
109 return self
.metadata
.uid
113 return self
.metadata
.name
117 return self
.obj
.fixtures
120 def fixtures(self
, fixtures
):
121 self
.obj
.fixtures
= fixtures
125 return self
.obj
.runner
127 # TODO Change log to provide status_update, result_update for all types.
128 def log_status(self
, status
):
129 import testlib
.log
as log
130 log
.test_log
.status_update(self
, status
)
132 def log_result(self
, result
):
133 import testlib
.log
as log
134 log
.test_log
.result_update(self
, result
)
140 class LoadedTest(LoadedTestable
):
141 def __init__(self
, test_obj
, loaded_suite
, path
):
142 self
.parent_suite
= loaded_suite
144 LoadedTestable
.__init
__(self
, test_obj
)
146 def test(self
, *args
, **kwargs
):
147 self
.obj
.test(*args
, **kwargs
)
149 def _generate_metadata(self
):
150 return TestCaseMetadata( **{
151 'name':self
.obj
.name
,
153 'uid': uid
.TestUID(self
._path
,
155 self
.parent_suite
.name
),
156 'status': Status
.Unscheduled
,
157 'result': Result(Result
.NotRun
),
158 'suite_uid': self
.parent_suite
.metadata
.uid
162 class LoadedSuite(LoadedTestable
):
163 def __init__(self
, suite_obj
, path
):
165 LoadedTestable
.__init
__(self
, suite_obj
)
166 self
.tests
= self
._wrap
_children
(suite_obj
)
168 def _wrap_children(self
, suite_obj
):
169 return [LoadedTest(test
, self
, self
.metadata
.path
)
170 for test
in suite_obj
]
172 def _generate_metadata(self
):
173 return TestSuiteMetadata( **{
174 'name': self
.obj
.name
,
175 'tags':self
.obj
.tags
,
177 'uid': uid
.SuiteUID(self
._path
, self
.obj
.name
),
178 'status': Status
.Unscheduled
,
179 'result': Result(Result
.NotRun
)
183 return iter(self
.tests
)
187 return self
.metadata
.tags
190 class LoadedLibrary(LoadedTestable
):
192 Wraps a collection of all loaded test suites and
193 provides utility functions for accessing fixtures.
195 def __init__(self
, suites
):
196 LoadedTestable
.__init
__(self
, suites
)
198 def _generate_metadata(self
):
199 return LibraryMetadata( **{
200 'name': 'Test Library',
201 'status': Status
.Unscheduled
,
202 'result': Result(Result
.NotRun
)
207 :returns: an iterator over contained :class:`TestSuite` objects.
209 return iter(self
.obj
)
211 def all_fixtures(self
):
213 :returns: an interator overall all global, suite,
216 return itertools
.chain(itertools
.chain(
217 *(suite
.fixtures
for suite
in self
.obj
)),
218 *(self
.test_fixtures(suite
) for suite
in self
.obj
)
221 def test_fixtures(self
, suite
):
223 :returns: an interator over all fixtures of each
224 test contained in the given suite
226 return itertools
.chain(*(test
.fixtures
for test
in suite
))
231 for fixture
in self
.all_fixtures():
232 if fixture
.is_global():
233 global_fixtures
.append(fixture
)
234 return global_fixtures
245 def suites(self
, suites
):