MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_deferred

Method test_deferred

test/ext/test_extendedattr.py:275–337  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

273 eq_(u.email_address, "foo@bar.com")
274
275 def test_deferred(self):
276 for base in (object, MyBaseClass, MyClass):
277
278 class Foo(base):
279 pass
280
281 data = {"a": "this is a", "b": 12}
282
283 def loader(state, keys, passive):
284 for k in keys:
285 state.dict[k] = data[k]
286 return attributes.ATTR_WAS_SET
287
288 manager = register_class(Foo)
289 manager.expired_attribute_loader = loader
290 _register_attribute(Foo, "a", uselist=False, useobject=False)
291 _register_attribute(Foo, "b", uselist=False, useobject=False)
292
293 if base is object:
294 assert Foo not in (
295 instrumentation._instrumentation_factory._state_finders
296 )
297 else:
298 assert Foo in (
299 instrumentation._instrumentation_factory._state_finders
300 )
301
302 f = Foo()
303 attributes.instance_state(f)._expire(
304 attributes.instance_dict(f), set()
305 )
306 eq_(f.a, "this is a")
307 eq_(f.b, 12)
308
309 f.a = "this is some new a"
310 attributes.instance_state(f)._expire(
311 attributes.instance_dict(f), set()
312 )
313 eq_(f.a, "this is a")
314 eq_(f.b, 12)
315
316 attributes.instance_state(f)._expire(
317 attributes.instance_dict(f), set()
318 )
319 f.a = "this is another new a"
320 eq_(f.a, "this is another new a")
321 eq_(f.b, 12)
322
323 attributes.instance_state(f)._expire(
324 attributes.instance_dict(f), set()
325 )
326 eq_(f.a, "this is a")
327 eq_(f.b, 12)
328
329 del f.a
330 eq_(f.a, None)
331 eq_(f.b, 12)
332

Callers

nothing calls this directly

Calls 6

register_classFunction · 0.90
eq_Function · 0.90
_expireMethod · 0.80
_commit_allMethod · 0.80
_register_attributeFunction · 0.70
FooClass · 0.70

Tested by

no test coverage detected