def test_instance_getattr(self): data = ''' class WebAppObject(object): def __init__(self, application): self.appli = application self.appli += 2 del self.appli ''' astng = abuilder.string_build(data, __name__, __file__) inst = Instance(astng['WebAppObject']) # test del statement not returned by getattr self.assertEquals(len(inst.getattr('appli')), 2)
def interfaces(self, herited=True, handler_func=_iface_hdlr): """return an iterator on interfaces implemented by the given class node """ # FIXME: what if __implements__ = (MyIFace, MyParent.__implements__)... try: implements = Instance(self).getattr('__implements__')[0] except NotFoundError: return if not herited and not implements.frame() is self: return found = set() for iface in unpack_infer(implements): if iface is YES: continue if not iface in found and handler_func(iface): found.add(iface) yield iface if not found: raise InferenceError()
def test_instance_getattr_with_class_attr(self): data = ''' class Parent: aa = 1 cc = 1 class Klass(Parent): aa = 0 bb = 0 def incr(self, val): self.cc = self.aa if val > self.aa: val = self.aa if val < self.bb: val = self.bb self.aa += val ''' astng = abuilder.string_build(data, __name__, __file__) inst = Instance(astng['Klass']) self.assertEquals(len(inst.getattr('aa')), 3, inst.getattr('aa')) self.assertEquals(len(inst.getattr('bb')), 1, inst.getattr('bb')) self.assertEquals(len(inst.getattr('cc')), 2, inst.getattr('cc'))