MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_loader_criteria

Method test_loader_criteria

test/orm/test_pickled.py:336–376  ·  view source on GitHub ↗

test #8109

(self, pickle_it, use_mixin)

Source from the content-addressed store, hash-verified

334 @testing.combinations(True, False, argnames="pickle_it")
335 @testing.combinations(True, False, argnames="use_mixin")
336 def test_loader_criteria(self, pickle_it, use_mixin):
337 """test #8109"""
338
339 users, addresses = (self.tables.users, self.tables.addresses)
340
341 AddressCls = AddressWMixin if use_mixin else Address
342
343 self.mapper_registry.map_imperatively(
344 User,
345 users,
346 properties={"addresses": relationship(AddressCls)},
347 )
348
349 self.mapper_registry.map_imperatively(AddressCls, addresses)
350
351 with fixture_session(expire_on_commit=False) as sess:
352 u1 = User(name="ed")
353 u1.addresses = [
354 AddressCls(email_address="ed@bar.com"),
355 AddressCls(email_address="ed@foo.com"),
356 ]
357 sess.add(u1)
358 sess.commit()
359
360 with fixture_session(expire_on_commit=False) as sess:
361 # note that non-lambda is not picklable right now as
362 # SQL expressions usually can't be pickled.
363 opt = with_loader_criteria(
364 Mixin if use_mixin else Address,
365 no_ed_foo,
366 include_aliases=True,
367 )
368
369 u1 = sess.query(User).options(opt).first()
370
371 if pickle_it:
372 u1 = pickle.loads(pickle.dumps(u1))
373 sess.close()
374 sess.add(u1)
375
376 eq_([ad.email_address for ad in u1.addresses], ["ed@bar.com"])
377
378 def test_instance_deferred_cols(self):
379 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