Skip to content

Commit

Permalink
fix paths (and regex for paths) comparison issues (#1592)
Browse files Browse the repository at this point in the history
* add os.path.normcase for return value of Logger.FindCaller, escape windows path delimiter for regex comparison

* escape os path separator for regular expression comparison

* use os.path.sep to indicate path separator

* use re.escape to escape metacharacters

* apply escaping only when the string is used for comparison
  • Loading branch information
kejxu authored and dirk-thomas committed Feb 5, 2019
1 parent aabed39 commit 08b28eb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/test_rospy/test/unit/test_rospy_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def lvl2loglvl_stream(lvl):
'[0-9]*\.[0-9]*',
'[0-9]*',
'rosout',
this_file,
re.escape(this_file),
'[0-9]*',
'TestRospyCore.test_loggers',
'/unnamed',
Expand Down
1 change: 1 addition & 0 deletions tools/rosgraph/src/rosgraph/roslogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def findCaller(self, dummy=False): # Dummy second arg to match Python3 function
file name, line number, and function name with class name if possible.
"""
file_name, lineno, func_name = super(RospyLogger, self).findCaller()[:3]
file_name = os.path.normcase(file_name)

f = inspect.currentframe()
if f is not None:
Expand Down
3 changes: 2 additions & 1 deletion tools/rosgraph/test/test_roslogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from StringIO import StringIO
import sys

import re
from nose.tools import assert_regexp_matches
import rosgraph.roslogging

Expand Down Expand Up @@ -109,7 +110,7 @@ def test_rosconsole__logging_format():
'[0-9]*\.[0-9]*',
'[0-9]*',
'rosout',
this_file,
re.escape(this_file),
'[0-9]*',
function,
# depending if rospy.get_name() is available
Expand Down

0 comments on commit 08b28eb

Please sign in to comment.