Example #1
0
	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))
Example #2
0
	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())
Example #3
0
	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)
Example #4
0
	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))
Example #5
0
	def testFamily(self):
		"""
		Tests :class:`foundations.nodes.AbstractNode` class family property.
		"""

		nodeA = AbstractNode("MyNode")
		self.assertEqual(nodeA.family, "Abstract")
Example #6
0
	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)
Example #7
0
	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"])
Example #8
0
	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"))