Example #1
0
def has_length(x):
    """Evaluates whether len(item) satisfies a given matcher, providing a
    shortcut to the frequently used has_length(equal_to(x))
    
    For example:  has_length(equal_to(x))
             vs.  has_length(x)
    """
    return HasLength(wrap_shortcut(x))
def only_contains(*items):
    """Matches collections that only contain elements satisfying any of a list
    of items.

    For example, [1,2,3] would satisfy only_contains(less_than(4)).
    
    If an item is not a matcher, it is equivalent to equal_to(item), so the
    list in the example above would also satisfy only_contains(1,2,3).

    """
    matchers = []
    for item in items:
        matchers.append(wrap_shortcut(item))    
    return IsSequenceOnlyContaining(apply(any_of, matchers))
def has_value(value):
    return IsDictContainingValue(wrap_shortcut(value))
Example #4
0
def has_key(key):
    return IsDictContainingKey(wrap_shortcut(key))
Example #5
0
def _wrap_shortcut(x):
    if isinstance(x, type):
        return instance_of(x)
    else:
        return wrap_shortcut(x)
Example #6
0
def has_item(item):
    return IsSequenceContaining(wrap_shortcut(item))
Example #7
0
def has_entry(key, value):
    return IsDictContaining(wrap_shortcut(key), wrap_shortcut(value))