def _get_summary_spec(specs_or_keys): """Returns a specification object that may be used to describe a set of requirements. This is used if a key or value does not match the possible specs, thereby describing the set of allowed values. """ specs, keys = group_by_pred(_is_spec, specs_or_keys) if specs and keys: return Or(ValueIn(keys, description="key in {rvalue}"), *specs) elif specs: return Or(*specs) elif keys: return ValueIn(keys, description="key in {rvalue}") return ValueMissing()
def _print_sub_nodes(cls, nodegraph, nodes, prefix=" "): _grouper = lambda node: (nodegraph.get_node_state(node) != cls.DONE) viable_nodes, dead_nodes = group_by_pred(_grouper, nodes) viable_nodes.sort(key=str) for node in viable_nodes: runable = cls._get_runable_prefix(nodegraph, node) description = "%s%s %s" % (prefix, runable, node) if node.subnodes: states, threads \ = cls._count_states(nodegraph, node.subnodes, True) description = "%s (%s)" \ % (description, cls._describe_states(states, threads)) print_func = cls._get_print_function(nodegraph, node) print_func(description) is_last_node = (node == viable_nodes[-1]) and not dead_nodes current_prefix = prefix + (" " if is_last_node else "| ") if node.dependencies: if cls._collapse_node(nodegraph, node.dependencies): description = "+ %i dependencies hidden ..." \ % cls._count_dependencies(node.dependencies | node.subnodes) print_disabled(current_prefix + description) print_disabled(current_prefix) else: cls._print_sub_nodes(nodegraph, node.dependencies, current_prefix + " ") else: print_func(current_prefix) if dead_nodes: print_disabled(prefix + "+ %i dependencies hidden ..." % cls._count_dependencies(dead_nodes)) print_disabled(prefix)
def test_group_by_pred__iterable(): assert_equal(utils.group_by_pred(lambda x: x % 2 == 0, xrange(1, 4)), ([2], [1, 3]))
def test_group_by_pred__is_even(): assert_equal(utils.group_by_pred(lambda x: x % 2 == 0, [1, 2, 3]), ([2], [1, 3]))
def test_group_by_pred__always_true(): assert_equal(utils.group_by_pred(lambda x: True, [1, 2, 3]), ([1, 2, 3], []))
def test_group_by_pred__always_false(): assert_equal(utils.group_by_pred(lambda x: False, [1, 2, 3]), ([], [1, 2, 3]))
def test_group_by_pred__empty_list(): assert_equal(utils.group_by_pred(id, []), ([], []))