def test_Source_notify_unwraps(self): """Source.notify unwraps callables before storing them""" def T(got,expected = True): self.assert_(expected == got,'got: %s expected: %s' % (got,expected)) a = Element(id=Id('a')) called = False class f: def __init__(self): self.called = False def __call__(self): self.called = True f = f() a.notify('foo',f) a.foo = 10 T(f.called)
def test_Source_notify_unwraps(self): """Source.notify unwraps callables before storing them""" def T(got, expected=True): self.assert_(expected == got, 'got: %s expected: %s' % (got, expected)) a = Element(id=Id('a')) called = False class f: def __init__(self): self.called = False def __call__(self): self.called = True f = f() a.notify('foo', f) a.foo = 10 T(f.called)
def testElementIdAttr(self): """Auto-magical attribute lookup from sub-element Id's""" a = Element(id=Id('a')) translate(a,V(1,1)) foo = Element(id=Id('foo')) translate(foo,V(2,1)) bar = Element(id=Id('bar')) translate(bar,V(1,2)) a.add(foo) a.add(bar) self.assert_(a.foo.id == Id('a/foo')) self.assert_(repr(centerof(a.foo)) == repr(V(3,2))) self.assert_(a.bar.id == Id('a/bar')) self.assert_(repr(centerof(a.bar)) == repr(V(2,3))) self.assertRaises(AttributeError,lambda: a.foobar) foo.foo = 'foo' self.assert_(a.foo.foo is foo.foo) a.foo.bar = 'bar' self.assert_(a.foo.bar is foo.bar)