cm_msgs_utils_test.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Copyright (C) 2014, PAL Robotics S.L.
00004 #
00005 # Redistribution and use in source and binary forms, with or without
00006 # modification, are permitted provided that the following conditions are met:
00007 # * Redistributions of source code must retain the above copyright notice,
00008 # this list of conditions and the following disclaimer.
00009 # * Redistributions in binary form must reproduce the above copyright
00010 # notice, this list of conditions and the following disclaimer in the
00011 # documentation and/or other materials provided with the distribution.
00012 # * Neither the name of PAL Robotics S.L. nor the names of its
00013 # contributors may be used to endorse or promote products derived from
00014 # this software without specific prior written permission.
00015 #
00016 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00019 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00020 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00021 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00022 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00023 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00024 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00025 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00026 # POSSIBILITY OF SUCH DAMAGE.
00027 
00028 from controller_manager_msgs.msg import ControllerState
00029 from controller_manager_msgs.utils import *
00030 
00031 ctrl_list = [
00032     ControllerState(name='foo_controller',
00033                     state='running',
00034                     type='foo_base/foo',
00035                     hardware_interface='hardware_interface::FooInterface',
00036                     resources=['one', 'two', 'three']),
00037     ControllerState(name='bar_controller',
00038                     state='running',
00039                     type='bar_base/bar',
00040                     hardware_interface='hardware_interface::BarInterface',
00041                     resources=['four']),
00042     ControllerState(name='foobar_controller',
00043                     state='stopped',
00044                     type='foobar_base/foobar',
00045                     hardware_interface='hardware_interface::FooBarInterface',
00046                     resources=['one'])
00047 ]
00048 
00049 
00050 def filter_by_name_test():
00051     # Non-existing
00052     assert(not filter_by_name(ctrl_list, 'null', match_substring=False))
00053     assert(not filter_by_name(ctrl_list, 'null', match_substring=True))
00054 
00055     # Existing, full match
00056     out = filter_by_name(ctrl_list, 'foo_controller')
00057     assert(1 == len(out))
00058     assert(out[0].name == 'foo_controller')
00059 
00060     # Existing, substring match
00061     out = filter_by_name(ctrl_list, 'foo_controller', match_substring=True)
00062     assert(1 == len(out))
00063     assert(out[0].name == 'foo_controller')
00064 
00065     out = filter_by_name(ctrl_list, 'foo', match_substring=True)
00066     assert(2 == len(out))
00067     assert(out[0].name == 'foo_controller')
00068     assert(out[1].name == 'foobar_controller')
00069 
00070 
00071 def filter_by_state_test():
00072     # Non-existing
00073     assert(not filter_by_state(ctrl_list, 'null', match_substring=False))
00074     assert(not filter_by_state(ctrl_list, 'null', match_substring=True))
00075 
00076     # Existing, full match
00077     out = filter_by_state(ctrl_list, 'stopped')
00078     assert(1 == len(out))
00079     assert(out[0].name == 'foobar_controller')
00080 
00081     # Existing, substring match
00082     out = filter_by_state(ctrl_list, 'stopped', match_substring=True)
00083     assert(1 == len(out))
00084     assert(out[0].name == 'foobar_controller')
00085 
00086     out = filter_by_state(ctrl_list, 'run', match_substring=True)
00087     assert(2 == len(out))
00088     assert(out[0].name == 'foo_controller')
00089     assert(out[1].name == 'bar_controller')
00090 
00091 
00092 def filter_by_type_test():
00093     # Non-existing
00094     assert(not filter_by_type(ctrl_list, 'null', match_substring=False))
00095     assert(not filter_by_type(ctrl_list, 'null', match_substring=True))
00096 
00097     # Existing, full match
00098     out = filter_by_type(ctrl_list, 'foo_base/foo')
00099     assert(1 == len(out))
00100     assert(out[0].name == 'foo_controller')
00101 
00102     # Existing, substring match
00103     out = filter_by_type(ctrl_list, 'foo_base/foo', match_substring=True)
00104     assert(1 == len(out))
00105     assert(out[0].name == 'foo_controller')
00106 
00107     out = filter_by_type(ctrl_list, 'foo', match_substring=True)
00108     assert(2 == len(out))
00109     assert(out[0].name == 'foo_controller')
00110     assert(out[1].name == 'foobar_controller')
00111 
00112 
00113 def filter_by_hardware_interface_test():
00114     # Non-existing
00115     assert(not filter_by_hardware_interface(ctrl_list,
00116                                             'null',
00117                                             match_substring=False))
00118     assert(not filter_by_hardware_interface(ctrl_list,
00119                                             'null',
00120                                             match_substring=True))
00121 
00122     # Existing, full match
00123     out = filter_by_hardware_interface(ctrl_list,
00124                                        'hardware_interface::FooInterface')
00125     assert(1 == len(out))
00126     assert(out[0].name == 'foo_controller')
00127 
00128     # Existing, substring match
00129     out = filter_by_hardware_interface(ctrl_list,
00130                                        'hardware_interface::FooInterface',
00131                                        match_substring=True)
00132     assert(1 == len(out))
00133     assert(out[0].name == 'foo_controller')
00134 
00135     out = filter_by_hardware_interface(ctrl_list,
00136                                        'FooInterface',
00137                                        match_substring=True)
00138     assert(1 == len(out))
00139     assert(out[0].name == 'foo_controller')
00140 
00141 
00142 def filter_by_resources_test():
00143     # Non-existing
00144     assert(not filter_by_resources(ctrl_list, ['null'], match_any=False))
00145     assert(not filter_by_resources(ctrl_list, ['null'], match_any=True))
00146 
00147     # Existing, full match
00148     res = ctrl_list[0].resources
00149     out = filter_by_resources(ctrl_list, res)
00150     assert(1 == len(out))
00151     assert(out[0].name == 'foo_controller')
00152 
00153     # Existing, partial match
00154     out = filter_by_resources(ctrl_list, res, match_any=True)
00155     assert(2 == len(out))
00156     assert(out[0].name == 'foo_controller')
00157     assert(out[1].name == 'foobar_controller')
00158 
00159     out = filter_by_resources(ctrl_list, ['one'], match_any=True)
00160     assert(2 == len(out))
00161     assert(out[0].name == 'foo_controller')
00162     assert(out[1].name == 'foobar_controller')


controller_manager_tests
Author(s): Vijay Pradeep
autogenerated on Sat Jun 8 2019 20:09:25