예제 #1
0
def has_property(name, match=None):
    """Matches if object has a property with a given name whose value satisfies
    a given matcher.

    :param name: The name of the property.
    :param match: Optional matcher to satisfy.

    This matcher determines if the evaluated object has a property with a given
    name. If no such property is found, ``has_property`` is not satisfied.

    If the property is found, its value is passed to a given matcher for
    evaluation. If the ``match`` argument is not a matcher, it is implicitly
    wrapped in an :py:func:`~hamcrest.core.core.isequal.equal_to` matcher to
    check for equality.

    If the ``match`` argument is not provided, the
    :py:func:`~hamcrest.core.core.isanything.anything` matcher is used so that
    ``has_property`` is satisfied if a matching property is found.

    Examples::

        has_property('name', starts_with('J'))
        has_property('name', 'Jon')
        has_property('name')

    """

    if match is None:
        match = anything()

    return IsObjectWithProperty(name, wrap_shortcut(match))
예제 #2
0
def has_property(name, match=None):
    """Matches if object has a property with a given name whose value satisfies
    a given matcher.

    :param name: The name of the property.
    :param match: Optional matcher to satisfy.

    This matcher determines if the evaluated object has a property with a given
    name. If no such property is found, ``has_property`` is not satisfied.

    If the property is found, its value is passed to a given matcher for
    evaluation. If the ``match`` argument is not a matcher, it is implicitly
    wrapped in an :py:func:`~hamcrest.core.core.isequal.equal_to` matcher to
    check for equality.

    If the ``match`` argument is not provided, the
    :py:func:`~hamcrest.core.core.isanything.anything` matcher is used so that
    ``has_property`` is satisfied if a matching property is found.

    Examples::

        has_property('name', starts_with('J'))
        has_property('name', 'Jon')
        has_property('name')

    """

    if match is None:
        match = anything()

    return IsObjectWithProperty(name, wrap_shortcut(match))
예제 #3
0
def has_damage(damage_amount=None, damage_type=None):
    """
    Check if weapon makes specific amount and type of damage
    Both parameters support using matchers
    has_damage(greater_than(3), 'piercing') is valid call

    :param damage_amount: amount of damage
    :type damage_amount: int
    :param damage_type: type of damage
    :type damage_type: string
    """
    if damage_amount is not None and damage_type is not None:
        return HasDamage(wrap_matcher(damage_amount),
                         wrap_matcher(damage_type))
    elif damage_amount is None:
        return HasDamage(anything(), wrap_matcher(damage_type))
    else:
        return HasDamage(wrap_matcher(damage_amount), anything())
예제 #4
0
def has_property(name, value=None):
    """Matches objects that have a property matching the given value matcher.

    :param name: The name of the property that the object must have. If the object
        does not have this property, the matcher will fail.

    :param value: The value to match. If the value is not provided, the
        matcher will match against anything(), which transforms this
        matcher into a property existence check.

    """

    if value is None:
        value = anything()

    return IsObjectWithProperty(name, wrap_shortcut(value))