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 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
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
00056 out = filter_by_name(ctrl_list, 'foo_controller')
00057 assert(1 == len(out))
00058 assert(out[0].name == 'foo_controller')
00059
00060
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
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
00077 out = filter_by_state(ctrl_list, 'stopped')
00078 assert(1 == len(out))
00079 assert(out[0].name == 'foobar_controller')
00080
00081
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
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
00098 out = filter_by_type(ctrl_list, 'foo_base/foo')
00099 assert(1 == len(out))
00100 assert(out[0].name == 'foo_controller')
00101
00102
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
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
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
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
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
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
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')