44 from rospy.exceptions
import ROSException
45 from rospy.names
import scoped_name
47 [
'/',
'/name',
'name'],
48 [
'/',
'/ns/name',
'ns/name'],
49 [
'/ns',
'/ns/name',
'ns/name'],
50 [
'/ns/node',
'/ns/name',
'name'],
51 [
'/ns/',
'/ns/name',
'ns/name'],
52 [
'/ns/ns2/',
'/ns/name',
'name'],
54 for caller_id, name, v
in tests:
55 val = scoped_name(caller_id, name)
56 self.assertEquals(v, val,
"failed on [%s] [%s]: %s"%(caller_id, name, val))
63 for caller_id, name
in fail:
65 scoped_name(caller_id, name)
66 self.fail(
"should have failed on %s, %s"%(caller_id, name))
67 except ROSException:
pass 72 from rospy.names
import get_mappings, get_resolved_mappings, initialize_mappings
74 self.assertEquals({}, get_mappings())
77 self.assertEquals({}, get_resolved_mappings())
80 initialize_mappings(
'foo')
82 self.assertEquals({}, get_resolved_mappings())
85 rospy.names._mappings = roslib.names.load_mappings([
'__name:=newname',
'__log:=blah',
'_param:=value',
'foo:=bar',
'/baz:=a/b',
'~car:=c/d/e'])
87 self.assertEquals({
'__name':
'newname',
'__log':
'blah',
88 'foo':
'bar',
'/baz':
'a/b',
'~car':
'c/d/e'}, get_mappings())
90 self.assertEquals({}, get_resolved_mappings())
91 initialize_mappings(
'/name')
94 self.assertEquals({
'__name':
'newname',
'__log':
'blah',
95 'foo':
'bar',
'/baz':
'a/b',
'~car':
'c/d/e'}, get_mappings())
97 self.assertEquals({
'__name':
'newname',
'__log':
'blah',
98 '/foo':
'/bar',
'/baz':
'/a/b',
'/name/car':
'/c/d/e'},
99 get_resolved_mappings())
102 initialize_mappings(
'/ns/name')
104 self.assertEquals({
'__name':
'newname',
'__log':
'blah',
105 '/ns/foo':
'/ns/bar',
'/baz':
'/ns/a/b',
'/ns/name/car':
'/ns/c/d/e'},
106 get_resolved_mappings())
111 from rospy.names
import canonicalize_name
118 (
'/foo/bar',
'/foo/bar'),
119 (
'/foo/bar/',
'/foo/bar'),
120 (
'/foo/bar//',
'/foo/bar'),
121 (
'/foo//bar',
'/foo/bar'),
122 (
'//foo/bar',
'/foo/bar'),
123 (
'foo/bar',
'foo/bar'),
124 (
'foo//bar',
'foo/bar'),
125 (
'foo/bar/',
'foo/bar'),
126 (
'/foo/bar',
'/foo/bar'),
129 self.assertEquals(v, canonicalize_name(t))
132 from rospy.names
import TOPIC_ANYTYPE, SERVICE_ANYTYPE
133 self.assertEquals(
"*", TOPIC_ANYTYPE)
134 self.assertEquals(
"*", SERVICE_ANYTYPE)
137 from rospy.names
import resolve_name
143 (
'',
'/ns1/node',
'/ns1/'),
146 (
'foo',
None,
'/foo'),
147 (
'foo/',
'',
'/foo'),
148 (
'/foo',
'',
'/foo'),
149 (
'/foo/',
'',
'/foo'),
150 (
'/foo',
'/',
'/foo'),
151 (
'/foo',
None,
'/foo'),
152 (
'/foo/',
'/',
'/foo'),
153 (
'/foo',
'/bar',
'/foo'),
154 (
'/foo/',
'/bar',
'/foo'),
156 (
'foo',
'/ns1/ns2',
'/ns1/foo'),
157 (
'foo',
'/ns1/ns2/',
'/ns1/foo'),
158 (
'foo',
'/ns1/ns2/ns3/',
'/ns1/ns2/foo'),
159 (
'foo/',
'/ns1/ns2',
'/ns1/foo'),
160 (
'/foo',
'/ns1/ns2',
'/foo'),
161 (
'foo/bar',
'/ns1/ns2',
'/ns1/foo/bar'),
162 (
'foo//bar',
'/ns1/ns2',
'/ns1/foo/bar'),
163 (
'foo/bar',
'/ns1/ns2/ns3',
'/ns1/ns2/foo/bar'),
164 (
'foo//bar//',
'/ns1/ns2/ns3',
'/ns1/ns2/foo/bar'),
166 (
'~foo',
'/',
'/foo'),
167 (
'~foo',
'/node',
'/node/foo'),
168 (
'~foo',
'/ns1/ns2',
'/ns1/ns2/foo'),
169 (
'~foo/',
'/ns1/ns2',
'/ns1/ns2/foo'),
170 (
'~foo/bar',
'/ns1/ns2',
'/ns1/ns2/foo/bar'),
173 for name, node_name, v
in tests:
174 self.assertEquals(v, resolve_name(name, node_name))
178 from rospy.names
import valid_name_validator_resolved, valid_name, ParameterInvalid
179 validator = valid_name(
'param_name',
True)
181 (
'name',
'/node',
'/name'),
182 (
'/name',
'/node',
'/name'),
183 (
'~name',
'/node',
'/node/name'),
185 (
u'~name',
'/node',
u'/node/name'),
187 for name, caller_id, v
in tests:
188 self.assertEquals(v, valid_name_validator_resolved(
'p', name, caller_id),
"failed on %s %s"%(name, caller_id))
189 self.assertEquals(v, validator(name, caller_id))
198 (
'localhost:123',
'/node'),
199 (
'Bob Barker',
'/node'),
201 (
u'Bob Barker',
'/node'),
203 for name, caller_id
in invalid:
205 valid_name_validator_resolved(
'p', name, caller_id)
206 self.fail(
"valid_name_validator_unresolved should have failed on : [%s], [%s]"%(name, caller_id))
207 except ParameterInvalid:
pass 209 validator(name, caller_id)
210 self.fail(
"valid_name_validator_unresolved should have failed on : [%s], [%s]"%(name, caller_id))
211 except ParameterInvalid:
pass 213 from rospy.names
import valid_name_validator_unresolved
214 validator = valid_name(
'param_name',
False)
216 (
'name',
'/node',
'name'),
217 (
'/name',
'/node',
'/name'),
218 (
'~name',
'/node',
'~name'),
220 (
u'~name',
'/node',
u'~name'),
222 for name, caller_id, v
in tests:
223 self.assertEquals(v, valid_name_validator_unresolved(
'p', name, caller_id),
"failed on [%s] [%s]"%(name, caller_id))
224 self.assertEquals(v, validator(name, caller_id))
226 for name, caller_id
in invalid:
228 valid_name_validator_unresolved(
'p', name, caller_id)
229 self.fail(
"valid_name_validator_unresolved should have failed on : [%s], [%s]"%(name, caller_id))
230 except ParameterInvalid:
pass 232 validator(name, caller_id)
233 self.fail(
"valid_name_validator_unresolved should have failed on : [%s], [%s]"%(name, caller_id))
234 except ParameterInvalid:
pass 237 from rospy.names
import global_name, ParameterInvalid
238 validator = global_name(
'param_name')
241 (
'/name',
'/node',
'/name'),
243 (
u'/name',
'/node',
u'/name'),
245 for name, caller_id, v
in tests:
246 self.assertEquals(v, validator(name, caller_id))
253 for name, caller_id
in invalid:
255 validator(name, caller_id)
256 self.fail(
"global_name should have failed on : [%s], [%s]"%(name, caller_id))
257 except ParameterInvalid:
pass 260 from rospy.names
import get_caller_id, get_name, _set_caller_id, get_namespace
263 self.assertEquals(
'/unnamed', get_name())
264 self.assertEquals(
'/', get_namespace())
265 _set_caller_id(
'/foo')
266 self.assertEquals(
'/foo', get_name())
267 self.assertEquals(
'/', get_namespace())
268 _set_caller_id(
'/foo/bar')
269 self.assertEquals(
'/foo/bar', get_name())
270 self.assertEquals(
'/foo/', get_namespace())
272 _set_caller_id(
'/unnamed')
276 self.assertEquals(
'/unnamed', get_caller_id())
277 self.assertEquals(
'/', get_namespace())
278 _set_caller_id(
'/foo')
279 self.assertEquals(
'/foo', get_caller_id())
280 self.assertEquals(
'/', get_namespace())
281 _set_caller_id(
'/foo/bar')
282 self.assertEquals(
'/foo/bar', get_caller_id())
283 self.assertEquals(
'/foo/', get_namespace())
285 _set_caller_id(
'/unnamed')
def test_canonicalize_name(self)
def test_global_name(self)
def test_scoped_name(self)
def test_resolve_name(self)
def test_valid_name(self)