MCPcopy Create free account
hub / github.com/zzzeek/sqlalchemy / test_inheritance

Method test_inheritance

test/ext/test_extendedattr.py:338–376  ·  view source on GitHub ↗

tests that attributes are polymorphic

(self)

Source from the content-addressed store, hash-verified

336 eq_(f.b, 12)
337
338 def test_inheritance(self):
339 """tests that attributes are polymorphic"""
340
341 for base in (object, MyBaseClass, MyClass):
342
343 class Foo(base):
344 pass
345
346 class Bar(Foo):
347 pass
348
349 register_class(Foo)
350 register_class(Bar)
351
352 def func1(state, passive):
353 return "this is the foo attr"
354
355 def func2(state, passive):
356 return "this is the bar attr"
357
358 def func3(state, passive):
359 return "this is the shared attr"
360
361 _register_attribute(
362 Foo, "element", uselist=False, callable_=func1, useobject=True
363 )
364 _register_attribute(
365 Foo, "element2", uselist=False, callable_=func3, useobject=True
366 )
367 _register_attribute(
368 Bar, "element", uselist=False, callable_=func2, useobject=True
369 )
370
371 x = Foo()
372 y = Bar()
373 assert x.element == "this is the foo attr"
374 assert y.element == "this is the bar attr", y.element
375 assert x.element2 == "this is the shared attr"
376 assert y.element2 == "this is the shared attr"
377
378 def test_collection_with_backref(self):
379 for base in (object, MyBaseClass, MyClass):

Callers

nothing calls this directly

Calls 4

register_classFunction · 0.90
_register_attributeFunction · 0.70
FooClass · 0.70
BarClass · 0.70

Tested by

no test coverage detected