MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_loader_criteria

Method test_loader_criteria

test/orm/test_pickled.py:351–391  ·  view source on GitHub ↗

test #8109

(self, pickle_it, use_mixin)

Source from the content-addressed store, hash-verified

349 @testing.combinations(True, False, argnames="pickle_it")
350 @testing.combinations(True, False, argnames="use_mixin")
351 def test_loader_criteria(self, pickle_it, use_mixin):
352 """test #8109"""
353
354 users, addresses = (self.tables.users, self.tables.addresses)
355
356 AddressCls = AddressWMixin if use_mixin else Address
357
358 self.mapper_registry.map_imperatively(
359 User,
360 users,
361 properties={"addresses": relationship(AddressCls)},
362 )
363
364 self.mapper_registry.map_imperatively(AddressCls, addresses)
365
366 with fixture_session(expire_on_commit=False) as sess:
367 u1 = User(name="ed")
368 u1.addresses = [
369 AddressCls(email_address="ed@bar.com"),
370 AddressCls(email_address="ed@foo.com"),
371 ]
372 sess.add(u1)
373 sess.commit()
374
375 with fixture_session(expire_on_commit=False) as sess:
376 # note that non-lambda is not picklable right now as
377 # SQL expressions usually can't be pickled.
378 opt = with_loader_criteria(
379 Mixin if use_mixin else Address,
380 no_ed_foo,
381 include_aliases=True,
382 )
383
384 u1 = sess.query(User).options(opt).first()
385
386 if pickle_it:
387 u1 = pickle.loads(pickle.dumps(u1))
388 sess.close()
389 sess.add(u1)
390
391 eq_([ad.email_address for ad in u1.addresses], ["ed@bar.com"])
392
393 def test_instance_deferred_cols(self):
394 users, addresses = (self.tables.users, self.tables.addresses)

Callers

nothing calls this directly

Calls 14

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
UserClass · 0.90
with_loader_criteriaFunction · 0.90
eq_Function · 0.90
map_imperativelyMethod · 0.80
addMethod · 0.45
commitMethod · 0.45
firstMethod · 0.45
optionsMethod · 0.45
queryMethod · 0.45
loadsMethod · 0.45

Tested by

no test coverage detected