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)
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)
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)
def test_is_match(case, expected): assert _.is_match(*case) == expected