Skip to content

Commit

Permalink
[jsk_rosbag_tools] Split test to avoid indigo's error
Browse files Browse the repository at this point in the history
  • Loading branch information
iory committed Jun 28, 2022
1 parent 1ba8c6a commit 6d055a9
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 36 deletions.
6 changes: 6 additions & 0 deletions jsk_rosbag_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if(CATKIN_ENABLE_TESTING)

set(python_test_scripts
tests/test_jsk_rosbag_tools.py
tests/test_bag_to_video.py
)

roslint_python()
Expand All @@ -47,4 +48,9 @@ if(CATKIN_ENABLE_TESTING)

add_rostest(tests/test_jsk_rosbag_tools.test
DEPENDENCIES download_audio_data download_video_data)
if("$ENV{ROS_DISTRO}" STRGREATER "indigo")
# could not install moviepy on indigo.
add_rostest(tests/test_bag_to_video.test
DEPENDENCIES download_audio_data download_video_data)
endif()
endif()
66 changes: 66 additions & 0 deletions jsk_rosbag_tools/tests/test_bag_to_video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python

import os.path as osp
import subprocess
import unittest

import rospkg
import rospy


PKG = 'jsk_rosbag_tools'
NAME = 'test_bag_to_video'


class TestBagToVideo(unittest.TestCase):

def _check_command(self, cmd):
proc = subprocess.Popen(cmd, shell=True,
stdout=subprocess.PIPE)
with proc.stdout:
for line in iter(proc.stdout.readline, b''):
rospy.loginfo('{}'.format(line.decode('utf-8').strip()))
returncode = proc.wait()

if returncode != 0:
raise RuntimeError('command {} failed.'.format(cmd))

def test_bag_to_video_and_video_to_bag_and_compress(self):
rospack = rospkg.RosPack()
path = rospack.get_path('jsk_rosbag_tools')

output_dir = osp.join(path, 'tests', 'output', 'audio')
audio_bag_path = osp.join(path, 'samples', 'data',
'2022-05-07-hello-test.bag')

cmd = 'rosrun jsk_rosbag_tools bag_to_video.py {} -o {}'.format(
audio_bag_path, output_dir)
self._check_command(cmd)

output_dir = osp.join(path, 'tests', 'output', 'video')
video_bag_path = osp.join(path, 'samples', 'data',
'20220530173950_go_to_kitchen_rosbag.bag')
cmd = 'rosrun jsk_rosbag_tools bag_to_video.py {} -o {}'.format(
video_bag_path, output_dir)
self._check_command(cmd)

# video_to_bag.py test
video_path = osp.join(
output_dir,
'head_camera--slash--rgb--slash--throttled'
'--slash--image_rect_color--slash--compressed.mp4')
output_filename = osp.join(path, 'tests', 'output', 'video_to_bag.bag')
cmd = 'rosrun jsk_rosbag_tools video_to_bag.py {} ' \
'--out {} --no-progress-bar'.format(
video_path, output_filename)
self._check_command(cmd)

# compress_imgs.py test
cmd = 'rosrun jsk_rosbag_tools compress_imgs.py {} ' \
'--no-progress-bar'.format(output_filename)
self._check_command(cmd)


if __name__ == '__main__':
import rostest
rostest.rosrun(PKG, NAME, TestBagToVideo)
7 changes: 7 additions & 0 deletions jsk_rosbag_tools/tests/test_bag_to_video.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" ?>
<launch>

<test test-name="test_bag_to_video" pkg="jsk_rosbag_tools" type="test_bag_to_video.py"
time-limit="360.0" />

</launch>
35 changes: 0 additions & 35 deletions jsk_rosbag_tools/tests/test_jsk_rosbag_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,41 +54,6 @@ def test_merge(self):
.format(audio_bag_path, audio_bag_path, output_path)
self._check_command(cmd)

def test_bag_to_video_and_video_to_bag_and_compress(self):
rospack = rospkg.RosPack()
path = rospack.get_path('jsk_rosbag_tools')

output_dir = osp.join(path, 'tests', 'output', 'audio')
audio_bag_path = osp.join(path, 'samples', 'data',
'2022-05-07-hello-test.bag')

cmd = 'rosrun jsk_rosbag_tools bag_to_video.py {} -o {}'.format(
audio_bag_path, output_dir)
self._check_command(cmd)

output_dir = osp.join(path, 'tests', 'output', 'video')
video_bag_path = osp.join(path, 'samples', 'data',
'20220530173950_go_to_kitchen_rosbag.bag')
cmd = 'rosrun jsk_rosbag_tools bag_to_video.py {} -o {}'.format(
video_bag_path, output_dir)
self._check_command(cmd)

# video_to_bag.py test
video_path = osp.join(
output_dir,
'head_camera--slash--rgb--slash--throttled'
'--slash--image_rect_color--slash--compressed.mp4')
output_filename = osp.join(path, 'tests', 'output', 'video_to_bag.bag')
cmd = 'rosrun jsk_rosbag_tools video_to_bag.py {} ' \
'--out {} --no-progress-bar'.format(
video_path, output_filename)
self._check_command(cmd)

# compress_imgs.py test
cmd = 'rosrun jsk_rosbag_tools compress_imgs.py {} ' \
'--no-progress-bar'.format(output_filename)
self._check_command(cmd)


if __name__ == '__main__':
import rostest
Expand Down
2 changes: 1 addition & 1 deletion jsk_rosbag_tools/tests/test_jsk_rosbag_tools.test
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" ?>
<launch>

<test test-name="test_bag_to_video" pkg="jsk_rosbag_tools" type="test_jsk_rosbag_tools.py"
<test test-name="test_jsk_rosbag_tools" pkg="jsk_rosbag_tools" type="test_jsk_rosbag_tools.py"
time-limit="360.0" />

</launch>

0 comments on commit 6d055a9

Please sign in to comment.