def tests_filter_combinations(tests):
    """ Return a complete list of filter combinations for given list of tests
    """
    if len(tests) == 0:
        return [Filter()]
    
    # unique properties
    properties = sorted(list(set([test.property for test in tests])))

    property_tests = {}
    
    # divide up the tests by their first argument, e.g. "landuse" vs. "tourism",
    # into lists of all possible legal combinations of those tests.
    for property in properties:
        
        # limit tests to those with the current property
        current_tests = [test for test in tests if test.property == property]
        
        has_ranged_tests = True in [test.isRanged() for test in current_tests]
        has_nonnumeric_tests = False in [test.isNumeric() for test in current_tests]
        
        if has_ranged_tests and has_nonnumeric_tests:
            raise Exception('Mixed ranged/non-numeric tests in %s' % str(current_tests))

        elif has_ranged_tests:
            property_tests[property] = [range.toFilter(property).tests for range in test_ranges(current_tests)]

        else:
            property_tests[property] = test_combinations(current_tests)
            
    # get a list of the number of combinations for each group of tests from above.
    property_counts = [len(property_tests[property]) for property in properties]
    
    filters = []
        
    # now iterate over each combination - for large numbers of tests, this can get big really, really fast
    for property_indexes in xindexes(property_counts):
        # list of lists of tests
        testslist = [property_tests[properties[i]][j] for (i, j) in enumerate(property_indexes)]
        
        # corresponding filter
        filter = Filter(*reduce(operator.add, testslist))
        
        filters.append(filter)

    if len(filters):
        return sorted(filters)

    # if no filters have been defined, return a blank one that matches anything
    return [Filter()]
def tests_filter_combinations ( tests ) : if len ( tests ) == 0 : return [ Filter ( ) ] properties = sorted ( list ( set ( [ test . property for test in tests ] ) ) ) property_tests = { } for property in properties : current_tests = [ test for test in tests if test . property == property ] has_ranged_tests = True in [ test . isRanged ( ) for test in current_tests ] has_nonnumeric_tests = False in [ test . isNumeric ( ) for test in current_tests ] if has_ranged_tests and has_nonnumeric_tests : raise Exception ( 'Mixed ranged/non-numeric tests in %s' % str ( current_tests ) ) elif has_ranged_tests : property_tests [ property ] = [ range . toFilter ( property ) . tests for range in test_ranges ( current_tests ) ] else : property_tests [ property ] = test_combinations ( current_tests ) property_counts = [ len ( property_tests [ property ] ) for property in properties ] filters = [ ] for property_indexes in xindexes ( property_counts ) : testslist = [ property_tests [ properties [ i ] ] [ j ] for ( i , j ) in enumerate ( property_indexes ) ] filter = Filter ( * reduce ( operator . add , testslist ) ) filters . append ( filter ) if len ( filters ) : return sorted ( filters ) return [ Filter ( ) ]
Return a complete list of filter combinations for given list of tests