Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | # Copyright (C) 2016 Intel Corporation |
| 2 | # Released under the MIT license (see COPYING.MIT) |
| 3 | |
| 4 | import unittest |
| 5 | |
| 6 | from oeqa.core.exception import OEQAMissingVariable |
| 7 | |
| 8 | def _validate_td_vars(td, td_vars, type_msg): |
| 9 | if td_vars: |
| 10 | for v in td_vars: |
| 11 | if not v in td: |
| 12 | raise OEQAMissingVariable("Test %s need %s variable but"\ |
| 13 | " isn't into td" % (type_msg, v)) |
| 14 | |
| 15 | class OETestCase(unittest.TestCase): |
| 16 | # TestContext and Logger instance set by OETestLoader. |
| 17 | tc = None |
| 18 | logger = None |
| 19 | |
| 20 | # td has all the variables needed by the test cases |
| 21 | # is the same across all the test cases. |
| 22 | td = None |
| 23 | |
| 24 | # td_vars has the variables needed by a test class |
| 25 | # or test case instance, if some var isn't into td a |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame^] | 26 | # OEQAMissingVariable exception is raised |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 27 | td_vars = None |
| 28 | |
| 29 | @classmethod |
| 30 | def _oeSetUpClass(clss): |
| 31 | _validate_td_vars(clss.td, clss.td_vars, "class") |
| 32 | clss.setUpClassMethod() |
| 33 | |
| 34 | @classmethod |
| 35 | def _oeTearDownClass(clss): |
| 36 | clss.tearDownClassMethod() |
| 37 | |
| 38 | def _oeSetUp(self): |
| 39 | for d in self.decorators: |
| 40 | d.setUpDecorator() |
| 41 | self.setUpMethod() |
| 42 | |
| 43 | def _oeTearDown(self): |
| 44 | for d in self.decorators: |
| 45 | d.tearDownDecorator() |
| 46 | self.tearDownMethod() |