def testName(self): """ Tests :class:`foundations.nodes.AbstractNode` class name resolving consistency. """ nodeA = AbstractNode("MyNodeA") self.assertEqual(nodeA.name, "MyNodeA") nodeB = AbstractNode() self.assertEqual(nodeB.name, "Abstract{0}".format(nodeB.identity))
def testGetAttributes(self): """ Tests :meth:`foundations.nodes.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): """ Tests :meth:`foundations.nodes.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): """ Tests :meth:`foundations.nodes.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 testFamily(self): """ Tests :class:`foundations.nodes.AbstractNode` class family property. """ nodeA = AbstractNode("MyNode") self.assertEqual(nodeA.family, "Abstract")
def testAbstractNodePickle(self): """ Tests :class:`foundations.nodes.AbstractNode` class pickling. """ nodeA = AbstractNode("MyNodeA", attributeA=Attribute(), attributeB=Attribute()) data = pickle.dumps(nodeA) data = pickle.loads(data) self.assertEqual(nodeA, data) data = pickle.dumps(nodeA, pickle.HIGHEST_PROTOCOL) data = pickle.loads(data) self.assertEqual(nodeA, data)
def testListAttributes(self): """ Tests :meth:`foundations.nodes.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 testHasAttribute(self): """ Tests :meth:`foundations.nodes.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"))