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 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, []), ([], []))
def test_group_by_pred__iterable(): assert utils.group_by_pred(lambda x: x % 2 == 0, range(1, 4)) == ([2], [1, 3])
def test_group_by_pred__is_even(): assert utils.group_by_pred(lambda x: x % 2 == 0, [1, 2, 3]) == ([2], [1, 3])
def test_group_by_pred__always_true(): assert utils.group_by_pred(lambda x: True, [1, 2, 3]) == ([1, 2, 3], [])
def test_group_by_pred__always_false(): assert utils.group_by_pred(lambda x: False, [1, 2, 3]) == ([], [1, 2, 3])
def test_group_by_pred__empty_list(): assert utils.group_by_pred(id, []) == ([], [])