Skip to content
Snippets Groups Projects
Commit 4e0ac1d3 authored by Ramin Yaghoubzadeh's avatar Ramin Yaghoubzadeh
Browse files

Added first test case. Found approx 10 bugs.

parent 667acc1d
No related branches found
No related tags found
No related merge requests found
......@@ -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):
......
#!/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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment