Skip to content

Commit

Permalink
Add test for --root-dir argument
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Jan 15, 2025
1 parent b4aa47d commit 4399f2b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/test_xacro.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,46 @@ def test_create_subdirs(self):

self.assertTrue(output_file_created)

def test_set_root_directory(self):
# Run xacro in one directory, but specify the directory to resolve
# filenames in.
tmp_dir_name = tempfile.mkdtemp() # create directory we can trash

output_path = os.path.join(tmp_dir_name, "out")

# Generate a pair of files to be parsed by xacro, outside of the
# test directory, to ensure the root-dir argument works
file_foo = os.path.join(tmp_dir_name, 'foo.xml.xacro')
file_bar = os.path.join(tmp_dir_name, 'bar.xml.xacro')
with open(file_foo, 'w') as f:
f.write('''<?xml version="1.0"?>
<robot xmlns:xacro="http://ros.org/wiki/xacro">
<xacro:include filename="bar.xml.xacro"/>
</robot>
''')
with open(file_bar, 'w') as f:
f.write('''<?xml version="1.0"?>
<robot xmlns:xacro="http://ros.org/wiki/xacro">
<link name="my_link"/>
</robot>
''')

# Run xacro with no --root-dir arg, which will then use the
# current path as the path to resolveto
self.run_xacro('foo.xml.xacro', '-o', output_path)
output_file_created = os.path.isfile(output_path)
self.assertFalse(output_file_created)

# Run xacro with --root-dir arg set to the new temp directory
self.run_xacro('foo.xml.xacro',
'--root-dir', tmp_dir_name,
'-o', output_path)

output_file_created = os.path.isfile(output_path)
shutil.rmtree(tmp_dir_name) # clean up after ourselves

self.assertTrue(output_file_created)

def test_iterable_literals_plain(self):
self.assert_matches(self.quick_xacro('''
<a xmlns:xacro="http://www.ros.org/wiki/xacro">
Expand Down

0 comments on commit 4399f2b

Please sign in to comment.