def test_dblocks(self): dpl_1 = DPlugin() dpl_1.id = 1 dbl_1 = DBlock('Block1') dbl_1.dplugin_id = dpl_1.id dbl_2 = DBlock('Block2') dbl_2.dplugin_id = dpl_1.id #check: add Parameter self.assertTrue(dpl_1.add_dblock(dbl_1)) self.assertTrue(dpl_1.add_dblock(dbl_2)) self.assertFalse(dpl_1.add_dblock(dbl_1)) self.assertFalse(dpl_1.add_dblock(dbl_2)) #Check: count of parameters self.assertEqual(len(dpl_1.get_dblocks().keys()), 2) #Check: rm parameter self.assertTrue(dpl_1.rm_dblock(dbl_1)) self.assertEqual(len(dpl_1.get_dblocks().keys()), 1) self.assertTrue(dpl_1.rm_dblock(dbl_2)) self.assertEqual(len(dpl_1.get_dblocks().keys()), 0)
def test_parameters(self): dpl_1 = DPlugin() dpl_1.id = 1 dp_1 = DParameter(1, 'parameter1') dp_1.id = 2 dp_2 = DParameter(2, 'parameter2') dp_2.id = 3 #check: add Parameter self.assertTrue(dpl_1.add_parameter(dp_1)) self.assertTrue(dpl_1.add_parameter(dp_2)) self.assertFalse(dpl_1.add_parameter(dp_1)) self.assertFalse(dpl_1.add_parameter(dp_2)) #Check: count of parameters self.assertEqual(len(dpl_1.get_parameters().keys()), 2) #Check: rm parameter self.assertTrue(dpl_1.rm_parameter(dp_1)) self.assertEqual(len(dpl_1.get_parameters().keys()), 1) self.assertTrue(dpl_1.rm_parameter(dp_2)) self.assertEqual(len(dpl_1.get_parameters().keys()), 0)
def test_add_susbcribers(self): dbl = DBlock('DBlock1') dbl.id = 1 dpl_1 = DPlugin() dpl_1.id = 2 dpl_2 = DPlugin() dpl_2.id = 3 self.assertTrue(dbl.add_subscribers(dpl_1)) self.assertTrue(dbl.add_subscribers(dpl_2)) self.assertEqual(len(dbl.get_subscribers()),2)
def add_plugin(self, process, pid, own_process, queue, plugin, id): """ Add plugin with necessary information. :param process: Plugin is running in this process :param pid: Process ID of the process in which the plugin is running :param queue: Event queue needed for events which should be received by this plugin :param plugin: Plugin object :param plugin_id: ID of this plugin :param id: ID for the new DPlugin :return: Returns the data object DPlugin :rtype: DPlugin """ d_pl = DPlugin() d_pl.process = process d_pl.pid = pid d_pl.queue = queue d_pl.plugin = plugin d_pl.id = id d_pl.own_process = own_process self.__DPlugins[id] = d_pl return d_pl
def test_rm_subscribers(self): dbl = DBlock('DBlock1') dbl.id = 1 dpl_1 = DPlugin() dpl_1.id = 2 dpl_2 = DPlugin() dpl_2.id = 3 dbl.add_subscribers(dpl_1) dbl.add_subscribers(dpl_2) self.assertEqual(len(dbl.get_subscribers()),2) dbl.rm_subscriber(dpl_1) self.assertEqual(len(dbl.get_subscribers()),1) dbl.rm_subscriber(dpl_2) self.assertEqual(len(dbl.get_subscribers()),0) self.assertFalse(dbl.rm_subscriber(dpl_1))
def test_add_susbcribers(self): dbl = DBlock('DBlock1') dbl.id = 1 dpl_1 = DPlugin() dpl_1.id = 2 dpl_2 = DPlugin() dpl_2.id = 3 self.assertTrue(dbl.add_subscribers(dpl_1)) self.assertTrue(dbl.add_subscribers(dpl_2)) self.assertEqual(len(dbl.get_subscribers()), 2)
def test_rm_subscribers(self): dbl = DBlock('DBlock1') dbl.id = 1 dpl_1 = DPlugin() dpl_1.id = 2 dpl_2 = DPlugin() dpl_2.id = 3 dbl.add_subscribers(dpl_1) dbl.add_subscribers(dpl_2) self.assertEqual(len(dbl.get_subscribers()), 2) dbl.rm_subscriber(dpl_1) self.assertEqual(len(dbl.get_subscribers()), 1) dbl.rm_subscriber(dpl_2) self.assertEqual(len(dbl.get_subscribers()), 0) self.assertFalse(dbl.rm_subscriber(dpl_1))
def test_subscribtions(self): dpl_1 = DPlugin() dpl_1.id = 1 dpl_2 = DPlugin() dpl_2.id = 2 dbl_1 = DBlock('DBlock1') dbl_1.id = 3 dbl_1.dplugin_id = dpl_2.id dbl_2 = DBlock('DBlock2') dbl_2.id = 4 dbl_2.dplugin_id = dpl_2.id dpl_2.add_dblock(dbl_1) dpl_2.add_dblock(dbl_2) #Check: subscribe DBlocks self.assertTrue(dpl_1.subscribe(dbl_1)) self.assertTrue(dpl_1.subscribe(dbl_2)) self.assertFalse(dpl_1.subscribe(dbl_1)) self.assertFalse(dpl_1.subscribe(dbl_2)) #Check: count of subscribtions self.assertEqual(len(dpl_1.get_subscribtions()[dpl_2.id].keys()), 2) #Check: unsubscribe DBlock self.assertTrue(dpl_1.unsubscribe(dbl_1)) #Check: count of subscribtions self.assertEqual(len(dpl_1.get_subscribtions().keys()), 1) #Check: count of subscribtions self.assertEqual(len(dpl_1.get_subscribtions()[dpl_2.id].keys()), 1)