blob: aca144e9dcce7efcae3b739409b6aa6e501289e6 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002# Copyright (C) 2016 Intel Corporation
Brad Bishopc342db32019-05-15 21:57:59 -04003#
4# SPDX-License-Identifier: MIT
5#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05006
7import unittest
8
9from oeqa.core.exception import OEQAMissingVariable
10
11def _validate_td_vars(td, td_vars, type_msg):
12 if td_vars:
13 for v in td_vars:
14 if not v in td:
15 raise OEQAMissingVariable("Test %s need %s variable but"\
16 " isn't into td" % (type_msg, v))
17
18class OETestCase(unittest.TestCase):
19 # TestContext and Logger instance set by OETestLoader.
20 tc = None
21 logger = None
22
23 # td has all the variables needed by the test cases
24 # is the same across all the test cases.
25 td = None
26
27 # td_vars has the variables needed by a test class
28 # or test case instance, if some var isn't into td a
Brad Bishopd7bf8c12018-02-25 22:55:05 -050029 # OEQAMissingVariable exception is raised
Brad Bishop6e60e8b2018-02-01 10:27:11 -050030 td_vars = None
31
32 @classmethod
33 def _oeSetUpClass(clss):
34 _validate_td_vars(clss.td, clss.td_vars, "class")
Brad Bishopc8f47122019-06-24 09:36:18 -040035 if hasattr(clss, 'setUpHooker') and callable(getattr(clss, 'setUpHooker')):
36 clss.setUpHooker()
Brad Bishop6e60e8b2018-02-01 10:27:11 -050037 clss.setUpClassMethod()
38
39 @classmethod
40 def _oeTearDownClass(clss):
41 clss.tearDownClassMethod()
42
43 def _oeSetUp(self):
44 for d in self.decorators:
45 d.setUpDecorator()
46 self.setUpMethod()
47
48 def _oeTearDown(self):
49 for d in self.decorators:
50 d.tearDownDecorator()
51 self.tearDownMethod()