MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_deferred

Method test_deferred

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

Source from the content-addressed store, hash-verified

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

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