def __init__(self, *args, **argd): """You want to overide this method locally. You MUST remember to call the superconstructor for things to work however. The way you do this is: super(YourClass,self).__init__() """ super(component, self).__init__() self.__dict__.update(argd) self.inboxes = dict() self.outboxes = dict() # Create boxes for inboxes/outboxes for boxname in self.Inboxes: self.inboxes[boxname] = makeInbox(notify=self.unpause) for boxname in self.Outboxes: self.outboxes[boxname] = makeOutbox(notify=self.unpause) self.children = [] self._callOnCloseDown = [] self.postoffice = postoffice("component :" + self.name) if TraceAllSends: self._o_send = self.send self.send = self._debug_send if TraceAllRecvs: self._o_recv = self.recv self.recv = self._debug_recv
def test_linkderegisters(self): p = postoffice() c1 = DummyComponent() c2 = DummyComponent() l1 = p.link( (c1,"outbox"), (c2,"inbox") ) l2 = p.link( (c1,"signal"), (c2,"control") ) p.unlink(thelinkage=l1) self.assert_(l1 not in p.linkages and l2 in p.linkages, "linkage deregisters when you unlink specifying a linkage")
def test_linkregistered(self): p = postoffice() c1 = DummyComponent() c2 = DummyComponent() l1 = p.link( (c1,"outbox"), (c2,"inbox") ) self.assert_(l1 in p.linkages, "postoffice registers with itself any linkages you ask it to make") l2 = p.link( (c1,"signal"), (c2,"control") ) self.assert_(l1 in p.linkages and l2 in p.linkages)
def test_BoxAlreadyLinkedToDestinationException(self): p=postoffice() c1=component() c2=component() c3=component() l1 = p.link( (c1,"outbox"), (c2,"inbox") ) try: l2 = p.link( (c1,"outbox"), (c3,"inbox") ) self.fail("Should have raised BoxAreadyLinkedException when link was made from already linked c1-outbox") except BoxAlreadyLinkedToDestination: pass p.unlink(thelinkage=l1) l2 = p.link( (c1,"outbox"), (c3,"inbox") )
def test_componentlinksderegisters(self): p = postoffice() c1 = DummyComponent() c2 = DummyComponent() c3 = DummyComponent() l1 = p.link( (c1,"outbox"), (c2,"inbox") ) l2 = p.link( (c1,"signal"), (c2,"control") ) l3 = p.link( (c2,"outbox"), (c3,"inbox") ) l4 = p.link( (c2,"signal"), (c3,"control") ) p.unlink(thecomponent=c1) self.assert_(l1 not in p.linkages and l2 not in p.linkages and l3 in p.linkages and l4 in p.linkages, "linkages deregister when you unlink specifying a component")
def test_linkestablishes(self): p = postoffice() c1 = DummyComponent() c2 = DummyComponent() p.link( (c1,"outbox"), (c2,"inbox") ) self.assert_(c2.inboxes['inbox'].sourcesadded == [c1.outboxes['outbox']]) self.assert_(c2.inboxes['inbox'].sourcesremoved == []) self.assert_(c2.inboxes['control'].sourcesadded == []) self.assert_(c2.inboxes['control'].sourcesremoved == []) self.assert_(c2.outboxes['outbox'].sourcesadded == []) self.assert_(c2.outboxes['outbox'].sourcesremoved == []) self.assert_(c2.outboxes['signal'].sourcesadded == []) self.assert_(c2.outboxes['signal'].sourcesremoved == []) self.assert_(c1.inboxes['inbox'].sourcesadded == []) self.assert_(c1.inboxes['inbox'].sourcesremoved == []) self.assert_(c1.inboxes['control'].sourcesadded == []) self.assert_(c1.inboxes['control'].sourcesremoved == []) self.assert_(c1.outboxes['outbox'].sourcesadded == []) self.assert_(c1.outboxes['outbox'].sourcesremoved == []) self.assert_(c1.outboxes['signal'].sourcesadded == []) self.assert_(c1.outboxes['signal'].sourcesremoved == [])
def test_linkdisengages_outboxoutboxpassthrough(self): p = postoffice() c1 = DummyComponent() c2 = DummyComponent() l1 = p.link( (c1,"outbox"), (c2,"outbox"), passthrough=2 ) p.unlink(thelinkage=l1) self.assert_(c2.inboxes['inbox'].sourcesadded == []) self.assert_(c2.inboxes['inbox'].sourcesremoved == []) self.assert_(c2.inboxes['control'].sourcesadded == []) self.assert_(c2.inboxes['control'].sourcesremoved == []) self.assert_(c2.outboxes['outbox'].sourcesadded == [c1.outboxes['outbox']]) self.assert_(c2.outboxes['outbox'].sourcesremoved == [c1.outboxes['outbox']]) self.assert_(c2.outboxes['signal'].sourcesadded == []) self.assert_(c2.outboxes['signal'].sourcesremoved == []) self.assert_(c1.inboxes['inbox'].sourcesadded == []) self.assert_(c1.inboxes['inbox'].sourcesremoved == []) self.assert_(c1.inboxes['control'].sourcesadded == []) self.assert_(c1.inboxes['control'].sourcesremoved == []) self.assert_(c1.outboxes['outbox'].sourcesadded == []) self.assert_(c1.outboxes['outbox'].sourcesremoved == []) self.assert_(c1.outboxes['signal'].sourcesadded == []) self.assert_(c1.outboxes['signal'].sourcesremoved == [])
def test__str__checksStringFormatStrict(self): '__str__ - Checks the formatted string is of the correct format.' p = postoffice() self.failUnless(self.strtest(p)) p2 = postoffice(debugname="flurble") self.failUnless(self.strtest(p2))
def test___init__SmokeTest_DebugnameArgument(self): """postoffice can be instantiated with a debugger.""" testname="[fwibble]" p = postoffice(debugname=testname) self.assert_(testname in p.debugname, "can specify a debugname")
def test___init__SmokeTest_NoArguments(self): """postoffice can be instantiated with no arguments. Defaults to no debugger or registered linkages.""" p = postoffice() self.assert_(p.debugname=="", "defaults to have no debugname") self.assert_(len(p.linkages)==0, "initializes with no linkages registered")