test_app_list.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD License)
3 #
4 # Copyright (c) 2011, Willow Garage, Inc.
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following
15 # disclaimer in the documentation and/or other materials provided
16 # with the distribution.
17 # * Neither the name of Willow Garage, Inc. nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
33 PKG = 'app_manager'
34 import roslib; roslib.load_manifest(PKG)
35 
36 import os
37 import sys
38 import unittest
39 
40 import rospkg
41 import rosunit
42 
43 def touch(filename):
44  os.utime(filename, None)
45 
46 class AppListTest(unittest.TestCase):
47 
48  def test_AppList(self):
49  import app_manager
50  rospack = rospkg.RosPack()
51  path = rospack.get_path(PKG)
52  test_dir = os.path.join(path, 'test')
53 
54  app_list = app_manager.AppList([os.path.join(test_dir, 'applist0')])
55  self.assertEquals([], app_list.get_app_list())
56 
57  filename = os.path.join(test_dir, 'applist1')
58  app_list = app_manager.AppList([filename])
59  al = app_list.get_app_list()
60  self.assertEquals([], app_list.invalid_installed_files)
61  #self.assertEquals(1, len(al), al.invalid_installed_files)
62  self.assertEquals('Android Joystick', al[0].display_name )
63 
64  #Had to be commented out, see app_list.py
65  #mtime = app_list._applist_directory_mtime
66  #app_list.update()
67  #self.assertEquals(mtime, app_list._applist_directory_mtime)
68  #touch(filename)
69  #app_list.update()
70  #self.assertNotEquals(mtime, app_list._applist_directory_mtime)
71 
72  filename = os.path.join(test_dir, 'applistbad')
73  app_list = app_manager.AppList([filename])
74  al = app_list.get_app_list()
75  self.assertEquals([], al)
76  self.assertEquals(2, len(app_list.invalid_installed_files))
77 
80  self.assertEquals('/etc/robot/apps', app_manager.app_list.get_default_applist_directory())
81 
82  def test_InstalledFile(self):
83  from app_manager import InvalidAppException
84  from app_manager.app import find_resource
85  from app_manager.app_list import InstalledFile
86 
87  filename = find_resource('app_manager/apps1.installed')
88  inf = InstalledFile(filename)
89  self.failIf(inf._file_mtime is None)
90  self.assertEquals(filename, inf.filename)
91  self.assertEquals(1, len(inf.available_apps))
92  self.assertEquals('Android Joystick', inf.available_apps[0].display_name)
93 
94  #Had to be commented out, see app_list.py
95  #mtime = inf._file_mtime
96  #inf.update()
97  #self.assertEquals(mtime, inf._file_mtime)
98  #touch(filename)
99  #inf.update()
100  #self.assertNotEquals(mtime, inf._file_mtime)
101 
102  for bad in ['app_manager/bad.installed', 'app_manager/bad2.installed']:
103  filename = find_resource(bad)
104  try:
105  inf = InstalledFile(filename)
106  self.fail("should have thrown")
107  except InvalidAppException: pass
108 
110  from app_manager.msg import KeyValue
111  from app_manager.app_list import dict_to_KeyValue
112 
113  v = dict_to_KeyValue({})
114  self.assertEquals([], v)
115 
116  v = dict_to_KeyValue({'a': 'b'})
117  self.assertEquals([KeyValue('a', 'b')], v)
118 
119  v = dict_to_KeyValue({'a': 'b', 'c': 'd'})
120  for ve in [KeyValue('a', 'b'), KeyValue('c', 'd')]:
121  self.assert_(ve in v)
122 
123  # make sure that types convert
124  v = dict_to_KeyValue({'a': 1})
125  self.assertEquals([KeyValue('a', '1')], v)
126 
128  from app_manager.msg import App, ClientApp, KeyValue
129  from app_manager.app import AppDefinition, Client
130  from app_manager.app_list import AppDefinition_to_App, dict_to_KeyValue
131 
132  ad = AppDefinition(name="appname", display_name="An App",
133  description="Does something", platform="fakebot",
134  launch="file.launch", interface="file.interface", clients=[])
135  a = AppDefinition_to_App(ad)
136  self.assertEquals(a.name, 'appname')
137  self.assertEquals(a.display_name, 'An App')
138  self.assertEquals([], a.client_apps)
139 
140  client1 = Client('android',
141  {'manager1': 'data1'},
142  {'app1': 'data1'})
143  ca = ClientApp('android', [KeyValue('manager1', 'data1')], [KeyValue('app1', 'data1')])
144  ad = AppDefinition(name="appname", display_name="An App",
145  description="Does something", platform="fakebot",
146  launch="file.launch", interface="file.interface", clients=[client1])
147  a = AppDefinition_to_App(ad)
148  self.assertEquals([ca], a.client_apps)
149 
150  client1 = Client('android',
151  {'manager1': 'data1', 'manager2': 'data2'},
152  {'app1': 'data1', 'app2': 'data2'})
153  ca = ClientApp('android', dict_to_KeyValue(client1.manager_data), dict_to_KeyValue(client1.app_data))
154  ad = AppDefinition(name="appname", display_name="An App",
155  description="Does something", platform="fakebot",
156  launch="file.launch", interface="file.interface", clients=[client1])
157  a = AppDefinition_to_App(ad)
158  self.assertEquals([ca], a.client_apps)
159 
160  client2 = Client('web', {},
161  {'app2': 'data2', 'app2b': 'data2b'})
162  ca2 = ClientApp('web', [], dict_to_KeyValue(client2.app_data))
163  ad = AppDefinition(name="appname", display_name="An App",
164  description="Does something", platform="fakebot",
165  launch="file.launch", interface="file.interface", clients=[client1, client2])
166  a = AppDefinition_to_App(ad)
167  self.assertEquals([ca, ca2], a.client_apps)
168 
169 
170 if __name__ == '__main__':
171  rosunit.unitrun(PKG, 'test_app_list', AppListTest, coverage_packages=['app_manager.app_list'])
172 
def AppDefinition_to_App(app_definition)
Definition: app_list.py:78
def find_resource(resource)
Definition: app.py:112
def touch(filename)
def get_default_applist_directory()
Definition: app_list.py:51
def dict_to_KeyValue(d)
Definition: app_list.py:57
def test_get_default_applist_directory(self)


app_manager
Author(s): Jeremy Leibs, Ken Conley, Yuki Furuta
autogenerated on Tue Apr 2 2019 02:58:24