~canonical-platform-qa/snappy-ecosystem-tests/no-ephemeral-containers

« back to all changes in this revision

Viewing changes to snappy_ecosystem_tests/utils/filters.py

  • Committer: Heber Parrucci
  • Date: 2017-02-21 21:09:28 UTC
  • mto: (23.2.2 snappy-ecosystem-tests)
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: heber.parrucci@canonical.com-20170221210928-kvhsmmce5cg8x208
Adding: unittests for filter utils and minor improvements to filters.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
"""Filter utils"""
22
22
 
23
23
 
24
 
def object_filter(predicates):
 
24
def object_filter(**predicates):
25
25
    """
26
26
    Higher-order function to build and return an object filter function
27
 
    :param predicates: a dictionary that contains
28
 
    the conditions to look for in the object instance.
 
27
     :param predicates: key/values that represent
 
28
     the conditions to look for in the object instance.
29
29
    :return: a function to be used with filter or lambda expressions.
 
30
    :raise: AttributeError if any of the attributes provided in predicates
 
31
     does not exists
30
32
    """
31
33
    def wrapped_filter(instance):
32
34
        """wrapped function to be returned when calling object_filter"""
35
37
    return wrapped_filter
36
38
 
37
39
 
38
 
def filter_list(objects_list, predicates):
 
40
def filter_list(objects_list, **predicates):
39
41
    """
40
42
    Filter a list of objects with the given predicates
41
43
    :param objects_list: the target list that contains
42
44
     the objects to be filtered
43
 
    :param predicates: a dictionary that contains
 
45
    :param predicates: key/values that represent
44
46
    the conditions to look for in the object list.
45
47
    :return: A list with the objects that match all the predicates
 
48
    :raise: AttributeError if any of the attributes provided in predicates
 
49
     does not exists
46
50
    """
47
 
    return list(filter(object_filter(predicates), objects_list))
 
51
    return list(filter(object_filter(**predicates), objects_list))