3 from urdf_parser_py
import urdf
6 ParseError = xmlr.core.ParseError
12 def add_error(message):
13 self.
errors.append(message)
14 xmlr.core.on_error = add_error
17 xmlr.core.on_error = xmlr.core.on_error_stderr
21 self.assertEqual(self.
errors, errors)
24 with self.assertRaises(ParseError)
as cm:
27 self.assertEqual(str(e.path), str(path))
30 """ Check XML parsing of a given string, using both "from_xml_string" and "parse" """
40 use_static =
lambda: cls.from_xml_string(xml_string)
42 use_bound =
lambda: cls().parse(xml_string)
43 return [use_static, preclean(use_bound)]
46 xml_string =
'''<?xml version="1.0"?>
51 errors_expected = [
'Unknown tag "unknown_element" in /link[@name=\'b\']']
56 xml_string =
'''<?xml version="1.0"?>
57 <link name="b" unknown_attribute="nothing useful"/>'''
59 errors_expected = [
'Unknown attribute "unknown_attribute" in /link[@name=\'b\']']
64 xml_string =
'''<?xml version="1.0"?>
71 xml_string =
'''<?xml version="1.0"?>
72 <joint name="bad_joint" type="badtype">
73 <parent link="parent"/>
81 xml_string =
'''<?xml version="1.0"?>
83 <joint name="bad_joint" type="badtype">
84 <parent link="parent"/>
93 """ Show that an aggregate with an unset name still has its index specified """
94 xml_string =
'''<?xml version="1.0"?>
97 <link name_BAD="bad"/>
104 """ If an aggregate duck-typed element does not have a required attribute, ensure it is reported with the index """
105 xml_string =
'''<?xml version="1.0"?>
107 <transmission name_BAD="bad_trans"/>
114 xml_string =
'''<?xml version="1.0"?>
118 <origin xyz="0.1 0.2 BAD_NUMBER"/>
127 xml_string =
'''<?xml version="1.0"?>
129 <transmission name="simple_trans">
130 <type>transmission_interface/SimpleTransmission</type>
131 <joint name="foo_joint">
132 <hardwareInterface>EffortJointInterface</hardwareInterface>
134 <actuator name="foo_motor"/>
136 <transmission name="simple_trans_bad">
137 <type>transmission_interface/SimpleTransmission</type>
138 <actuator name="foo_motor"/>
139 <joint name_BAD="foo_joint">
140 <hardwareInterface>EffortJointInterface</hardwareInterface>
148 if __name__ ==
'__main__':