MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _roundtrip

Method _roundtrip

test/ext/declarative/test_inheritance.py:49–112  ·  view source on GitHub ↗
(
        self,
        Employee,
        Manager,
        Engineer,
        Boss,
        polymorphic=True,
        explicit_type=False,
    )

Source from the content-addressed store, hash-verified

47 RemoveORMEventsGlobally, DeclarativeTestBase, testing.AssertsCompiledSQL
48):
49 def _roundtrip(
50 self,
51 Employee,
52 Manager,
53 Engineer,
54 Boss,
55 polymorphic=True,
56 explicit_type=False,
57 ):
58 Base.metadata.create_all(testing.db)
59 sess = fixture_session()
60 e1 = Engineer(name="dilbert", primary_language="java")
61 e2 = Engineer(name="wally", primary_language="c++")
62 m1 = Manager(name="dogbert", golf_swing="fore!")
63 e3 = Engineer(name="vlad", primary_language="cobol")
64 b1 = Boss(name="pointy haired")
65
66 if polymorphic:
67 for obj in [e1, e2, m1, e3, b1]:
68 if explicit_type:
69 eq_(obj.type, obj.__mapper__.polymorphic_identity)
70 else:
71 assert_raises_message(
72 AttributeError,
73 "does not implement attribute .?'type' "
74 "at the instance level.",
75 getattr,
76 obj,
77 "type",
78 )
79 else:
80 assert "type" not in Engineer.__dict__
81 assert "type" not in Manager.__dict__
82 assert "type" not in Boss.__dict__
83
84 sess.add_all([e1, e2, m1, e3, b1])
85 sess.flush()
86 sess.expunge_all()
87 if polymorphic:
88 eq_(
89 sess.query(Employee).order_by(Employee.name).all(),
90 [
91 Engineer(name="dilbert"),
92 Manager(name="dogbert"),
93 Boss(name="pointy haired"),
94 Engineer(name="vlad"),
95 Engineer(name="wally"),
96 ],
97 )
98 else:
99 eq_(
100 sess.query(Engineer).order_by(Engineer.name).all(),
101 [
102 Engineer(name="dilbert"),
103 Engineer(name="vlad"),
104 Engineer(name="wally"),
105 ],
106 )

Calls 15

fixture_sessionFunction · 0.90
eq_Function · 0.90
assert_raises_messageFunction · 0.90
create_allMethod · 0.80
EngineerClass · 0.70
ManagerClass · 0.70
BossClass · 0.70
add_allMethod · 0.45
flushMethod · 0.45
expunge_allMethod · 0.45
allMethod · 0.45
order_byMethod · 0.45

Tested by

no test coverage detected