def test_rm_dplugin(self): #Create dplugins d_pl_1 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) d_pl_2 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) #Create dblocks d_bl_1 = DBlock('Block_1') d_bl_2 = DBlock('Block_2') #assign dblocks to DPlugin d_pl_1 d_pl_1.add_dblock(d_bl_1) d_pl_1.add_dblock(d_bl_2) #create subscribtions self.dcore.subscribe(d_pl_2.id, d_pl_1.id, d_bl_1.name) self.dcore.subscribe(d_pl_2.id, d_pl_1.id, d_bl_2.name) self.assertEqual(len(d_pl_2.get_subscribtions()[d_pl_1.id]), 2) self.assertEqual(len(d_bl_1.get_subscribers()), 1) self.assertEqual(len(d_bl_2.get_subscribers()), 1) self.dcore.rm_dplugin(d_pl_1.id) #Check if DPlugin d_pl_1 is missing self.assertFalse(self.dcore.get_dplugin_by_id(d_pl_1.id)) #Check if all subscribtions were canceled self.assertEqual(len(d_pl_2.get_subscribtions().keys()), 0) self.assertEqual(len(d_bl_1.get_subscribers()), 0) self.assertEqual(len(d_bl_2.get_subscribers()), 0) pass
def test_rm_all_subscribers(self): #Create dplugins d_pl_1 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) d_pl_2 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) d_pl_3 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) #Create dblocks d_bl_1 = DBlock('Block_1') d_bl_2 = DBlock('Block_2') #assign dblocks to DPlugin d_pl_1 d_pl_1.add_dblock(d_bl_1) d_pl_1.add_dblock(d_bl_2) self.assertTrue(self.dcore.subscribe(d_pl_2.id, d_pl_1.id, d_bl_1.name)) self.assertTrue(self.dcore.subscribe(d_pl_2.id, d_pl_1.id, d_bl_2.name)) self.assertTrue(self.dcore.subscribe(d_pl_3.id, d_pl_1.id, d_bl_1.name)) self.assertTrue(self.dcore.subscribe(d_pl_3.id, d_pl_1.id, d_bl_2.name)) self.assertEqual(len(d_bl_1.get_subscribers()), 2) self.assertEqual(len(d_bl_2.get_subscribers()), 2) self.dcore.rm_all_subscribers(d_pl_1.id) self.assertEqual(len(d_bl_1.get_subscribers()), 0) self.assertEqual(len(d_bl_2.get_subscribers()), 0) pass
def test_unsubscribe_all(self): #Create dplugins d_pl_1 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) d_pl_2 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) d_pl_3 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) #Create dblocks d_bl_1 = DBlock('Block_1') d_bl_2 = DBlock('Block_2') #assign dblocks to DPlugin d_pl_1 d_pl_1.add_dblock(d_bl_1) d_pl_1.add_dblock(d_bl_2) self.assertTrue(self.dcore.subscribe(d_pl_2.id, d_pl_1.id, d_bl_1.name)) self.assertTrue(self.dcore.subscribe(d_pl_3.id, d_pl_1.id, d_bl_1.name)) self.assertTrue(self.dcore.subscribe(d_pl_2.id, d_pl_1.id, d_bl_2.name)) print(d_bl_1.get_subscribers()) self.assertEqual(len(d_pl_2.get_subscribtions()[d_pl_1.id].keys()), 2) self.dcore.unsubscribe_all(d_pl_2.id) self.assertNotIn(d_pl_1.id, d_pl_2.get_subscribtions()) print(d_bl_1.get_subscribers()) self.assertTrue(len(d_bl_1.get_subscribers())==1) self.assertTrue(len(d_bl_2.get_subscribers())==0) pass
def test_rm_dplugin(self): # Create dplugins d_pl_1 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) d_pl_2 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) # Create dblocks d_bl_1 = DBlock("Block_1") d_bl_2 = DBlock("Block_2") # assign dblocks to DPlugin d_pl_1 d_pl_1.add_dblock(d_bl_1) d_pl_1.add_dblock(d_bl_2) # create subscribtions self.dcore.subscribe(d_pl_2.id, d_pl_1.id, d_bl_1.name) self.dcore.subscribe(d_pl_2.id, d_pl_1.id, d_bl_2.name) self.assertEqual(len(d_pl_2.get_subscribtions()[d_pl_1.id]), 2) self.assertEqual(len(d_bl_1.get_subscribers()), 1) self.assertEqual(len(d_bl_2.get_subscribers()), 1) self.dcore.rm_dplugin(d_pl_1.id) # Check if DPlugin d_pl_1 is missing self.assertFalse(self.dcore.get_dplugin_by_id(d_pl_1.id)) # Check if all subscribtions were canceled self.assertEqual(len(d_pl_2.get_subscribtions().keys()), 0) self.assertEqual(len(d_bl_1.get_subscribers()), 0) self.assertEqual(len(d_bl_2.get_subscribers()), 0) pass
def test_rm_all_subscribers(self): # Create dplugins d_pl_1 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) d_pl_2 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) d_pl_3 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) # Create dblocks d_bl_1 = DBlock("Block_1") d_bl_2 = DBlock("Block_2") # assign dblocks to DPlugin d_pl_1 d_pl_1.add_dblock(d_bl_1) d_pl_1.add_dblock(d_bl_2) self.assertTrue(self.dcore.subscribe(d_pl_2.id, d_pl_1.id, d_bl_1.name)) self.assertTrue(self.dcore.subscribe(d_pl_2.id, d_pl_1.id, d_bl_2.name)) self.assertTrue(self.dcore.subscribe(d_pl_3.id, d_pl_1.id, d_bl_1.name)) self.assertTrue(self.dcore.subscribe(d_pl_3.id, d_pl_1.id, d_bl_2.name)) self.assertEqual(len(d_bl_1.get_subscribers()), 2) self.assertEqual(len(d_bl_2.get_subscribers()), 2) self.dcore.rm_all_subscribers(d_pl_1.id) self.assertEqual(len(d_bl_1.get_subscribers()), 0) self.assertEqual(len(d_bl_2.get_subscribers()), 0) pass
def test_unsubscribe_all(self): # Create dplugins d_pl_1 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) d_pl_2 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) d_pl_3 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) # Create dblocks d_bl_1 = DBlock("Block_1") d_bl_2 = DBlock("Block_2") # assign dblocks to DPlugin d_pl_1 d_pl_1.add_dblock(d_bl_1) d_pl_1.add_dblock(d_bl_2) self.assertTrue(self.dcore.subscribe(d_pl_2.id, d_pl_1.id, d_bl_1.name)) self.assertTrue(self.dcore.subscribe(d_pl_3.id, d_pl_1.id, d_bl_1.name)) self.assertTrue(self.dcore.subscribe(d_pl_2.id, d_pl_1.id, d_bl_2.name)) print(d_bl_1.get_subscribers()) self.assertEqual(len(d_pl_2.get_subscribtions()[d_pl_1.id].keys()), 2) self.dcore.unsubscribe_all(d_pl_2.id) self.assertNotIn(d_pl_1.id, d_pl_2.get_subscribtions()) print(d_bl_1.get_subscribers()) self.assertTrue(len(d_bl_1.get_subscribers()) == 1) self.assertTrue(len(d_bl_2.get_subscribers()) == 0) pass
def test_unsubscribe_signals(self): #Create dplugins d_pl_1 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) d_pl_2 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) d_pl_3 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) #Create dblocks d_bl_1 = DBlock('Block1') d_bl_2 = DBlock('Block2') #assign dblocks to DPlugin d_pl_1 d_pl_1.add_dblock(d_bl_1) d_pl_1.add_dblock(d_bl_2) self.dcore.subscribe(d_pl_2.id, d_pl_1.id, d_bl_1.name) self.dcore.subscribe(d_pl_2.id, d_pl_1.id, d_bl_2.name) self.dcore.subscribe(d_pl_3.id, d_pl_1.id, d_bl_1.name) self.dcore.subscribe(d_pl_3.id, d_pl_1.id, d_bl_2.name) self.dcore.subscribe_signals(d_pl_2.id, d_pl_1.id, d_bl_1.name, [1, 2, 3]) self.dcore.subscribe_signals(d_pl_2.id, d_pl_1.id, d_bl_2.name, [6, 4, 5]) self.dcore.subscribe_signals(d_pl_3.id, d_pl_1.id, d_bl_1.name, [9]) self.dcore.subscribe_signals(d_pl_3.id, d_pl_1.id, d_bl_2.name, [17,19,18]) self.assertTrue(self.dcore.unsubscribe_signals(d_pl_2.id, d_pl_1.id, d_bl_1.name, [1, 2])) subscription = d_pl_2.get_subscribtions()[d_pl_1.id][d_bl_1.name] self.assertNotIn(1, subscription.get_signals()) self.assertNotIn(2, subscription.get_signals()) self.assertIn(3, subscription.get_signals()) self.assertEqual(len(d_bl_1.get_subscribers()), 2) self.assertTrue(self.dcore.unsubscribe_signals(d_pl_2.id, d_pl_1.id, d_bl_1.name, [3])) self.assertEqual(len(d_bl_1.get_subscribers()), 1)
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_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_unsubscribe_signals(self): # Create dplugins d_pl_1 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) d_pl_2 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) d_pl_3 = self.dcore.add_plugin(None, 1, None, None, None, self.dcore.create_id()) # Create dblocks d_bl_1 = DBlock("Block1") d_bl_2 = DBlock("Block2") # assign dblocks to DPlugin d_pl_1 d_pl_1.add_dblock(d_bl_1) d_pl_1.add_dblock(d_bl_2) self.dcore.subscribe(d_pl_2.id, d_pl_1.id, d_bl_1.name) self.dcore.subscribe(d_pl_2.id, d_pl_1.id, d_bl_2.name) self.dcore.subscribe(d_pl_3.id, d_pl_1.id, d_bl_1.name) self.dcore.subscribe(d_pl_3.id, d_pl_1.id, d_bl_2.name) self.dcore.subscribe_signals(d_pl_2.id, d_pl_1.id, d_bl_1.name, [1, 2, 3]) self.dcore.subscribe_signals(d_pl_2.id, d_pl_1.id, d_bl_2.name, [6, 4, 5]) self.dcore.subscribe_signals(d_pl_3.id, d_pl_1.id, d_bl_1.name, [9]) self.dcore.subscribe_signals(d_pl_3.id, d_pl_1.id, d_bl_2.name, [17, 19, 18]) self.assertTrue(self.dcore.unsubscribe_signals(d_pl_2.id, d_pl_1.id, d_bl_1.name, [1, 2])) subscription = d_pl_2.get_subscribtions()[d_pl_1.id][d_bl_1.name] self.assertNotIn(1, subscription.get_signals()) self.assertNotIn(2, subscription.get_signals()) self.assertIn(3, subscription.get_signals()) self.assertEqual(len(d_bl_1.get_subscribers()), 2) self.assertTrue(self.dcore.unsubscribe_signals(d_pl_2.id, d_pl_1.id, d_bl_1.name, [3])) self.assertEqual(len(d_bl_1.get_subscribers()), 1)