(self, eager_defaults)
| 1141 | |
| 1142 | @testing.variation("eager_defaults", ["auto", True, False]) |
| 1143 | def test_insert(self, eager_defaults): |
| 1144 | althohoval, hohoval, default_t, Hoho = ( |
| 1145 | self.other.althohoval, |
| 1146 | self.other.hohoval, |
| 1147 | self.tables.default_t, |
| 1148 | self.classes.Hoho, |
| 1149 | ) |
| 1150 | |
| 1151 | mp = self.mapper_registry.map_imperatively( |
| 1152 | Hoho, |
| 1153 | default_t, |
| 1154 | eager_defaults=( |
| 1155 | "auto" if eager_defaults.auto else bool(eager_defaults) |
| 1156 | ), |
| 1157 | ) |
| 1158 | |
| 1159 | h1 = Hoho(hoho=althohoval) |
| 1160 | h2 = Hoho(counter=12) |
| 1161 | h3 = Hoho(hoho=althohoval, counter=12) |
| 1162 | h4 = Hoho() |
| 1163 | h5 = Hoho(foober="im the new foober") |
| 1164 | |
| 1165 | session = fixture_session(expire_on_commit=False) |
| 1166 | session.add_all((h1, h2, h3, h4, h5)) |
| 1167 | session.commit() |
| 1168 | |
| 1169 | eq_(h1.hoho, althohoval) |
| 1170 | eq_(h3.hoho, althohoval) |
| 1171 | |
| 1172 | def go(): |
| 1173 | # test deferred load of attributes, one select per instance |
| 1174 | self.assert_(h2.hoho == h4.hoho == h5.hoho == hohoval) |
| 1175 | |
| 1176 | if mp._prefer_eager_defaults(testing.db.dialect, default_t): |
| 1177 | self.sql_count_(0, go) |
| 1178 | else: |
| 1179 | self.sql_count_(3, go) |
| 1180 | |
| 1181 | def go(): |
| 1182 | self.assert_(h1.counter == h4.counter == h5.counter == 7) |
| 1183 | |
| 1184 | if mp._prefer_eager_defaults(testing.db.dialect, default_t): |
| 1185 | self.sql_count_(0, go) |
| 1186 | else: |
| 1187 | self.sql_count_(1, go) |
| 1188 | |
| 1189 | def go(): |
| 1190 | self.assert_(h3.counter == h2.counter == 12) |
| 1191 | self.assert_(h2.foober == h3.foober == h4.foober == "im foober") |
| 1192 | self.assert_(h5.foober == "im the new foober") |
| 1193 | |
| 1194 | self.sql_count_(0, go) |
| 1195 | |
| 1196 | session.expunge_all() |
| 1197 | |
| 1198 | h1, h2, h3, h4, h5 = session.query(Hoho).order_by(Hoho.id).all() |
| 1199 | |
| 1200 | eq_(h1.hoho, althohoval) |
nothing calls this directly
no test coverage detected