MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_basic_w_new_style

Method test_basic_w_new_style

test/orm/test_deferred.py:100–139  ·  view source on GitHub ↗

sanity check that mapped_column(deferred=True) works

(self)

Source from the content-addressed store, hash-verified

98 )
99
100 def test_basic_w_new_style(self):
101 """sanity check that mapped_column(deferred=True) works"""
102
103 class Base(DeclarativeBase):
104 pass
105
106 class Order(Base):
107 __tablename__ = "orders"
108
109 id: Mapped[int] = mapped_column(primary_key=True)
110 user_id: Mapped[int]
111 address_id: Mapped[int]
112 isopen: Mapped[bool]
113 description: Mapped[str] = mapped_column(deferred=True)
114
115 q = fixture_session().query(Order).order_by(Order.id)
116
117 def go():
118 result = q.all()
119 o2 = result[2]
120 o2.description
121
122 self.sql_eq_(
123 go,
124 [
125 (
126 "SELECT orders.id AS orders_id, "
127 "orders.user_id AS orders_user_id, "
128 "orders.address_id AS orders_address_id, "
129 "orders.isopen AS orders_isopen "
130 "FROM orders ORDER BY orders.id",
131 {},
132 ),
133 (
134 "SELECT orders.description "
135 "FROM orders WHERE orders.id = :pk_1",
136 {"pk_1": 3},
137 ),
138 ],
139 )
140
141 @testing.combinations(True, False, None, argnames="deferred_parameter")
142 def test_group_defer_newstyle(self, deferred_parameter: Union[bool, None]):

Callers

nothing calls this directly

Calls 4

fixture_sessionFunction · 0.90
sql_eq_Method · 0.80
order_byMethod · 0.45
queryMethod · 0.45

Tested by

no test coverage detected