def test_write_duplicate(self): x1 = np.arange(12).reshape(2, 6) messagedb.Singletone().Write(x1, "test") x2 = np.arange(12).reshape(3, 4) messagedb.Singletone().Write(x2, "test") result = messagedb.Singletone().Read("test") self.assertEqual(x2.shape, result.shape)
def test_clean_once(self): messagedb.Singletone().Write(np.ones(1), 'test') result = messagedb.Singletone().Read("test") self.assertEqual(1, result.size) messagedb.Singletone().Clean() result = messagedb.Singletone().Read("test") self.assertIsNone(result)
def test_list_all_actives(self): x1 = np.arange(12).reshape(2, 6) x2 = np.arange(12).reshape(3, 4) messagedb.Singletone().Write(x1, "test1") messagedb.Singletone().Write(x2, "test2") messagedb.Singletone().Read("test1") active = messagedb.Singletone().AllActiveNames() totalactive = len(active) self.assertEqual(1, totalactive)
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 __loop(self): """ The node thread looper""" self.runStooped = False while self.isRunning: name = self.Get("Name") if messagedb.Singletone().IsActive(name): payload = messagedb.Singletone().Read(name) result = self.Run(payload) [self.Post(c, result) for c in self.Get('Connect')] self.runStooped = True
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 Post(self, connection, payload: object): """ Post a message to a specific connection :connection: name of the downstream node :payload: the data payload that will be posted """ messagedb.Singletone().Write(payload, connection)
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_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_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_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_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 Add(self, node, name): """ Add a a node to a graph """ if self.Exist(name): raise Exception('Pre-existing node') self.nodes.append(node) messagedb.Singletone().Write(np.zeros(1), name)
def test(self): self.assertIsNotNone(messagedb.Singletone().db)
def test_image(self): pic = img.open("res/download.jpg") messagedb.Singletone().WriteImage(pic, "test") result = messagedb.Singletone().ReadImage("test") self.assertEqual(pic.size, result.size)
def test_read_np(self): x = np.arange(12).reshape(2, 6) messagedb.Singletone().Write(x, "test") result = messagedb.Singletone().Read("test") self.assertEqual(x.shape, result.shape)
def test_write_np(self): x = np.arange(12).reshape(2, 6) messagedb.Singletone().Write(x, "test") self.assertIsNotNone(messagedb.Singletone().db)