diff --git a/python/src/ipaaca.py b/python/src/ipaaca.py index 834fed8592b77569ab81c92aaca77e7ee6c515c1..38f0d5a73eff40f5f6b691ee19ff24b06db417d5 100755 --- a/python/src/ipaaca.py +++ b/python/src/ipaaca.py @@ -215,7 +215,7 @@ class IUInterface(object): #{{{ def _replace_links(self, links): '''Just wipe and replace our links set, do not send an update here''' '''Note: Also used for remotely enforced links updates.''' - self._links = {} + self._links = collections.defaultdict(set) for type in links.keys(): self._links[type] |= set(links[type]) def add_links(self, type, targets, writer_name=None): @@ -239,7 +239,7 @@ class IUInterface(object): #{{{ '''Attempt to set (replace) links if the conditions are met and send an update message. Then call the local setter.''' self._modify_links(links=self, is_delta=False, new_links=links, links_to_remove={}, writer_name=writer_name) - self._replace_links( links=new_links ) + self._replace_links( links=links ) def get_links(self, type): return set(self._links[type]) def get_all_links(self): diff --git a/python/src/testipaaca.py b/python/src/testipaaca.py new file mode 100755 index 0000000000000000000000000000000000000000..4156281f6162002ef2a30ed2a6b03e3597fa491b --- /dev/null +++ b/python/src/testipaaca.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +import time +import ipaaca +import sys + +import unittest + +class IpaacaLinksTestCase(unittest.TestCase): + def setUp(self): + self.ib = ipaaca.InputBuffer('TestIn', ['sensorcategory']) + self.ob = ipaaca.OutputBuffer('TestOut') + self.sensor_iu = ipaaca.IU('sensorcategory') + self.sensor_iu.payload = {'data': 'sensordata'} + self.ob.add(self.sensor_iu) + def tearDown(self): + pass + def testSetLink(self): + time.sleep(0.1) + self.decision_iu = ipaaca.IU('decisioncategory') + self.decision_iu.payload = {'data':'decision'} + self.decision_iu.set_links( { 'grin': [self.sensor_iu.uid] } ) + self.ob.add(self.decision_iu) + time.sleep(0.1) + grinlinks = self.decision_iu.get_links('grin') + self.assertIn(self.sensor_iu.uid, grinlinks) + self.assertEqual(len(grinlinks), 1) + +if __name__ == '__main__': + unittest.main() +