summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorAníbal Limón <anibal.limon@linux.intel.com>2016-11-08 17:57:43 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-01-23 12:05:18 +0000
commit08714d3b7e744b19dde2b102ed4d80fc171f07a1 (patch)
treeafd3d6cff0b4cef3f2ddcc298fccf46ac7b060ed /meta
parent7998501f472278b4ed93dd7b95b1776efde5cb6c (diff)
downloadpoky-08714d3b7e744b19dde2b102ed4d80fc171f07a1.tar.gz
oeqa/core: Add base OEQA framework
case: Defines OETestCase base class that provides custom methods/attrs defined by the framework. Every OETestCase instance contains a reference to the test data (d), the test context (tc) and the logger. Also implements _oe{SetUp,TearDown}Class for make special handling of OEQA decorators and validations. runner: Defines OETestRunner/OETestResult with support for RAW and XML result logs. exception: Custom exceptions related to the OEQA framework based on class OEQAException. [YOCTO #10230] [YOCTO #10233] (From OE-Core rev: c466086ccc4d4bb02d578a821cfb945945bfd529) Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com> Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/lib/oeqa/core/__init__.py0
-rw-r--r--meta/lib/oeqa/core/case.py46
-rw-r--r--meta/lib/oeqa/core/exception.py14
-rw-r--r--meta/lib/oeqa/core/runner.py76
4 files changed, 136 insertions, 0 deletions
diff --git a/meta/lib/oeqa/core/__init__.py b/meta/lib/oeqa/core/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/meta/lib/oeqa/core/__init__.py
diff --git a/meta/lib/oeqa/core/case.py b/meta/lib/oeqa/core/case.py
new file mode 100644
index 0000000000..d2dbf20f9e
--- /dev/null
+++ b/meta/lib/oeqa/core/case.py
@@ -0,0 +1,46 @@
1# Copyright (C) 2016 Intel Corporation
2# Released under the MIT license (see COPYING.MIT)
3
4import unittest
5
6from oeqa.core.exception import OEQAMissingVariable
7
8def _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
15class 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
26 # OEMissingVariable exception is raised
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()
diff --git a/meta/lib/oeqa/core/exception.py b/meta/lib/oeqa/core/exception.py
new file mode 100644
index 0000000000..2dfd8402cf
--- /dev/null
+++ b/meta/lib/oeqa/core/exception.py
@@ -0,0 +1,14 @@
1# Copyright (C) 2016 Intel Corporation
2# Released under the MIT license (see COPYING.MIT)
3
4class OEQAException(Exception):
5 pass
6
7class OEQATimeoutError(OEQAException):
8 pass
9
10class OEQAMissingVariable(OEQAException):
11 pass
12
13class OEQADependency(OEQAException):
14 pass
diff --git a/meta/lib/oeqa/core/runner.py b/meta/lib/oeqa/core/runner.py
new file mode 100644
index 0000000000..8f5af579f3
--- /dev/null
+++ b/meta/lib/oeqa/core/runner.py
@@ -0,0 +1,76 @@
1# Copyright (C) 2016 Intel Corporation
2# Released under the MIT license (see COPYING.MIT)
3
4import os
5import time
6import unittest
7import logging
8
9xmlEnabled = False
10try:
11 import xmlrunner
12 from xmlrunner.result import _XMLTestResult as _TestResult
13 from xmlrunner.runner import XMLTestRunner as _TestRunner
14 xmlEnabled = True
15except ImportError:
16 # use the base runner instead
17 from unittest import TextTestResult as _TestResult
18 from unittest import TextTestRunner as _TestRunner
19
20class OEStreamLogger(object):
21 def __init__(self, logger):
22 self.logger = logger
23 self.buffer = ""
24
25 def write(self, msg):
26 if msg[-1] != '\n':
27 self.buffer += msg
28 else:
29 self.logger.log(logging.INFO, self.buffer.rstrip("\n"))
30 self.buffer = ""
31
32 def flush(self):
33 for handler in self.logger.handlers:
34 handler.flush()
35
36class OETestResult(_TestResult):
37 def __init__(self, tc, *args, **kwargs):
38 super(OETestResult, self).__init__(*args, **kwargs)
39
40 self.tc = tc
41
42 self.tc._results['failures'] = self.failures
43 self.tc._results['errors'] = self.errors
44 self.tc._results['skipped'] = self.skipped
45 self.tc._results['expectedFailures'] = self.expectedFailures
46
47 def startTest(self, test):
48 super(OETestResult, self).startTest(test)
49
50class OETestRunner(_TestRunner):
51 def __init__(self, tc, *args, **kwargs):
52 if xmlEnabled:
53 if not kwargs.get('output'):
54 kwargs['output'] = os.path.join(os.getcwd(),
55 'TestResults_%s' % time.strftime("%Y%m%d%H%M%S"))
56
57 super(OETestRunner, self).__init__(*args, **kwargs)
58 self.tc = tc
59 self.resultclass = OETestResult
60
61 # XXX: The unittest-xml-reporting package defines _make_result method instead
62 # of _makeResult standard on unittest.
63 if xmlEnabled:
64 def _make_result(self):
65 """
66 Creates a TestResult object which will be used to store
67 information about the executed tests.
68 """
69 # override in subclasses if necessary.
70 return self.resultclass(self.tc,
71 self.stream, self.descriptions, self.verbosity, self.elapsed_times
72 )
73 else:
74 def _makeResult(self):
75 return self.resultclass(self.tc, self.stream, self.descriptions,
76 self.verbosity)