Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UTF8 reading. #83

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/urdf_parser_py/display_urdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def main():
parser = argparse.ArgumentParser(usage='Load an URDF file')
parser.add_argument('file', type=argparse.FileType('r'),
parser.add_argument('file', type=argparse.FileType('rb'),
help='File to load. Use - for stdin')
parser.add_argument('-o', '--output', type=argparse.FileType('w'),
default=None, help='Dump file to XML')
Expand Down
2 changes: 1 addition & 1 deletion src/urdf_parser_py/xml_reflection/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ def from_xml_string(cls, xml_string):

@classmethod
def from_xml_file(cls, file_path):
xml_string = open(file_path, 'r').read()
xml_string = open(file_path, 'rb').read()
return cls.from_xml_string(xml_string)

# Confusing distinction between loading code in object and reflection
Expand Down
15 changes: 15 additions & 0 deletions test/test_urdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,21 @@ def test_robot_link_defaults_xyz_set(self):
self.assertEqual(origin.xyz, [1, 2, 3])
self.assertEqual(origin.rpy, [0, 0, 0])

def test_xml_with_UTF8_encoding(self):
xml = b'''<?xml version="1.0" encoding="UTF-8"?>
<robot name="test">
<link name="test_link">
<inertial>
<mass value="10.0"/>
<origin xyz="1 2 3"/>
</inertial>
</link>
</robot>'''
robot = self.parse(xml)
origin = robot.links[0].inertial.origin
self.assertEqual(origin.xyz, [1, 2, 3])
self.assertEqual(origin.rpy, [0, 0, 0])


class LinkMultiVisualsAndCollisionsTest(unittest.TestCase):

Expand Down