Exemplo n.º 1
0
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()
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
def test_group_by_pred__iterable():
    assert_equal(utils.group_by_pred(lambda x: x % 2 == 0, xrange(1, 4)),
                 ([2], [1, 3]))
Exemplo n.º 4
0
def test_group_by_pred__is_even():
    assert_equal(utils.group_by_pred(lambda x: x % 2 == 0, [1, 2, 3]),
                 ([2], [1, 3]))
Exemplo n.º 5
0
def test_group_by_pred__always_true():
    assert_equal(utils.group_by_pred(lambda x: True, [1, 2, 3]),
                 ([1, 2, 3], []))
Exemplo n.º 6
0
def test_group_by_pred__always_false():
    assert_equal(utils.group_by_pred(lambda x: False, [1, 2, 3]),
                 ([], [1, 2, 3]))
Exemplo n.º 7
0
def test_group_by_pred__empty_list():
    assert_equal(utils.group_by_pred(id, []), ([], []))
Exemplo n.º 8
0
def test_group_by_pred__iterable():
    assert utils.group_by_pred(lambda x: x % 2 == 0, range(1,
                                                           4)) == ([2], [1, 3])
Exemplo n.º 9
0
def test_group_by_pred__is_even():
    assert utils.group_by_pred(lambda x: x % 2 == 0,
                               [1, 2, 3]) == ([2], [1, 3])
Exemplo n.º 10
0
def test_group_by_pred__always_true():
    assert utils.group_by_pred(lambda x: True, [1, 2, 3]) == ([1, 2, 3], [])
Exemplo n.º 11
0
def test_group_by_pred__always_false():
    assert utils.group_by_pred(lambda x: False, [1, 2, 3]) == ([], [1, 2, 3])
Exemplo n.º 12
0
def test_group_by_pred__empty_list():
    assert utils.group_by_pred(id, []) == ([], [])