summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/core/decorator
diff options
context:
space:
mode:
authorAníbal Limón <anibal.limon@linux.intel.com>2016-11-09 10:38:37 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-01-23 12:05:18 +0000
commit13c8c08b95191829705b5a4c8f0d368c251f0174 (patch)
tree737412ed0d676dcf1982fc6b2cd0046bca760281 /meta/lib/oeqa/core/decorator
parentabb55ab304af91f68a4e09176ce9c6b995d903e0 (diff)
downloadpoky-13c8c08b95191829705b5a4c8f0d368c251f0174.tar.gz
oeqa/core: Add loader, context and decorator modules
loader: Implements OETestLoader handling OETestDecorator and filtering support when load tests. The OETestLoader is responsible to set custom methods, attrs of the OEQA frameowork. [YOCTO #10231] [YOCTO #10317] [YOCTO #10353] decorator: Add base class OETestDecorator to provide a common way to define decorators to be used over OETestCase's, every decorator has a method to be called when loading tests and before test execution starts. Special decorators could be implemented for filter tests on loading phase. context: Provides HIGH level API for loadTests and runTests of certain test component (i.e. runtime, sdk, selftest). [YOCTO #10230] (From OE-Core rev: 275ef03b77ef5f23b75cb01c55206d1ab0261342) 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/lib/oeqa/core/decorator')
-rw-r--r--meta/lib/oeqa/core/decorator/__init__.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/meta/lib/oeqa/core/decorator/__init__.py b/meta/lib/oeqa/core/decorator/__init__.py
new file mode 100644
index 0000000000..855b6b9d28
--- /dev/null
+++ b/meta/lib/oeqa/core/decorator/__init__.py
@@ -0,0 +1,71 @@
1# Copyright (C) 2016 Intel Corporation
2# Released under the MIT license (see COPYING.MIT)
3
4from functools import wraps
5from abc import abstractmethod
6
7decoratorClasses = set()
8
9def registerDecorator(obj):
10 decoratorClasses.add(obj)
11 return obj
12
13class OETestDecorator(object):
14 case = None # Reference of OETestCase decorated
15 attrs = None # Attributes to be loaded by decorator implementation
16
17 def __init__(self, *args, **kwargs):
18 if not self.attrs:
19 return
20
21 for idx, attr in enumerate(self.attrs):
22 if attr in kwargs:
23 value = kwargs[attr]
24 else:
25 value = args[idx]
26 setattr(self, attr, value)
27
28 def __call__(self, func):
29 @wraps(func)
30 def wrapped_f(*args, **kwargs):
31 self.attrs = self.attrs # XXX: Enables OETestLoader discover
32 return func(*args, **kwargs)
33 return wrapped_f
34
35 # OETestLoader call it when is loading test cases.
36 # XXX: Most methods would change the registry for later
37 # processing; be aware that filtrate method needs to
38 # run later than bind, so there could be data (in the
39 # registry) of a cases that were filtered.
40 def bind(self, registry, case):
41 self.case = case
42 self.logger = case.tc.logger
43 self.case.decorators.append(self)
44
45 # OETestRunner call this method when tries to run
46 # the test case.
47 def setUpDecorator(self):
48 pass
49
50 # OETestRunner call it after a test method has been
51 # called even if the method raised an exception.
52 def tearDownDecorator(self):
53 pass
54
55class OETestDiscover(OETestDecorator):
56
57 # OETestLoader call it after discover test cases
58 # needs to return the cases to be run.
59 @staticmethod
60 def discover(registry):
61 return registry['cases']
62
63class OETestFilter(OETestDecorator):
64
65 # OETestLoader call it while loading the tests
66 # in loadTestsFromTestCase method, it needs to
67 # return a bool, True if needs to be filtered.
68 # This method must consume the filter used.
69 @abstractmethod
70 def filtrate(self, filters):
71 return False