def test_get_const_node(self):
     logfile = "res/sample.log"
     txt_log = TextLogger(logfile)
     log = Logger(txt_log)
     node = Const(log)
     node.set("Value", 1)
     self.assertEqual(1, node.Get("Value"))
 def test_add_two_throw_execption(self):
     logfile = "res/sample.log"
     txt_log = TextLogger(logfile)
     log = Logger(txt_log)
     messagedb.Singletone().Clean()
     self.graph.Add(Const(log), "const1")
     self.graph.Add(Const(log), "const2")
     self.assertTrue(len(self.graph.nodes) == 2)
 def test_add_douplicate_throw_execption(self):
     logfile = "res/sample.log"
     txt_log = TextLogger(logfile)
     log = Logger(txt_log)
     messagedb.Singletone().Clean()
     self.graph.Add(Const(log), "const1")
     self.graph.Add(Const(log), "const1")
     self.assertRaises(Exception, 'Pre-exisiting node')
 def test_add_connection_to_node(self):
     logfile = "res/sample.log"
     txt_log = TextLogger(logfile)
     log = Logger(txt_log)
     messagedb.Singletone().Clean()
     self.graph.Add(Const(log), "const1")
     self.graph.Add(Const(log), "const2")
     self.graph.Connect("const1", "const2")
     self.assertRaises(Exception, 'Fail to connect')
    def test_add_nodes_to_parallel_graph(self):
        logfile = "res/sample.log"
        txt_log = TextLogger(logfile)
        log = Logger(txt_log)

        graph = Agent.CreateThreadedGraph()
        graph.Add(Const(log), "test")
        graph.Add(Const(log), "test2")
        self.assertRaises(Exception,
                          'Parallel graph must only contain one node')
    def test_run_two_connected_node(self):
        logfile = "res/sample.log"
        txt_log = TextLogger(logfile)
        log = Logger(txt_log)
        messagedb.Singletone().Clean()

        self.graph.Add(Const(log), "const1")
        self.graph.Add(Const(log), "const2")
        self.graph.Connect("const1", "const2")
        self.graph.Post("const1", np.ones(1) * 2)
        self.graph.Run()
        const2_payload = messagedb.Singletone().Read('const2')
        self.assertEqual(2, const2_payload[0])
 def test_get_node_with_name_or_id(self):
     logfile = "res/sample.log"
     txt_log = TextLogger(logfile)
     log = Logger(txt_log)
     messagedb.Singletone().Clean()
     self.graph.Add(Const(log), "const1")
     node = self.graph.Get("const1")
     self.assertTrue(node['Name'] == "const1")
 def test_node_post_payload(self):
     logfile = "res/sample.log"
     txt_log = TextLogger(logfile)
     log = Logger(txt_log)
     messagedb.Singletone().Clean()
     self.graph.Add(Const(log), "const1")
     self.graph.Connect('const1', 'const1')
     self.graph.Post("const1", np.ones(1))
     payload = messagedb.Singletone().Read("const1")
     self.assertEqual(1, payload)
 def test_update_node_value(self):
     logfile = "res/sample.log"
     txt_log = TextLogger(logfile)
     log = Logger(txt_log)
     messagedb.Singletone().Clean()
     self.graph.Add(Const(log), "const1")
     node = self.graph.Get("const1")
     self.graph.Update(node, 'Value', '2')
     node = self.graph.Get("const1")
     self.assertEqual('2', node["Value"])
    def test_createSimpleTesGraph(self):
        logfile = "res/sample.log"
        txt_log = TextLogger(logfile)
        log = Logger(txt_log)

        const = Const(log)
        sink = SinkNode(log)

        graph = NodeGraph()
        graph.Add(const, "const1")
        graph.Add(sink, "sink1")

        graph.Connect("const1", "sink1")
        control = controller()

        control.Start()

        self.assertEqual(1, 1)
 def test_create_const_node(self):
     logfile = "res/sample.log"
     txt_log = TextLogger(logfile)
     log = Logger(txt_log)
     node = Const(log)
     self.assertEqual("const", node.Properties["NodeType"])