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 as CtrlState
00029 from controller_manager_msgs.msg import HardwareInterfaceResources
00030 from controller_manager_msgs.utils import *
00031
00032 ctrl_list = [
00033 CtrlState(name='foo_controller',
00034 state='running',
00035 type='foo_base/foo',
00036 claimed_resources=[
00037 HardwareInterfaceResources(
00038 hardware_interface='hardware_interface::FooInterface',
00039 resources=['one', 'two', 'three'])
00040 ]),
00041 CtrlState(name='bar_controller',
00042 state='running',
00043 type='bar_base/bar',
00044 claimed_resources=[
00045 HardwareInterfaceResources(
00046 hardware_interface='hardware_interface::BarInterface',
00047 resources=['four'])
00048 ]),
00049 CtrlState(name='foobar_controller',
00050 state='stopped',
00051 type='foobar_base/foobar',
00052 claimed_resources=[
00053 HardwareInterfaceResources(
00054 hardware_interface='hardware_interface::FooBarInterface',
00055 resources=['one'])
00056 ]),
00057 CtrlState(name='foobaz_controller',
00058 state='running',
00059 type='foobaz_base/foobaz',
00060 claimed_resources=[
00061 HardwareInterfaceResources(
00062 hardware_interface='hardware_interface::FooInterface',
00063 resources=['one']),
00064 HardwareInterfaceResources(
00065 hardware_interface='hardware_interface::BazInterface',
00066 resources=['one', 'two'])
00067 ])
00068 ]
00069
00070
00071 def filter_by_name_test():
00072
00073 assert(not filter_by_name(ctrl_list, 'null', match_substring=False))
00074 assert(not filter_by_name(ctrl_list, 'null', match_substring=True))
00075
00076
00077 out = filter_by_name(ctrl_list, 'foo_controller')
00078 assert(1 == len(out))
00079 assert(out[0].name == 'foo_controller')
00080
00081
00082 out = filter_by_name(ctrl_list, 'foo_controller', match_substring=True)
00083 assert(1 == len(out))
00084 assert(out[0].name == 'foo_controller')
00085
00086 out = filter_by_name(ctrl_list, 'foo', match_substring=True)
00087 assert(3 == len(out))
00088 assert(out[0].name == 'foo_controller')
00089 assert(out[1].name == 'foobar_controller')
00090 assert(out[2].name == 'foobaz_controller')
00091
00092
00093 def filter_by_state_test():
00094
00095 assert(not filter_by_state(ctrl_list, 'null', match_substring=False))
00096 assert(not filter_by_state(ctrl_list, 'null', match_substring=True))
00097
00098
00099 out = filter_by_state(ctrl_list, 'stopped')
00100 assert(1 == len(out))
00101 assert(out[0].name == 'foobar_controller')
00102
00103
00104 out = filter_by_state(ctrl_list, 'stopped', match_substring=True)
00105 assert(1 == len(out))
00106 assert(out[0].name == 'foobar_controller')
00107
00108 out = filter_by_state(ctrl_list, 'run', match_substring=True)
00109 assert(3 == len(out))
00110 assert(out[0].name == 'foo_controller')
00111 assert(out[1].name == 'bar_controller')
00112 assert(out[2].name == 'foobaz_controller')
00113
00114
00115 def filter_by_type_test():
00116
00117 assert(not filter_by_type(ctrl_list, 'null', match_substring=False))
00118 assert(not filter_by_type(ctrl_list, 'null', match_substring=True))
00119
00120
00121 out = filter_by_type(ctrl_list, 'foo_base/foo')
00122 assert(1 == len(out))
00123 assert(out[0].name == 'foo_controller')
00124
00125
00126 out = filter_by_type(ctrl_list, 'foo_base/foo', match_substring=True)
00127 assert(1 == len(out))
00128 assert(out[0].name == 'foo_controller')
00129
00130 out = filter_by_type(ctrl_list, 'foo', match_substring=True)
00131 assert(3 == len(out))
00132 assert(out[0].name == 'foo_controller')
00133 assert(out[1].name == 'foobar_controller')
00134 assert(out[2].name == 'foobaz_controller')
00135
00136
00137 def filter_by_hardware_interface_test():
00138
00139 assert(not filter_by_hardware_interface(ctrl_list,
00140 'null',
00141 match_substring=False))
00142 assert(not filter_by_hardware_interface(ctrl_list,
00143 'null',
00144 match_substring=True))
00145
00146
00147 out = filter_by_hardware_interface(ctrl_list,
00148 'hardware_interface::FooInterface')
00149 assert(2 == len(out))
00150 assert(out[0].name == 'foo_controller')
00151 assert(out[1].name == 'foobaz_controller')
00152
00153
00154 out = filter_by_hardware_interface(ctrl_list,
00155 'hardware_interface::BazInterface',
00156 match_substring=True)
00157 assert(1 == len(out))
00158 assert(out[0].name == 'foobaz_controller')
00159
00160 out = filter_by_hardware_interface(ctrl_list,
00161 'BazInterface',
00162 match_substring=True)
00163 assert(1 == len(out))
00164 assert(out[0].name == 'foobaz_controller')
00165
00166
00167 def filter_by_resources_test():
00168
00169 assert(not filter_by_resources(ctrl_list, ['null'], match_any=False))
00170 assert(not filter_by_resources(ctrl_list, ['null'], match_any=True))
00171
00172
00173 assert(not filter_by_resources(
00174 ctrl_list,
00175 hardware_interface='hardware_interface::FooInterface',
00176 resources=['null'],
00177 match_any=False))
00178
00179 assert(not filter_by_resources(
00180 ctrl_list,
00181 hardware_interface='hardware_interface::FooInterface',
00182 resources=['null'],
00183 match_any=True))
00184
00185
00186
00187 assert(not filter_by_resources(
00188 ctrl_list,
00189 hardware_interface='hardware_interface::FooInterface',
00190 resources=['four'],
00191 match_any=False))
00192
00193 assert(not filter_by_resources(
00194 ctrl_list,
00195 hardware_interface='hardware_interface::FooInterface',
00196 resources=['four'],
00197 match_any=True))
00198
00199
00200 res = ctrl_list[0].claimed_resources[0].resources
00201 out = filter_by_resources(ctrl_list, res)
00202 assert(1 == len(out))
00203 assert(out[0].name == 'foo_controller')
00204
00205
00206 out = filter_by_resources(
00207 ctrl_list,
00208 hardware_interface='hardware_interface::FooInterface',
00209 resources=res)
00210 assert(1 == len(out))
00211 assert(out[0].name == 'foo_controller')
00212
00213 out = filter_by_resources(
00214 ctrl_list,
00215 hardware_interface='hardware_interface::FooInterface',
00216 resources=['one'])
00217 assert(2 == len(out))
00218 assert(out[0].name == 'foo_controller')
00219 assert(out[1].name == 'foobaz_controller')
00220
00221
00222 out = filter_by_resources(ctrl_list, res, match_any=True)
00223 assert(3 == len(out))
00224 assert(out[0].name == 'foo_controller')
00225 assert(out[1].name == 'foobar_controller')
00226 assert(out[2].name == 'foobaz_controller')
00227
00228
00229 out = filter_by_resources(
00230 ctrl_list,
00231 hardware_interface='hardware_interface::BazInterface',
00232 resources=['one'],
00233 match_any=True)
00234 assert(1 == len(out))
00235 assert(out[0].name == 'foobaz_controller')