def testEmptyGraph(self): graph1 = dgpy.Graph() graph1.model = dgpy.PULL data = graph1.serialize() graph2 = dgpy.Graph.fromData(data) self.assertEqual(graph1.model, graph2.model) self.assertEqual(len(graph1.nodes), len(graph2.nodes))
def testGetter(self): graph = dgpy.Graph() graph.addNode("node1", AddNode) self.assertIsNotNone(graph.get("node1.value1")) self.assertIsNotNone(graph.get("node1.value2")) self.assertIsNotNone(graph.get("node1.result")) self.assertIsNotNone(graph.get("node1")) self.assertIsNone(graph.get("foo"))
def testOrphanNodes(self): graph1 = dgpy.Graph() graph1.model = dgpy.PULL graph1.addNode("testingVoidNode", dgpy.VoidNode) graph1.addNode("testingAddNode", AddNode, value1=2, value2=3) data = graph1.serialize() graph2 = dgpy.Graph.fromData(data) self.assertDictEqual(data, graph2.serialize())
def testSingleNodeEvaluation(self): graph = dgpy.Graph() graph.model = self.model node1 = graph.addNode("node1", AddNode) node1.getInputPort("value1").value = 2 node1.getInputPort("value2").value = 3 self.assertEqual(node1.getOutputPort("result").value, 2+3) return graph
def testModelIsolation(self): graph = dgpy.Graph() graph.model = None node1 = graph.addNode("node1", AddNode) node1.getInputPort("value1").value = 2 node1.getInputPort("value2").value = 3 self.assertIsNone(node1.getOutputPort("result").value) return graph
def testNodeConnections(self): graph = dgpy.Graph() graph.model = self.model node1 = graph.addNode("node1", AddNode) node1.getInputPort("value1").value = 2 node1.getInputPort("value2").value = 3 node2 = graph.addNode("node2", AddNode, value1=5) node2.getInputPort("value2").connect(node1.getOutputPort("result")) self.assertEqual(node2.getOutputPort("result").value, 5 + 5) return graph
def testDisconnect(self): graph = dgpy.Graph() node1 = graph.addNode("node1", AddNode) node1.getInputPort("value1").value = 2 node1.getInputPort("value2").value = 3 node2 = graph.addNode("node2", AddNode, value1=5) node2.getInputPort("value2").connect(node1.getOutputPort("result")) self.assertTrue(node1.getOutputPort("result").isConnected) self.assertTrue(node2.getInputPort("value2").isConnected) node2.getInputPort("value2").disconnect() self.assertFalse(node1.getOutputPort("result").isConnected) self.assertFalse(node2.getInputPort("value2").isConnected)
def testConnectedNodes(self): graph = dgpy.Graph() graph.model = dgpy.PULL node1 = graph.addNode("node1", AddNode) node1.getInputPort("value1").value = 2 node1.getInputPort("value2").value = 3 node2 = graph.addNode("node2", AddNode, value1=5) node2.getInputPort("value2").connect(node1.getOutputPort("result")) node3 = graph.addNode("node3", AddNode, value1=8) node3.getInputPort("value2").connect(node2.getOutputPort("result")) graph.addNode("testingVoidNode", dgpy.VoidNode) data = graph.serialize() graph2 = dgpy.Graph.fromData(data) self.assertTrue(graph2.get("node2.value2").isConnected) self.assertTrue(graph2.get("node3.value2").isConnected)
def testAddRemoveNodes(self): graph = dgpy.Graph() node1 = graph.addNode("node1", dgpy.VoidNode) self.assertEqual(len(graph.nodes), 1) graph.removeNode(node1) self.assertEqual(len(graph.nodes), 0)