00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 PKG = 'turtlebot_app_manager'
00034 import roslib; roslib.load_manifest(PKG)
00035
00036 import os
00037 import sys
00038 import unittest
00039
00040 import rospkg
00041 import rosunit
00042
00043 def touch(filename):
00044 os.utime(filename, None)
00045
00046 class AppListTest(unittest.TestCase):
00047
00048 def test_AppList(self):
00049 import app_manager
00050 rospack = rospkg.RosPack()
00051 path = rospack.get_path(PKG)
00052 test_dir = os.path.join(path, 'test')
00053
00054 app_list = turtlebot_app_manager.AppList([os.path.join(test_dir, 'applist0')])
00055 self.assertEquals([], app_list.get_app_list())
00056
00057 filename = os.path.join(test_dir, 'applist1')
00058 app_list = turtlebot_app_manager.AppList([filename])
00059 al = app_list.get_app_list()
00060 self.assertEquals([], app_list.invalid_installed_files)
00061
00062 self.assertEquals('Android Joystick', al[0].display_name )
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 filename = os.path.join(test_dir, 'applistbad')
00073 app_list = turtlebot_app_manager.AppList([filename])
00074 al = app_list.get_app_list()
00075 self.assertEquals([], al)
00076 self.assertEquals(2, len(app_list.invalid_installed_files))
00077
00078 def test_get_default_applist_directory(self):
00079 import turtlebot_app_manager.app_list
00080 self.assertEquals('/etc/robot/apps', turtlebot_app_manager.app_list.get_default_applist_directory())
00081
00082 def test_InstalledFile(self):
00083 from turtlebot_app_manager import InvalidAppException
00084 from turtlebot_app_manager.app import find_resource
00085 from turtlebot_app_manager.app_list import InstalledFile
00086
00087 filename = find_resource('turtlebot_app_manager/apps1.installed')
00088 inf = InstalledFile(filename)
00089 self.failIf(inf._file_mtime is None)
00090 self.assertEquals(filename, inf.filename)
00091 self.assertEquals(1, len(inf.available_apps))
00092 self.assertEquals('Android Joystick', inf.available_apps[0].display_name)
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 for bad in ['turtlebot_app_manager/bad.installed', 'turtlebot_app_manager/bad2.installed']:
00103 filename = find_resource(bad)
00104 try:
00105 inf = InstalledFile(filename)
00106 self.fail("should have thrown")
00107 except InvalidAppException: pass
00108
00109 def test_dict_to_KeyValue(self):
00110 from turtlebot_app_manager.msg import KeyValue
00111 from turtlebot_app_manager.app_list import dict_to_KeyValue
00112
00113 v = dict_to_KeyValue({})
00114 self.assertEquals([], v)
00115
00116 v = dict_to_KeyValue({'a': 'b'})
00117 self.assertEquals([KeyValue('a', 'b')], v)
00118
00119 v = dict_to_KeyValue({'a': 'b', 'c': 'd'})
00120 for ve in [KeyValue('a', 'b'), KeyValue('c', 'd')]:
00121 self.assert_(ve in v)
00122
00123
00124 v = dict_to_KeyValue({'a': 1})
00125 self.assertEquals([KeyValue('a', '1')], v)
00126
00127 def test_AppDefinition_to_App(self):
00128 from turtlebot_app_manager.msg import App, ClientApp, KeyValue
00129 from turtlebot_app_manager.app import AppDefinition, Client
00130 from turtlebot_app_manager.app_list import AppDefinition_to_App, dict_to_KeyValue
00131
00132 ad = AppDefinition(name="appname", display_name="An App",
00133 description="Does something", platform="fakebot",
00134 launch="file.launch", interface="file.interface", clients=[])
00135 a = AppDefinition_to_App(ad)
00136 self.assertEquals(a.name, 'appname')
00137 self.assertEquals(a.display_name, 'An App')
00138 self.assertEquals([], a.client_apps)
00139
00140 client1 = Client('android',
00141 {'manager1': 'data1'},
00142 {'app1': 'data1'})
00143 ca = ClientApp('android', [KeyValue('manager1', 'data1')], [KeyValue('app1', 'data1')])
00144 ad = AppDefinition(name="appname", display_name="An App",
00145 description="Does something", platform="fakebot",
00146 launch="file.launch", interface="file.interface", clients=[client1])
00147 a = AppDefinition_to_App(ad)
00148 self.assertEquals([ca], a.client_apps)
00149
00150 client1 = Client('android',
00151 {'manager1': 'data1', 'manager2': 'data2'},
00152 {'app1': 'data1', 'app2': 'data2'})
00153 ca = ClientApp('android', dict_to_KeyValue(client1.manager_data), dict_to_KeyValue(client1.app_data))
00154 ad = AppDefinition(name="appname", display_name="An App",
00155 description="Does something", platform="fakebot",
00156 launch="file.launch", interface="file.interface", clients=[client1])
00157 a = AppDefinition_to_App(ad)
00158 self.assertEquals([ca], a.client_apps)
00159
00160 client2 = Client('web', {},
00161 {'app2': 'data2', 'app2b': 'data2b'})
00162 ca2 = ClientApp('web', [], dict_to_KeyValue(client2.app_data))
00163 ad = AppDefinition(name="appname", display_name="An App",
00164 description="Does something", platform="fakebot",
00165 launch="file.launch", interface="file.interface", clients=[client1, client2])
00166 a = AppDefinition_to_App(ad)
00167 self.assertEquals([ca, ca2], a.client_apps)
00168
00169
00170 if __name__ == '__main__':
00171 rosunit.unitrun(PKG, 'test_app_list', AppListTest, coverage_packages=['turtlebot_app_manager.app_list'])
00172