MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _test_list

Method _test_list

test/orm/test_collection.py:239–481  ·  test/orm/test_collection.py::CollectionsTest._test_list
(self, typecallable, creator=None)

Source from the content-addressed store, hash-verified

237 eq_(set(adapter), {e1, e2})
238
239 def _test_list(self, typecallable, creator=None):
240 if creator is None:
241 creator = self.entity_maker
242
243 class Foo:
244 pass
245
246 canary = Canary()
247 instrumentation.register_class(Foo)
248 d = _register_attribute(
249 Foo,
250 class="st">"attr",
251 uselist=True,
252 typecallable=typecallable,
253 useobject=True,
254 )
255 canary.listen(d)
256
257 obj = Foo()
258 adapter = collections.collection_adapter(obj.attr)
259 direct = obj.attr
260 control = list()
261
262 def assert_eq():
263 eq_(set(direct), canary.data)
264 eq_(set(adapter), canary.data)
265 eq_(direct, control)
266
267 class="cm"># assume append() is available for list tests
268 e = creator()
269 direct.append(e)
270 control.append(e)
271 assert_eq()
272
273 if hasattr(direct, class="st">"pop"):
274 direct.pop()
275 control.pop()
276 assert_eq()
277
278 if hasattr(direct, class="st">"__setitem__"):
279 e = creator()
280 direct.append(e)
281 control.append(e)
282
283 e = creator()
284 direct[0] = e
285 control[0] = e
286 assert_eq()
287
288 if reduce(
289 and_,
290 [
291 hasattr(direct, a)
292 for a in (class="st">"__delitem__", class="st">"insert", class="st">"__len__")
293 ],
294 True,
295 ):
296 values = [creator(), creator(), creator(), creator()]

Callers 5

test_listMethod · 0.95
test_list_subclassMethod · 0.95
test_list_duckMethod · 0.95
test_list_emulatesMethod · 0.95

Calls 12

listenMethod · 0.95
defer_dupe_checkMethod · 0.95
assert_raisesFunction · 0.90
CanaryClass · 0.85
creatorFunction · 0.85
_register_attributeFunction · 0.70
FooClass · 0.70
appendMethod · 0.45
popMethod · 0.45
removeMethod · 0.45
clearMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected