Skip to content

Commit 3d061ea

Browse files
Noel215rhaschke
authored andcommitted
Handle str and pathlib.Path args for process_file()
1 parent 46f2a79 commit 3d061ea

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/xacro/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ def process_file(input_file_name, **kwargs):
11201120
banner = [xml.dom.minidom.Comment(c) for c in
11211121
[" %s " % ('=' * 83),
11221122
# replace consecutive dashes with a single one to yield a XML-compliant comment string
1123-
" | This document was autogenerated by xacro from %-30s | " % re.sub(r'-+', '-', input_file_name),
1123+
" | This document was autogenerated by xacro from %-30s | " % re.sub(r'-+', '-', str(input_file_name)),
11241124
" | EDITING THIS FILE BY HAND IS NOT RECOMMENDED %-30s | " % "",
11251125
" %s " % ('=' * 83)]]
11261126
first = doc.firstChild

test/test_xacro.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import itertools
4040
import math
4141
import os.path
42+
import pathlib
4243
import re
4344
import shutil
4445
import subprocess
@@ -1653,6 +1654,15 @@ def test_remove_property(self):
16531654
${p}</a>'''
16541655
self.assert_matches(self.quick_xacro(src), '<a>2nd</a>')
16551656

1657+
def test_process_file_types(self):
1658+
# Test that checks process_file method with different path types
1659+
# os.path
1660+
path = os.path.join(os.path.dirname(__file__), 'emoji.xacro')
1661+
self.assert_matches(xacro.process_file(path), '<robot>🍔</robot>')
1662+
1663+
# pathlib.Path
1664+
path = pathlib.Path(os.path.join(os.path.dirname(__file__), 'emoji.xacro'))
1665+
self.assert_matches(xacro.process_file(path), '<robot>🍔</robot>')
16561666

16571667
if __name__ == '__main__':
16581668
unittest.main()

0 commit comments

Comments
 (0)