From 32d632c93ed6b223503d5cd34353a1898190167d Mon Sep 17 00:00:00 2001 From: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> Date: Mon, 19 Dec 2022 16:30:43 +0900 Subject: [PATCH 01/10] add quiet mode to info verb Signed-off-by: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> --- ros2bag/ros2bag/verb/info.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ros2bag/ros2bag/verb/info.py b/ros2bag/ros2bag/verb/info.py index f29b62dc7..c4167be7d 100644 --- a/ros2bag/ros2bag/verb/info.py +++ b/ros2bag/ros2bag/verb/info.py @@ -21,8 +21,15 @@ class InfoVerb(VerbExtension): """Print information about a bag to the screen.""" def add_arguments(self, parser, cli_name): # noqa: D102 - add_standard_reader_args(parser) + parser.add_argument( + '-q', '--quiet', action='store_true', + help='Only display topic names.' + ) def main(self, *, args): # noqa: D102 m = Info().read_metadata(args.bag_path, args.storage) - print(m) + if args.quiet: + for topic_info in m.topics_with_message_count: + print(topic_info.topic_metadata.name) + else: + print(m) From c8db9fbb6753402623cb6f81e1510e71715a4bb3 Mon Sep 17 00:00:00 2001 From: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> Date: Tue, 20 Dec 2022 16:16:48 +0900 Subject: [PATCH 02/10] revert standard_reader_args Signed-off-by: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> --- ros2bag/ros2bag/verb/info.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ros2bag/ros2bag/verb/info.py b/ros2bag/ros2bag/verb/info.py index c4167be7d..7ac9b10a2 100644 --- a/ros2bag/ros2bag/verb/info.py +++ b/ros2bag/ros2bag/verb/info.py @@ -21,6 +21,7 @@ class InfoVerb(VerbExtension): """Print information about a bag to the screen.""" def add_arguments(self, parser, cli_name): # noqa: D102 + add_standard_reader_args(parser) parser.add_argument( '-q', '--quiet', action='store_true', help='Only display topic names.' From c5b64c221fa46e4cd86a703131f903647d3986cd Mon Sep 17 00:00:00 2001 From: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> Date: Tue, 20 Dec 2022 16:17:30 +0900 Subject: [PATCH 03/10] change argument name to topic_name Signed-off-by: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> --- ros2bag/ros2bag/verb/info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros2bag/ros2bag/verb/info.py b/ros2bag/ros2bag/verb/info.py index 7ac9b10a2..a8df4ee23 100644 --- a/ros2bag/ros2bag/verb/info.py +++ b/ros2bag/ros2bag/verb/info.py @@ -23,7 +23,7 @@ class InfoVerb(VerbExtension): def add_arguments(self, parser, cli_name): # noqa: D102 add_standard_reader_args(parser) parser.add_argument( - '-q', '--quiet', action='store_true', + '-t', '--topic_name', action='store_true', help='Only display topic names.' ) From 9014a160ef3e55cd028f0bb2dd54f39f1625cfb5 Mon Sep 17 00:00:00 2001 From: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> Date: Tue, 20 Dec 2022 17:50:57 +0900 Subject: [PATCH 04/10] fix argument Signed-off-by: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> --- ros2bag/ros2bag/verb/info.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ros2bag/ros2bag/verb/info.py b/ros2bag/ros2bag/verb/info.py index a8df4ee23..7b78730ed 100644 --- a/ros2bag/ros2bag/verb/info.py +++ b/ros2bag/ros2bag/verb/info.py @@ -23,13 +23,13 @@ class InfoVerb(VerbExtension): def add_arguments(self, parser, cli_name): # noqa: D102 add_standard_reader_args(parser) parser.add_argument( - '-t', '--topic_name', action='store_true', + '-t', '--topic-name', action='store_true', help='Only display topic names.' ) def main(self, *, args): # noqa: D102 m = Info().read_metadata(args.bag_path, args.storage) - if args.quiet: + if args.topic_name: for topic_info in m.topics_with_message_count: print(topic_info.topic_metadata.name) else: From a1b450ddd53b9afceabec18bf0e12059709a7381 Mon Sep 17 00:00:00 2001 From: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> Date: Wed, 21 Dec 2022 15:40:02 +0900 Subject: [PATCH 05/10] add tests Signed-off-by: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> --- ros2bag/test/test_info.py | 88 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 ros2bag/test/test_info.py diff --git a/ros2bag/test/test_info.py b/ros2bag/test/test_info.py new file mode 100644 index 000000000..031d3952b --- /dev/null +++ b/ros2bag/test/test_info.py @@ -0,0 +1,88 @@ +# Copyright 2022 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import contextlib +from pathlib import Path +import unittest + +from launch import LaunchDescription +from launch.actions import ExecuteProcess +import launch_testing +import launch_testing.actions + +import pytest + + +RESOURCES_PATH = Path(__file__).parent / 'resources' +EXPECTED_OUTPUT = """ +Files: empty_bag_0.db3 +Bag size: 49.1 KiB +Storage id: sqlite3 +Duration: 0.0s +Start: Apr 12 2262 08:47:16.854 (9223372036.854) +End: Apr 12 2262 08:47:16.854 (9223372036.854) +Messages: 0 +Topic information: Topic: /parameter_events | Type: rcl_interfaces/msg/ParameterEvent \ +| Count: 0 | Serialization Format: cdr + Topic: /rosout | Type: rcl_interfaces/msg/Log \ +| Count: 0 | Serialization Format: cdr + +""" +EXPECTED_TOPIC_NAME_OUTPUT = """/parameter_events +/rosout +""" + + +@pytest.mark.rostest +@launch_testing.markers.keep_alive +def generate_test_description(): + return LaunchDescription([launch_testing.actions.ReadyToTest()]) + + +class TestRos2BagInfo(unittest.TestCase): + + @classmethod + def setUpClass(cls, launch_service, proc_info, proc_output): + @contextlib.contextmanager + def launch_bag_command(self, arguments, **kwargs): + pkg_command_action = ExecuteProcess( + cmd=['ros2', 'bag', *arguments], + additional_env={'PYTHONUNBUFFERED': '1'}, + name='ros2bag-cli', + output='screen', + **kwargs + ) + with launch_testing.tools.launch_process( + launch_service, pkg_command_action, proc_info, proc_output + ) as pkg_command: + yield pkg_command + cls.launch_bag_command = launch_bag_command + + def test_info_with_no_options(self): + """Test the output with no options.""" + bag_path = RESOURCES_PATH / 'empty_bag' + arguments = ['info', bag_path.as_posix()] + with self.launch_bag_command(arguments=arguments) as bag_command: + bag_command.wait_for_shutdown(timeout=5) + assert bag_command.output == EXPECTED_OUTPUT, \ + 'ros2bag CLI did not produce the expected output' + + def test_info_with_topic_name_option(self): + """Test the output with --topic-name options.""" + bag_path = RESOURCES_PATH / 'empty_bag' + arguments = ['info', '--topic-name', bag_path.as_posix()] + with self.launch_bag_command(arguments=arguments) as bag_command: + bag_command.wait_for_shutdown(timeout=5) + assert bag_command.output == EXPECTED_TOPIC_NAME_OUTPUT, \ + 'ros2bag CLI did not produce the expected output' From 6d94b7e7309e0d0c9a7c00fa7acbe308a28c036e Mon Sep 17 00:00:00 2001 From: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> Date: Wed, 21 Dec 2022 17:14:00 +0900 Subject: [PATCH 06/10] fix timezone Signed-off-by: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> --- ros2bag/test/test_info.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ros2bag/test/test_info.py b/ros2bag/test/test_info.py index 031d3952b..8c4954a6f 100644 --- a/ros2bag/test/test_info.py +++ b/ros2bag/test/test_info.py @@ -30,8 +30,8 @@ Bag size: 49.1 KiB Storage id: sqlite3 Duration: 0.0s -Start: Apr 12 2262 08:47:16.854 (9223372036.854) -End: Apr 12 2262 08:47:16.854 (9223372036.854) +Start: Apr 11 2262 23:47:16.854 (9223372036.854) +End: Apr 11 2262 23:47:16.854 (9223372036.854) Messages: 0 Topic information: Topic: /parameter_events | Type: rcl_interfaces/msg/ParameterEvent \ | Count: 0 | Serialization Format: cdr From f63713ded9d2335ab64634ed17abbeb090aaea03 Mon Sep 17 00:00:00 2001 From: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> Date: Wed, 21 Dec 2022 17:25:54 +0900 Subject: [PATCH 07/10] fix local test run Signed-off-by: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> --- ros2bag/test/test_info.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ros2bag/test/test_info.py b/ros2bag/test/test_info.py index 8c4954a6f..af49541ce 100644 --- a/ros2bag/test/test_info.py +++ b/ros2bag/test/test_info.py @@ -58,7 +58,10 @@ def setUpClass(cls, launch_service, proc_info, proc_output): def launch_bag_command(self, arguments, **kwargs): pkg_command_action = ExecuteProcess( cmd=['ros2', 'bag', *arguments], - additional_env={'PYTHONUNBUFFERED': '1'}, + additional_env={ + 'PYTHONUNBUFFERED': '1', + 'TZ': 'UTC', + }, name='ros2bag-cli', output='screen', **kwargs From 7a3db2fbd70eda70d9ccf2d75f2dc38f72a8439c Mon Sep 17 00:00:00 2001 From: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> Date: Thu, 22 Dec 2022 11:16:29 +0900 Subject: [PATCH 08/10] fix test error on windows Signed-off-by: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> --- ros2bag/test/test_info.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ros2bag/test/test_info.py b/ros2bag/test/test_info.py index af49541ce..ec0bea434 100644 --- a/ros2bag/test/test_info.py +++ b/ros2bag/test/test_info.py @@ -20,6 +20,7 @@ from launch.actions import ExecuteProcess import launch_testing import launch_testing.actions +from launch_testing.tools.text import normalize_lineseps import pytest @@ -78,7 +79,7 @@ def test_info_with_no_options(self): arguments = ['info', bag_path.as_posix()] with self.launch_bag_command(arguments=arguments) as bag_command: bag_command.wait_for_shutdown(timeout=5) - assert bag_command.output == EXPECTED_OUTPUT, \ + assert normalize_lineseps(bag_command.output) == EXPECTED_OUTPUT, \ 'ros2bag CLI did not produce the expected output' def test_info_with_topic_name_option(self): @@ -87,5 +88,5 @@ def test_info_with_topic_name_option(self): arguments = ['info', '--topic-name', bag_path.as_posix()] with self.launch_bag_command(arguments=arguments) as bag_command: bag_command.wait_for_shutdown(timeout=5) - assert bag_command.output == EXPECTED_TOPIC_NAME_OUTPUT, \ + assert normalize_lineseps(bag_command.output) == EXPECTED_TOPIC_NAME_OUTPUT, \ 'ros2bag CLI did not produce the expected output' From a7e57aa6333ad14b1771db37a1dc8a5332319c81 Mon Sep 17 00:00:00 2001 From: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> Date: Thu, 22 Dec 2022 16:45:17 +0900 Subject: [PATCH 09/10] delete test_info_with_no_options Signed-off-by: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> --- ros2bag/test/test_info.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/ros2bag/test/test_info.py b/ros2bag/test/test_info.py index ec0bea434..54b4d75c6 100644 --- a/ros2bag/test/test_info.py +++ b/ros2bag/test/test_info.py @@ -73,15 +73,6 @@ def launch_bag_command(self, arguments, **kwargs): yield pkg_command cls.launch_bag_command = launch_bag_command - def test_info_with_no_options(self): - """Test the output with no options.""" - bag_path = RESOURCES_PATH / 'empty_bag' - arguments = ['info', bag_path.as_posix()] - with self.launch_bag_command(arguments=arguments) as bag_command: - bag_command.wait_for_shutdown(timeout=5) - assert normalize_lineseps(bag_command.output) == EXPECTED_OUTPUT, \ - 'ros2bag CLI did not produce the expected output' - def test_info_with_topic_name_option(self): """Test the output with --topic-name options.""" bag_path = RESOURCES_PATH / 'empty_bag' From 34eb24559c65538593efc0681f0979f5b9378ba5 Mon Sep 17 00:00:00 2001 From: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> Date: Thu, 22 Dec 2022 17:08:15 +0900 Subject: [PATCH 10/10] delete unused variable Signed-off-by: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> --- ros2bag/test/test_info.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/ros2bag/test/test_info.py b/ros2bag/test/test_info.py index 54b4d75c6..f1bec7dd8 100644 --- a/ros2bag/test/test_info.py +++ b/ros2bag/test/test_info.py @@ -26,21 +26,7 @@ RESOURCES_PATH = Path(__file__).parent / 'resources' -EXPECTED_OUTPUT = """ -Files: empty_bag_0.db3 -Bag size: 49.1 KiB -Storage id: sqlite3 -Duration: 0.0s -Start: Apr 11 2262 23:47:16.854 (9223372036.854) -End: Apr 11 2262 23:47:16.854 (9223372036.854) -Messages: 0 -Topic information: Topic: /parameter_events | Type: rcl_interfaces/msg/ParameterEvent \ -| Count: 0 | Serialization Format: cdr - Topic: /rosout | Type: rcl_interfaces/msg/Log \ -| Count: 0 | Serialization Format: cdr - -""" -EXPECTED_TOPIC_NAME_OUTPUT = """/parameter_events +EXPECTED_OUTPUT = """/parameter_events /rosout """ @@ -79,5 +65,5 @@ def test_info_with_topic_name_option(self): arguments = ['info', '--topic-name', bag_path.as_posix()] with self.launch_bag_command(arguments=arguments) as bag_command: bag_command.wait_for_shutdown(timeout=5) - assert normalize_lineseps(bag_command.output) == EXPECTED_TOPIC_NAME_OUTPUT, \ + assert normalize_lineseps(bag_command.output) == EXPECTED_OUTPUT, \ 'ros2bag CLI did not produce the expected output'