diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2018-05-08 13:50:37 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2018-05-09 11:10:32 -0700 |
commit | 1f0f2ad25ecbfdcb09ec764404ec365c6b6946c1 (patch) | |
tree | d6335864e2bfbe138b7472dce97bedb11cbd2350 /framework | |
parent | bde5cb4376df9ad59db26e7083d91ed12e107970 (diff) |
framework: Add filters class
This class works like a list, but with an extra method that allows it to
"reset" a filter. This will allow class based filters that need to be
reset to have deterministic behavior to do so.
Tested-by: Michel Dänzer <michel.daenzer@amd.com>
Diffstat (limited to 'framework')
-rw-r--r-- | framework/profile.py | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/framework/profile.py b/framework/profile.py index 44681592a..b0233866b 100644 --- a/framework/profile.py +++ b/framework/profile.py @@ -265,6 +265,42 @@ class TestDict(collections.MutableMapping): self.__allow_reassignment -= 1 +class Filters(collections.MutableSequence): + + def __init__(self, iterable=None): + if iterable: + self.__container = list(iterable) + else: + self.__container = [] + + def __getitem__(self, index): + return self.__container[index] + + def __setitem__(self, index, value): + self.__container[index] = value + + def __delitem__(self, index): + del self.__container[index] + + def __len__(self): + return len(self.__container) + + def __add__(self, other): + return type(self)(itertools.chain(iter(self), iter(other))) + + def insert(self, index, value): + self.__container.insert(index, value) + + def run(self, iterable): + for f in self.__container: + if hasattr(f, 'reset'): + f.reset() + + for k, v in iterable: + if all(f(k, v) for f in self.__container): + yield k, v + + def make_test(element): """Rebuild a test instance from xml.""" def process(elem, opt): @@ -309,7 +345,7 @@ class XMLProfile(object): def __init__(self, filename): self.filename = filename self.forced_test_list = [] - self.filters = [] + self.filters = Filters() self.options = { 'dmesg': get_dmesg(False), 'monitor': Monitoring(False), @@ -369,7 +405,7 @@ class MetaProfile(object): def __init__(self, filename): self.forced_test_list = [] - self.filters = [] + self.filters = Filters() self.options = { 'dmesg': get_dmesg(False), 'monitor': Monitoring(False), @@ -436,7 +472,7 @@ class TestProfile(object): def __init__(self): self.test_list = TestDict() self.forced_test_list = [] - self.filters = [] + self.filters = Filters() self.options = { 'dmesg': get_dmesg(False), 'monitor': Monitoring(False), |