test/test_app.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 class AppTest(unittest.TestCase):
44 
45 
46  def test_Interface(self):
47  from app_manager.app import Interface
48  s1 = {'/chatter': 'std_msgs/String'}
49  p1 = {'/chatter': 'std_msgs/String'}
50  i1 = Interface(s1, p1)
51  self.assertEquals(i1, i1)
52  self.assertEquals(s1, i1.subscribed_topics)
53  self.assertEquals(s1, i1.published_topics)
54 
55  i2 = Interface({'/chatter': 'std_msgs/String'}, {'/chatter': 'std_msgs/String'})
56  self.assertEquals(i1, i2)
57  i3 = Interface({'/chatter2': 'std_msgs/String'}, {'/chatter': 'std_msgs/String'})
58  self.assertNotEquals(i1, i3)
59  i4 = Interface({'/chatter': 'std_msgs/String'}, {'/chatter2': 'std_msgs/String'})
60  self.assertNotEquals(i1, i4)
61 
62  def test_Client(self):
63  from app_manager.app import Client
64  c1 = Client(client_type="android",
65  manager_data={"manager1": "dataA"},
66  app_data={"app1": "dataB"})
67  self.assertEquals("android", c1.client_type)
68  self.assertEquals({"manager1": "dataA"}, c1.manager_data)
69  self.assertEquals({"app1": "dataB"}, c1.app_data)
70  self.assertEquals(c1, c1)
71  c2 = Client(client_type="android",
72  manager_data={"manager1": "dataA"},
73  app_data={"app1": "dataB"})
74  self.assertEquals(c1, c2)
75  noteq = [
76  Client("androidB", {"manager1": "dataA"},
77  {"app1": "dataB"}),
78  Client("android", {"manager2": "dataA"},
79  {"app1": "dataB"}),
80  Client("android", {"manager1": "dataA"},
81  {"app2": "dataB"}),
82  ]
83  for c3 in noteq:
84  self.assertNotEquals(c1, c3)
85 
86  def test_AppDefinition(self):
87  # name, display_name, description, platform, launch, interface, clients
88  from app_manager.app import AppDefinition, Client
89  ad1 = AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})])
90  self.assertEquals(ad1, ad1)
91  ad2 = AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})])
92  self.assertEquals(ad1, ad2)
93  ad3 = AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})], None)
94  self.assertEquals(ad1, ad3)
95 
96  ad1b = AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})], 'app_manager/icon.png')
97  self.assertEquals(ad1, ad1)
98  ad2b = AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})], 'app_manager/icon.png')
99  self.assertEquals(ad1b, ad2b)
100  nad2b = AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})], 'app_manager/icon2.png')
101  self.assertNotEquals(ad1, nad2b)
102 
103  noteq = [
104  AppDefinition('bar', 'Foo', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})]),
105  AppDefinition('foo', 'Bar', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})]),
106  AppDefinition('foo', 'Foo', 'Is Bar', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})]),
107  AppDefinition('foo', 'Foo', 'Is Foo', 'ios', 'foo.launch', 'foo.interface', [Client("android", {}, {})]),
108  AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'bar.launch', 'foo.interface', [Client("android", {}, {})]),
109  AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'foo.launch', 'bar.interface', [Client("android", {}, {})]),
110  AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("ios", {}, {})]),
111  ]
112  for nad in noteq:
113  self.assertNotEquals(ad1, nad)
114 
116  from app_manager.app import find_resource
117  rospack = rospkg.RosPack()
118  path = rospack.get_path(PKG)
119  test_dir = os.path.join(path, 'test')
120 
121  e = os.path.join(test_dir, 'empty.interface')
122  self.assertEquals(e, find_resource('%s/empty.interface'%(PKG)))
123 
124  e = os.path.join(test_dir, 'applist1', 'apps1.installed')
125  self.assertEquals(e, find_resource('%s/apps1.installed'%(PKG)))
126 
127  try:
128  find_resource('empty.interface')
129  self.fail("should have thrown ValueError: no package name")
130  except ValueError:
131  pass
132  try:
133  find_resource('app_manager')
134  self.fail("should have thrown ValueError: no resource name")
135  except ValueError:
136  pass
137 
139  rospack = rospkg.RosPack()
140  rl_dir = rospack.get_path('roslaunch')
141  from app_manager import NotFoundException, InternalAppException
142  from app_manager.app import load_AppDefinition_by_name, Interface
143  try:
145  self.fail("should fail")
146  except ValueError: pass
147  try:
148  load_AppDefinition_by_name("fake_pkg/appA")
149  self.fail("should fail")
150  except NotFoundException: pass
151 
152  ad = load_AppDefinition_by_name('app_manager/appA')
153  self.assertEquals("app_manager/appA", ad.name)
154  self.assertEquals("Android Joystick", ad.display_name)
155  self.assertEquals("Control the TurtleBot with an Android device", ad.description)
156  self.assertEquals("turtlebot", ad.platform)
157  #self.assertEquals(os.path.join(rl_dir, 'resources', 'example-min.launch'), ad.launch) # example-min.launch location changed due to https://github.com/PR2/app_manager/pull/15
158  self.assertEquals(os.path.join(rospack.get_path(PKG), 'test', 'resources', 'example-min.launch'), ad.launch)
159  self.assert_(isinstance(ad.interface, Interface))
160  self.assertEquals({}, ad.interface.subscribed_topics)
161  self.assertEquals({}, ad.interface.published_topics)
162  self.assertEquals([], ad.clients)
163 
164  #monkey patch in for coverage
165  import errno
166  def fake_load_enoent(*args):
167  raise IOError(errno.ENOENT, "fnf")
168  def fake_load_gen(*args):
169  raise IOError()
170  import app_manager.app
171  load_actual = app_manager.app.load_AppDefinition_from_file
172  try:
173  app_manager.app.load_AppDefinition_from_file = fake_load_enoent
174  try:
175  load_AppDefinition_by_name('app_manager/appA')
176  self.fail("should have raised")
177  except NotFoundException: pass
178 
179  app_manager.app.load_AppDefinition_from_file = fake_load_gen
180  try:
181  load_AppDefinition_by_name('app_manager/appA')
182  self.fail("should have raised")
183  except InternalAppException: pass
184  finally:
185  app_manager.app.load_AppDefinition_from_file = load_actual
186 
188  rospack = rospkg.RosPack()
189  rl_dir = rospack.get_path('roslaunch')
190  path = rospack.get_path(PKG)
191  test_dir = os.path.join(path, 'test')
192 
193  from app_manager.app import load_AppDefinition_from_file, Interface
194  ad = load_AppDefinition_from_file(os.path.join(test_dir, 'appA.app'), 'foo/AppA')
195  self.assertEquals("foo/AppA", ad.name)
196  self.assertEquals("Android Joystick", ad.display_name)
197  self.assertEquals("Control the TurtleBot with an Android device", ad.description)
198  self.assertEquals("turtlebot", ad.platform)
199  #self.assertEquals(os.path.join(rl_dir, 'resources', 'example-min.launch'), ad.launch) # example-min.launch location changed due to https://github.com/PR2/app_manager/pull/15
200  self.assertEquals(os.path.join(test_dir, 'resources', 'example-min.launch'), ad.launch)
201  self.assert_(isinstance(ad.interface, Interface))
202  self.assertEquals({}, ad.interface.subscribed_topics)
203  self.assertEquals({}, ad.interface.published_topics)
204  self.assertEquals([], ad.clients)
205  #self.assertEquals('app_manager/empty.interface', ad.interface)
206 
208  from app_manager.app import load_Interface_from_file
209  rospack = rospkg.RosPack()
210  path = rospack.get_path(PKG)
211  test_dir = os.path.join(path, 'test')
212 
213  empty = load_Interface_from_file(os.path.join(test_dir, 'empty.interface'))
214  self.assertEquals({}, empty.subscribed_topics)
215  self.assertEquals({}, empty.published_topics)
216 
217  test1 = load_Interface_from_file(os.path.join(test_dir, 'test1.interface'))
218  self.assertEquals({'/camera/rgb/image_color/compressed': 'sensor_msgs/CompressedImage'}, test1.published_topics)
219  self.assertEquals({'/turtlebot_node/cmd_vel': 'geometry_msgs/Twist'}, test1.subscribed_topics)
220 
221 
222 if __name__ == '__main__':
223  rosunit.unitrun(PKG, 'test_app', AppTest, coverage_packages=['app_manager.app'])
224 
def test_Client(self)
def load_AppDefinition_from_file(appfile, appname)
Definition: app.py:274
def test_load_Interface_from_file(self)
def find_resource(resource)
Definition: app.py:117
def test_AppDefinition(self)
def test_load_AppDefinition_by_name(self)
def test_load_AppDefinition_from_file(self)
def load_AppDefinition_by_name(appname)
Definition: app.py:302
def test_Interface(self)
def test_find_resource(self)
def load_Interface_from_file(filename)
Definition: app.py:138


app_manager
Author(s): Jeremy Leibs, Ken Conley, Yuki Furuta
autogenerated on Fri Mar 5 2021 03:07:47