ext: Remove dead code from fixture.py
[gem5.git] / ext / testlib / fixture.py
1 # Copyright (c) 2017 Mark D. Hill and David A. Wood
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met: redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer;
8 # redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution;
11 # neither the name of the copyright holders nor the names of its
12 # contributors may be used to endorse or promote products derived from
13 # this software without specific prior written permission.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #
27 # Authors: Sean Wilson
28
29 import testlib.helper as helper
30
31 class SkipException(Exception):
32 def __init__(self, fixture, testitem):
33 self.msg = 'Fixture "%s" raised SkipException for "%s".' % (
34 fixture.name, testitem.name
35 )
36 super(SkipException, self).__init__(self.msg)
37
38
39 class Fixture(object):
40 '''
41 Base Class for a test Fixture.
42
43 Fixtures are items which possibly require setup and/or tearing down after
44 a TestCase, TestSuite, or the Library has completed.
45
46 Fixtures are the prefered method of carrying incremental results or
47 variables between TestCases in TestSuites. (Rather than using globals.)
48 Using fixtures rather than globals ensures that state will be maintained
49 when executing tests in parallel.
50
51 .. note:: In order for Fixtures to be enumerated by the test system this
52 class' :code:`__new__` method must be called.
53 '''
54 collector = helper.InstanceCollector()
55
56 def __new__(klass, *args, **kwargs):
57 obj = super(Fixture, klass).__new__(klass)
58 Fixture.collector.collect(obj)
59 return obj
60
61 def __init__(self, name=None, **kwargs):
62 if name is None:
63 name = self.__class__.__name__
64 self.name = name
65 self._is_global = False
66
67 def skip(self, testitem):
68 raise SkipException(self.name, testitem.metadata)
69
70 def setup(self, testitem):
71 pass
72
73 def teardown(self, testitem):
74 pass
75
76 def set_global(self):
77 self._is_global = True
78
79 def is_global(self):
80 return self._is_global