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