test_app_list.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Software License Agreement (BSD License)
00003 #
00004 # Copyright (c) 2011, Willow Garage, Inc.
00005 # All rights reserved.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions
00009 # are met:
00010 #
00011 #  * Redistributions of source code must retain the above copyright
00012 #    notice, this list of conditions and the following disclaimer.
00013 #  * Redistributions in binary form must reproduce the above
00014 #    copyright notice, this list of conditions and the following
00015 #    disclaimer in the documentation and/or other materials provided
00016 #    with the distribution.
00017 #  * Neither the name of Willow Garage, Inc. nor the names of its
00018 #    contributors may be used to endorse or promote products derived
00019 #    from this software without specific prior written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
00033 PKG = '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 = 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 = app_manager.AppList([filename])
00059         al = app_list.get_app_list()
00060         self.assertEquals([], app_list.invalid_installed_files)
00061         #self.assertEquals(1, len(al), al.invalid_installed_files)
00062         self.assertEquals('Android Joystick', al[0].display_name )
00063       
00064         #Had to be commented out, see app_list.py
00065         #mtime = app_list._applist_directory_mtime
00066         #app_list.update()
00067         #self.assertEquals(mtime, app_list._applist_directory_mtime)
00068         #touch(filename)
00069         #app_list.update()
00070         #self.assertNotEquals(mtime, app_list._applist_directory_mtime)
00071 
00072         filename = os.path.join(test_dir, 'applistbad')
00073         app_list = 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 app_manager.app_list
00080         self.assertEquals('/etc/robot/apps', app_manager.app_list.get_default_applist_directory())
00081       
00082     def test_InstalledFile(self):
00083         from app_manager import InvalidAppException
00084         from app_manager.app import find_resource
00085         from app_manager.app_list import InstalledFile
00086 
00087         filename = find_resource('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         #Had to be commented out, see app_list.py
00095         #mtime = inf._file_mtime
00096         #inf.update()
00097         #self.assertEquals(mtime, inf._file_mtime)
00098         #touch(filename)
00099         #inf.update()
00100         #self.assertNotEquals(mtime, inf._file_mtime)      
00101       
00102         for bad in ['app_manager/bad.installed', '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 app_manager.msg import KeyValue
00111         from 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         # make sure that types convert
00124         v = dict_to_KeyValue({'a': 1})
00125         self.assertEquals([KeyValue('a', '1')], v)
00126 
00127     def test_AppDefinition_to_App(self):
00128         from app_manager.msg import App, ClientApp, KeyValue
00129         from app_manager.app import AppDefinition, Client
00130         from 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=['app_manager.app_list'])
00172 


app_manager
Author(s): Jeremy Leibs, Ken Conley
autogenerated on Sat Jun 8 2019 20:23:45