本文整理汇总了Python中sqlalchemy.testing.eq_函数的典型用法代码示例。如果您正苦于以下问题:Python eq_函数的具体用法?Python eq_怎么用?Python eq_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了eq_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_autoflush_expressions
def test_autoflush_expressions(self):
"""test that an expression which is dependent on object state is
evaluated after the session autoflushes. This is the lambda
inside of strategies.py lazy_clause.
"""
users, Address, addresses, User = (self.tables.users,
self.classes.Address,
self.tables.addresses,
self.classes.User)
mapper(User, users, properties={
'addresses': relationship(Address, backref="user")})
mapper(Address, addresses)
sess = create_session(autoflush=True, autocommit=False)
u = User(name='ed', addresses=[Address(email_address='foo')])
sess.add(u)
eq_(sess.query(Address).filter(Address.user == u).one(),
Address(email_address='foo'))
# still works after "u" is garbage collected
sess.commit()
sess.close()
u = sess.query(User).get(u.id)
q = sess.query(Address).filter(Address.user == u)
del u
gc_collect()
eq_(q.one(), Address(email_address='foo'))
示例2: test_defaults_second_table
def test_defaults_second_table(self):
users, addresses = self.tables.users, self.tables.addresses
values = {
addresses.c.email_address: users.c.name,
users.c.name: 'ed2'
}
ret = testing.db.execute(
addresses.update().
values(values).
where(users.c.id == addresses.c.user_id).
where(users.c.name == 'ed'))
eq_(set(ret.prefetch_cols()), set([users.c.some_update]))
expected = [
(2, 8, 'ed'),
(3, 8, 'ed'),
(4, 9, '[email protected]')]
self._assert_addresses(addresses, expected)
expected = [
(8, 'ed2', 'im the update'),
(9, 'fred', 'value')]
self._assert_users(users, expected)
示例3: test_update_changes_resets_dirty
def test_update_changes_resets_dirty(self):
User = self.classes.User
sess = Session(autoflush=False)
john, jack, jill, jane = sess.query(User).order_by(User.id).all()
john.age = 50
jack.age = 37
# autoflush is false. therefore our '50' and '37' are getting
# blown away by this operation.
sess.query(User).filter(User.age > 29).\
update({'age': User.age - 10}, synchronize_session='evaluate')
for x in (john, jack, jill, jane):
assert not sess.is_modified(x)
eq_([john.age, jack.age, jill.age, jane.age], [25, 37, 29, 27])
john.age = 25
assert john in sess.dirty
assert jack in sess.dirty
assert jill not in sess.dirty
assert not sess.is_modified(john)
assert not sess.is_modified(jack)
示例4: test_attached_as_schema
def test_attached_as_schema(self):
cx = testing.db.connect()
try:
cx.execute('ATTACH DATABASE ":memory:" AS test_schema')
dialect = cx.dialect
assert dialect.get_table_names(cx, 'test_schema') == []
meta = MetaData(cx)
Table('created', meta, Column('id', Integer),
schema='test_schema')
alt_master = Table('sqlite_master', meta, autoload=True,
schema='test_schema')
meta.create_all(cx)
eq_(dialect.get_table_names(cx, 'test_schema'), ['created'])
assert len(alt_master.c) > 0
meta.clear()
reflected = Table('created', meta, autoload=True,
schema='test_schema')
assert len(reflected.c) == 1
cx.execute(reflected.insert(), dict(id=1))
r = cx.execute(reflected.select()).fetchall()
assert list(r) == [(1, )]
cx.execute(reflected.update(), dict(id=2))
r = cx.execute(reflected.select()).fetchall()
assert list(r) == [(2, )]
cx.execute(reflected.delete(reflected.c.id == 2))
r = cx.execute(reflected.select()).fetchall()
assert list(r) == []
# note that sqlite_master is cleared, above
meta.drop_all()
assert dialect.get_table_names(cx, 'test_schema') == []
finally:
cx.execute('DETACH DATABASE test_schema')
示例5: test_boolean
def test_boolean(self):
"Exercise type specification for boolean type."
columns = [
# column type, args, kwargs, expected ddl
(Boolean, [], {},
'BIT'),
]
metadata = MetaData()
table_args = ['test_mssql_boolean', metadata]
for index, spec in enumerate(columns):
type_, args, kw, res = spec
table_args.append(
Column('c%s' % index, type_(*args, **kw), nullable=None))
boolean_table = Table(*table_args)
dialect = mssql.dialect()
gen = dialect.ddl_compiler(dialect, schema.CreateTable(boolean_table))
for col in boolean_table.c:
index = int(col.name[1:])
testing.eq_(
gen.get_column_specification(col),
"%s %s" % (col.name, columns[index][3]))
self.assert_(repr(col))
示例6: test_with_transaction
def test_with_transaction(self):
conn = self.engine.connect()
trans = conn.begin()
eq_(conn.execute(select([1])).scalar(), 1)
assert not conn.closed
self.engine.test_shutdown()
_assert_invalidated(conn.execute, select([1]))
assert not conn.closed
assert conn.invalidated
assert trans.is_active
assert_raises_message(
tsa.exc.StatementError,
"Can't reconnect until invalid transaction is rolled back",
conn.execute, select([1]))
assert trans.is_active
assert_raises_message(
tsa.exc.InvalidRequestError,
"Can't reconnect until invalid transaction is rolled back",
trans.commit
)
assert trans.is_active
trans.rollback()
assert not trans.is_active
assert conn.invalidated
eq_(conn.execute(select([1])).scalar(), 1)
assert not conn.invalidated
示例7: _test_round_trip
def _test_round_trip(self, fixture, warnings=False):
from sqlalchemy import inspect
conn = testing.db.connect()
for from_, to_ in self._fixture_as_string(fixture):
inspector = inspect(conn)
conn.execute("CREATE TABLE foo (data %s)" % from_)
try:
if warnings:
def go():
return inspector.get_columns("foo")[0]
col_info = testing.assert_warnings(go,
["Could not instantiate"], regex=True)
else:
col_info = inspector.get_columns("foo")[0]
expected_type = type(to_)
is_(type(col_info['type']), expected_type)
# test args
for attr in ("scale", "precision", "length"):
if getattr(to_, attr, None) is not None:
eq_(
getattr(col_info['type'], attr),
getattr(to_, attr, None)
)
finally:
conn.execute("DROP TABLE foo")
示例8: test_selective_relationships
def test_selective_relationships(self):
sub, base_mtom, Related, Base, related, sub_mtom, base, Sub = (self.tables.sub,
self.tables.base_mtom,
self.classes.Related,
self.classes.Base,
self.tables.related,
self.tables.sub_mtom,
self.tables.base,
self.classes.Sub)
mapper(Base, base, properties={'related': relationship(Related,
secondary=base_mtom, backref='bases',
order_by=related.c.id)})
mapper(Sub, sub, inherits=Base, concrete=True,
properties={'related': relationship(Related,
secondary=sub_mtom, backref='subs',
order_by=related.c.id)})
mapper(Related, related)
sess = sessionmaker()()
b1, s1, r1, r2, r3 = Base(), Sub(), Related(), Related(), \
Related()
b1.related.append(r1)
b1.related.append(r2)
s1.related.append(r2)
s1.related.append(r3)
sess.add_all([b1, s1])
sess.commit()
eq_(s1.related, [r2, r3])
eq_(b1.related, [r1, r2])
示例9: test_time_result_processor
def test_time_result_processor(self):
eq_(
mysql.TIME().result_processor(None, None)(
datetime.timedelta(seconds=35, minutes=517,
microseconds=450)),
datetime.time(8, 37, 35, 450)
)
示例10: test_set_composite_attrs_via_selectable
def test_set_composite_attrs_via_selectable(self):
Values, CustomValues, values, Descriptions, descriptions = (self.classes.Values,
self.classes.CustomValues,
self.tables.values,
self.classes.Descriptions,
self.tables.descriptions)
session = Session()
d = Descriptions(
custom_descriptions = CustomValues('Color', 'Number'),
values =[
Values(custom_values = CustomValues('Red', '5')),
Values(custom_values=CustomValues('Blue', '1'))
]
)
session.add(d)
session.commit()
eq_(
testing.db.execute(descriptions.select()).fetchall(),
[(1, 'Color', 'Number')]
)
eq_(
testing.db.execute(values.select()).fetchall(),
[(1, 1, 'Red', '5'), (2, 1, 'Blue', '1')]
)
示例11: test_basic
def test_basic(self):
pjoin = polymorphic_union({'manager': managers_table, 'engineer'
: engineers_table}, 'type', 'pjoin')
employee_mapper = mapper(Employee, pjoin,
polymorphic_on=pjoin.c.type)
manager_mapper = mapper(Manager, managers_table,
inherits=employee_mapper,
concrete=True,
polymorphic_identity='manager')
engineer_mapper = mapper(Engineer, engineers_table,
inherits=employee_mapper,
concrete=True,
polymorphic_identity='engineer')
session = create_session()
session.add(Manager('Tom', 'knows how to manage things'))
session.add(Engineer('Kurt', 'knows how to hack'))
session.flush()
session.expunge_all()
assert set([repr(x) for x in session.query(Employee)]) \
== set(['Engineer Kurt knows how to hack',
'Manager Tom knows how to manage things'])
assert set([repr(x) for x in session.query(Manager)]) \
== set(['Manager Tom knows how to manage things'])
assert set([repr(x) for x in session.query(Engineer)]) \
== set(['Engineer Kurt knows how to hack'])
manager = session.query(Manager).one()
session.expire(manager, ['manager_data'])
eq_(manager.manager_data, 'knows how to manage things')
示例12: test_determine_local_remote_pairs_m2m
def test_determine_local_remote_pairs_m2m(self):
joincond = self._join_fixture_m2m()
eq_(
joincond.local_remote_pairs,
[(self.m2mleft.c.id, self.m2msecondary.c.lid),
(self.m2mright.c.id, self.m2msecondary.c.rid)]
)
示例13: test_determine_remote_columns_m2o_composite_selfref
def test_determine_remote_columns_m2o_composite_selfref(self):
joincond = self._join_fixture_m2o_composite_selfref()
eq_(
joincond.remote_columns,
set([self.composite_selfref.c.id,
self.composite_selfref.c.group_id])
)
示例14: test_determine_remote_columns_compound_2
def test_determine_remote_columns_compound_2(self):
joincond = self._join_fixture_compound_expression_2(
support_sync=False)
eq_(
joincond.remote_columns,
set([self.right.c.x, self.right.c.y])
)
示例15: test_invocation_systemwide_loaders
def test_invocation_systemwide_loaders(self):
baked.bake_lazy_loaders()
try:
User, Address = self._o2m_fixture()
sess = Session()
q = sess.query(User).options(lazyload(User.addresses))
with mock.patch.object(BakedLazyLoader, "_emit_lazyload") as el:
u1 = q.first()
u1.addresses
# invoked
is_(
el.mock_calls[0][1][1],
u1._sa_instance_state
)
finally:
baked.unbake_lazy_loaders()
clear_mappers()
User, Address = self._o2m_fixture()
sess = Session()
q = sess.query(User).options(lazyload(User.addresses))
with mock.patch.object(BakedLazyLoader, "_emit_lazyload") as el:
u1 = q.first()
u1.addresses
# not invoked
eq_(el.mock_calls, [])