本文整理汇总了Python中sqlalchemy.orm.interfaces.PropComparator方法的典型用法代码示例。如果您正苦于以下问题:Python interfaces.PropComparator方法的具体用法?Python interfaces.PropComparator怎么用?Python interfaces.PropComparator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.orm.interfaces
的用法示例。
在下文中一共展示了interfaces.PropComparator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_kwarg_accepted
# 需要导入模块: from sqlalchemy.orm import interfaces [as 别名]
# 或者: from sqlalchemy.orm.interfaces import PropComparator [as 别名]
def test_kwarg_accepted(self):
users, Address = self.tables.users, self.classes.Address
class DummyComposite(object):
def __init__(self, x, y):
pass
from sqlalchemy.orm.interfaces import PropComparator
class MyFactory(PropComparator):
pass
for args in (
(column_property, users.c.name),
(deferred, users.c.name),
(synonym, "name"),
(composite, DummyComposite, users.c.id, users.c.name),
(relationship, Address),
(backref, "address"),
(dynamic_loader, Address),
):
fn = args[0]
args = args[1:]
fn(comparator_factory=MyFactory, *args)
示例2: test_comparator
# 需要导入模块: from sqlalchemy.orm import interfaces [as 别名]
# 或者: from sqlalchemy.orm.interfaces import PropComparator [as 别名]
def test_comparator(self):
class Comparator(PropComparator):
__hash__ = None
attr = "bar"
def method1(self):
return "method1"
def method2(self, other):
return "method2"
def __getitem__(self, key):
return "value"
def __eq__(self, other):
return column("foo") == func.upper(other)
Foo = self._fixture()
d = MockDescriptor(Foo, "foo", comparator_factory=Comparator)
d.instrument_class(Foo.__mapper__)
eq_(Foo.foo.method1(), "method1")
eq_(Foo.foo.method2("x"), "method2")
assert Foo.foo.attr == "bar"
assert Foo.foo["bar"] == "value"
eq_((Foo.foo == "bar").__str__(), "foo = upper(:upper_1)")