MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_case

Method test_case

test/orm/test_relationships.py:3391–3467  ·  view source on GitHub ↗
(self, B_a_view, B_a_sync, A_bs_view, A_bs_sync)

Source from the content-addressed store, hash-verified

3389 @testing.combinations(True, False, None, argnames="B_a_sync")
3390 @testing.combinations(True, False, argnames="B_a_view")
3391 def test_case(self, B_a_view, B_a_sync, A_bs_view, A_bs_sync):
3392 class A(ComparableEntity):
3393 pass
3394
3395 class B(ComparableEntity):
3396 pass
3397
3398 case = self.cases[(B_a_view, B_a_sync, A_bs_view, A_bs_sync)]
3399 print(
3400 {
3401 "B_a_view": B_a_view,
3402 "B_a_sync": B_a_sync,
3403 "A_bs_view": A_bs_view,
3404 "A_bs_sync": A_bs_sync,
3405 },
3406 case,
3407 )
3408
3409 def rel():
3410 return relationship(
3411 B,
3412 viewonly=A_bs_view,
3413 sync_backref=A_bs_sync,
3414 backref=backref("a", viewonly=B_a_view, sync_backref=B_a_sync),
3415 )
3416
3417 if case.A_bs_init_error:
3418 assert_raises_message(
3419 exc.ArgumentError,
3420 "sync_backref and viewonly cannot both be True",
3421 rel,
3422 )
3423 return
3424
3425 self.mapper_registry.map_imperatively(
3426 A,
3427 self.tables.t1,
3428 properties={"bs": rel()},
3429 )
3430 self.mapper_registry.map_imperatively(B, self.tables.t2)
3431
3432 if case.B_a_init_error:
3433 assert_raises_message(
3434 exc.ArgumentError,
3435 "sync_backref and viewonly cannot both be True",
3436 configure_mappers,
3437 )
3438 return
3439
3440 if case.map_error:
3441 if case.map_error == "AB":
3442 args = ("A.bs", "B.a")
3443 else:
3444 args = ("B.a", "A.bs")
3445 assert_raises_message(
3446 exc.InvalidRequestError,
3447 "Relationship %s cannot specify sync_backref=True since %s "
3448 % args,

Callers

nothing calls this directly

Calls 8

assert_raises_messageFunction · 0.90
configure_mappersFunction · 0.90
inspectFunction · 0.90
map_imperativelyMethod · 0.80
has_changesMethod · 0.80
AClass · 0.70
BClass · 0.70
appendMethod · 0.45

Tested by

no test coverage detected