Skip to content

Commit

Permalink
[Windows][melodic-devel] Make test code to be more portable (#1726)
Browse files Browse the repository at this point in the history
* Make test code to be more portable.

* unrelated change
  • Loading branch information
seanyen authored and dirk-thomas committed Oct 3, 2019
1 parent c1ad5e5 commit d3991ab
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
8 changes: 4 additions & 4 deletions test/test_roslib_comm/test/test_roslib_msgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ def test___convert_val(self):

def test_msg_file(self):
import roslib.msgs
f = roslib.msgs.msg_file('rosgraph_msgs', 'Log')
f = os.path.normcase(roslib.msgs.msg_file('rosgraph_msgs', 'Log'))
self.assert_(os.path.isfile(f))
self.assert_(f.endswith('rosgraph_msgs/msg/Log.msg'))
self.assert_(f.endswith(os.path.normcase('rosgraph_msgs/msg/Log.msg')))

# msg_file should return paths even for non-existent resources
f = roslib.msgs.msg_file('roslib', 'Fake')
f = os.path.normcase(roslib.msgs.msg_file('roslib', 'Fake'))
self.failIf(os.path.isfile(f))
self.assert_(f.endswith('roslib/msg/Fake.msg'))
self.assert_(f.endswith(os.path.normcase('roslib/msg/Fake.msg')))

def test_is_valid_msg_type(self):
import roslib.msgs
Expand Down
4 changes: 2 additions & 2 deletions test/test_rosparam/test/test_rosparam_command_line_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_offline(self):
env['ROS_MASTER_URI'] = 'http://localhost:11312'
kwds = { 'env': env, 'stdout': PIPE, 'stderr': PIPE}

msg = "ERROR: Unable to communicate with master!\n"
msg = "ERROR: Unable to communicate with master!" + os.linesep

output = Popen([cmd, 'list'], **kwds).communicate()
self.assert_(output[1].decode().endswith(msg))
Expand All @@ -98,7 +98,7 @@ def test_offline(self):

# test with file that does not exist
output = Popen([cmd, 'load', 'fake.yaml'], **kwds).communicate()
self.assertEquals('ERROR: file [fake.yaml] does not exist\n', output[1].decode())
self.assertEquals('ERROR: file [fake.yaml] does not exist' + os.linesep, output[1].decode())

output = Popen([cmd, 'dump', 'foo.yaml'], **kwds).communicate()
self.assert_(output[1].decode().endswith(msg))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_offline(self):
env['ROS_MASTER_URI'] = 'http://localhost:11312'
kwds = { 'env': env, 'stdout': PIPE, 'stderr': PIPE}

msg = "ERROR: Unable to communicate with master!\n"
msg = "ERROR: Unable to communicate with master!" + os.linesep

output = Popen([cmd, 'list'], **kwds).communicate()
self.assert_(output[1].decode().endswith(msg))
Expand Down
2 changes: 1 addition & 1 deletion tools/rosgraph/test/test_rosgraph_command_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_offline(self):
env['ROS_MASTER_URI'] = 'http://localhost:11312'
kwds = { 'env': env, 'stdout': PIPE, 'stderr': PIPE}

msg = "ERROR: Unable to communicate with master!\n"
msg = "ERROR: Unable to communicate with master!" + os.linesep

output = Popen([cmd], **kwds).communicate()
self.assertEquals(msg, output[1].decode())
25 changes: 13 additions & 12 deletions tools/rosmsg/test/test_rosmsg_command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TestRosmsg(unittest.TestCase):

def setUp(self):
self.new_environ = os.environ
self.new_environ["PYTHONPATH"] = os.path.join(os.getcwd(), "src")+':'+os.environ['PYTHONPATH']
self.new_environ["PYTHONPATH"] = os.path.join(os.getcwd(), "src")+os.pathsep+os.environ['PYTHONPATH']

## test that the rosmsg command works
def test_cmd_help(self):
Expand Down Expand Up @@ -140,7 +140,7 @@ def test_cmd_show(self):
output = Popen(['rossrv', 'show', 'std_srvs/Empty'], stdout=PIPE).communicate()[0].decode()
self.assertEquals('---', output.strip())
output = Popen(['rossrv', 'show', 'test_rosmaster/AddTwoInts'], stdout=PIPE).communicate()[0].decode()
self.assertEquals('int64 a\nint64 b\n---\nint64 sum', output.strip())
self.assertEquals(os.linesep.join(['int64 a', 'int64 b', '---', 'int64 sum']), output.strip())

# test against test_rosmsg package
d = os.path.abspath(os.path.dirname(__file__))
Expand All @@ -156,23 +156,24 @@ def test_cmd_show(self):
text = f.read()
with open(os.path.join(msg_raw_d, '%s.msg'%t), 'r') as f:
text_raw = f.read()
text = text+'\n' # running command adds one new line
text_raw = text_raw+'\n'
text = text.strip()
text_raw = text_raw.strip()
type_ =test_message_package+'/'+t
output = Popen(['rosmsg', 'show', type_], stdout=PIPE).communicate()[0].decode()
self.assertEquals(text, output)
self.assertEquals(text, output.strip())
output = Popen(['rosmsg', 'show', '-r',type_], stdout=PIPE).communicate()[0].decode()
self.assertEquals(text_raw, output)
self.assertEquals(text_raw, output.strip())
output = Popen(['rosmsg', 'show', '--raw', type_], stdout=PIPE).communicate()[0].decode()
self.assertEquals(text_raw, output)
self.assertEquals(text_raw, output.strip())

# test as search
type_ = t
text = "[test_rosmaster/%s]:\n%s"%(t, text)
text_raw = "[test_rosmaster/%s]:\n%s"%(t, text_raw)
text_prefix = "[test_rosmaster/%s]:"%t
text = os.linesep.join([text_prefix, text])
text_raw = os.linesep.join([text_prefix, text_raw])
output = Popen(['rosmsg', 'show', type_], stdout=PIPE).communicate()[0].decode()
self.assertEquals(text, output)
self.assertEquals(text, output.strip())
output = Popen(['rosmsg', 'show', '-r',type_], stdout=PIPE, stderr=PIPE).communicate()
self.assertEquals(text_raw, output[0].decode(), "Failed: %s"%(str(output)))
self.assertEquals(text_raw, output[0].decode().strip(), "Failed: %s"%(str(output)))
output = Popen(['rosmsg', 'show', '--raw', type_], stdout=PIPE).communicate()[0].decode()
self.assertEquals(text_raw, output)
self.assertEquals(text_raw, output.strip())
2 changes: 1 addition & 1 deletion tools/rosmsg/test/test_rosmsgproto_command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def setUp(self):
# proto depends on python 2.7 having OrderedDict
if _NO_DICT: raise SkipTest("Test skipped because Python version too low")
self.new_environ = os.environ
self.new_environ["PYTHONPATH"] = os.path.join(os.getcwd(), "src")+':'+os.environ['PYTHONPATH']
self.new_environ["PYTHONPATH"] = os.path.join(os.getcwd(), "src")+os.linesep+os.environ['PYTHONPATH']

def testFail(self):
cmd = copy.copy(ROSMSGPROTO_FN)
Expand Down
2 changes: 1 addition & 1 deletion tools/rostopic/test/test_rostopic_command_line_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_offline(self):
env['ROS_MASTER_URI'] = 'http://localhost:11312'
kwds = { 'env': env, 'stdout': PIPE, 'stderr': PIPE}

msg = "ERROR: Unable to communicate with master!\n"
msg = "ERROR: Unable to communicate with master!" + os.linesep

output = Popen([cmd, 'bw', 'chatter'], **kwds).communicate()[1].decode()
self.assert_(output.endswith(msg))
Expand Down

0 comments on commit d3991ab

Please sign in to comment.