summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/core/decorator/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/core/decorator/__init__.py')
-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