def testListAttributes(self): """ This method tests :meth:`foundations.dag.AbstractNode.listAttributes` method. """ nodeA = AbstractNode("MyNodeA") self.assertListEqual(nodeA.listAttributes(), []) nodeB = AbstractNode("MyNodeB", attributeA=Attribute(), attributeB=Attribute()) self.assertListEqual(sorted(nodeB.listAttributes()), ["attributeA", "attributeB"])
def testHash(self): """ This method tests :class:`foundations.dag.AbstractNode` class hash consistency. """ nodeA = AbstractNode("MyNodeA") self.assertEqual(nodeA.identity, nodeA.__hash__()) nodeB = AbstractNode("MyNodeB") self.assertEqual(nodeB.identity, nodeB.__hash__())
def testGetAttributes(self): """ This method tests :meth:`foundations.dag.AbstractNode.getAttributes` method. """ attributes = {"attributeA" : Attribute(), "attributeB" : Attribute()} nodeA = AbstractNode("MyNodeA", **attributes) for attribute in attributes.itervalues(): self.assertIn(attribute, nodeA.getAttributes())
def testGetNodeByIdentity(self): """ This method tests :meth:`foundations.dag.AbstractNode.getNodeByIdentity` method. """ nodeA = AbstractNode() self.assertIsInstance(AbstractNode.getNodeByIdentity(nodeA.identity), AbstractNode) nodeB = AbstractNode() self.assertIsInstance(AbstractNode.getNodeByIdentity(nodeB.identity), AbstractNode) self.assertEqual(AbstractNode.getNodeByIdentity(nodeB.identity), nodeB)
def testAddAttribute(self): """ This method tests :meth:`foundations.dag.AbstractNode.addAttribute` method. """ attributes = {"attributeA" : Attribute(), "attributeB" : Attribute()} nodeA = AbstractNode("MyNodeA") for attribute, value in attributes.iteritems(): self.assertTrue(nodeA.addAttribute(attribute, value)) self.assertTrue(nodeA.attributeExists(attribute))
def testHasAttribute(self): """ This method tests :meth:`foundations.dag.AbstractNode.attributeExists` method. """ attributes = {"attributeA" : Attribute(), "attributeB" : Attribute()} nodeA = AbstractNode("MyNodeA", **attributes) for attribute in attributes: self.assertTrue(nodeA.attributeExists(attribute)) nodeB = AbstractNode("MyNodeB", nonAttribute="Non Attribute") self.assertFalse(nodeB.attributeExists("nonAttribute"))