Beispiel #1
0
def test_model_to_dict(db, model, expected):
    """Test that a model can be serialized to a dict."""
    db.save(model)
    model = (db.query(
        model.__class__).filter(core.identity_map_filter(model)).options(
            sa.orm.eagerload('*')).first())

    assert pyd.is_match(model.to_dict(), expected)
    assert pyd.is_match(dict(model), expected)
Beispiel #2
0
def test_model_to_dict(db, model, expected):
    """Test that a model can be serialized to a dict."""
    db.save(model)
    model = (db.query(model.__class__)
             .filter(core.identity_map_filter(model))
             .options(sa.orm.eagerload('*'))
             .first())

    assert pyd.is_match(model.to_dict(), expected)
    assert pyd.is_match(dict(model), expected)
Beispiel #3
0
def matches(source):
    """Creates a :func:`pydash.collections.where` style predicate function
    which performs a deep comparison between a given object and the `source`
    object, returning ``True`` if the given object has equivalent property
    values, else ``False``.

    Args:
        source (dict): Source object used for comparision.

    Returns:
        function: Function that compares an object to `source` and returns
            whether the two objects contain the same items.

    Example:

        >>> matches({'a': {'b': 2}})({'a': {'b': 2, 'c':3}})
        True
        >>> matches({'a': 1})({'b': 2, 'a': 1})
        True
        >>> matches({'a': 1})({'b': 2, 'a': 2})
        False

    .. versionadded:: 1.0.0

    .. versionchanged:: 3.0.0
        Use :func:`pydash.predicates.is_match` as matching function.
    """
    return lambda obj: pyd.is_match(obj, source)
Beispiel #4
0
def matches(source):
    """Creates a :func:`pydash.collections.where` style predicate function
    which performs a deep comparison between a given object and the `source`
    object, returning ``True`` if the given object has equivalent property
    values, else ``False``.

    Args:
        source (dict): Source object used for comparision.

    Returns:
        function: Function that compares an object to `source` and returns
            whether the two objects contain the same items.

    Example:

        >>> matches({'a': {'b': 2}})({'a': {'b': 2, 'c':3}})
        True
        >>> matches({'a': 1})({'b': 2, 'a': 1})
        True
        >>> matches({'a': 1})({'b': 2, 'a': 2})
        False

    .. versionadded:: 1.0.0

    .. versionchanged:: 3.0.0
        Use :func:`pydash.predicates.is_match` as matching function.
    """
    return lambda obj: pyd.is_match(obj, source)
Beispiel #5
0
def test_is_match(case, expected):
    assert _.is_match(*case) == expected