[Piglit] [PATCH 1/3] framework: Add filters class

Dylan Baker dylan at pnwbakers.com
Tue May 8 21:26:30 UTC 2018


Please ignore this series and see the next one I sent, the [N/4] one

Quoting Dylan Baker (2018-05-08 14:21:49)
> 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.
> ---
>  framework/profile.py | 42 +++++++++++++++++++++++++++++++++++++++---
>  1 file 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),
> -- 
> 2.17.0
> 
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/piglit
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/piglit/attachments/20180508/824dd425/attachment-0001.sig>


More information about the Piglit mailing list