From 5ab016b19ea8eb95fcf71c52f39669eff721f924 Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Mon, 28 Oct 2024 23:48:04 -0400 Subject: [PATCH] init (#1358) Signed-off-by: Michael Carlstrom Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- rclpy/test/test_action_client.py | 38 ++-- rclpy/test/test_action_graph.py | 6 +- rclpy/test/test_action_server.py | 48 ++--- rclpy/test/test_callback_group.py | 14 +- rclpy/test/test_client.py | 22 +-- rclpy/test/test_clock.py | 30 +-- rclpy/test/test_context.py | 10 +- rclpy/test/test_create_node.py | 16 +- rclpy/test/test_create_while_spinning.py | 22 +-- rclpy/test/test_destruction.py | 24 +-- rclpy/test/test_destruction_order.py | 2 +- rclpy/test/test_executor.py | 88 ++++----- rclpy/test/test_expand_topic_name.py | 10 +- rclpy/test/test_guard_condition.py | 10 +- rclpy/test/test_init_shutdown.py | 22 +-- rclpy/test/test_lifecycle.py | 8 +- rclpy/test/test_logging.py | 38 ++-- rclpy/test/test_logging_service.py | 16 +- rclpy/test/test_messages.py | 6 +- rclpy/test/test_node.py | 172 +++++++++--------- rclpy/test/test_parameter.py | 36 ++-- rclpy/test/test_parameter_event_handler.py | 30 +-- rclpy/test/test_parameter_service.py | 6 +- rclpy/test/test_publisher.py | 8 +- rclpy/test/test_qos.py | 26 +-- rclpy/test/test_qos_event.py | 22 +-- rclpy/test/test_qos_overriding_options.py | 12 +- rclpy/test/test_rate.py | 14 +- rclpy/test/test_rosout_subscription.py | 14 +- rclpy/test/test_serialization.py | 2 +- rclpy/test/test_service.py | 2 +- rclpy/test/test_service_introspection.py | 8 +- rclpy/test/test_subscription.py | 8 +- rclpy/test/test_task.py | 64 +++---- rclpy/test/test_time.py | 20 +- rclpy/test/test_time_source.py | 24 +-- rclpy/test/test_timer.py | 12 +- rclpy/test/test_topic_endpoint_info.py | 14 +- rclpy/test/test_topic_or_service_is_hidden.py | 2 +- rclpy/test/test_type_description_service.py | 6 +- rclpy/test/test_type_hash.py | 8 +- rclpy/test/test_type_support.py | 6 +- rclpy/test/test_utilities.py | 4 +- rclpy/test/test_validate_full_topic_name.py | 6 +- rclpy/test/test_validate_namespace.py | 4 +- rclpy/test/test_validate_node_name.py | 4 +- rclpy/test/test_validate_topic_name.py | 6 +- rclpy/test/test_wait_for_message.py | 8 +- rclpy/test/test_waitable.py | 24 +-- 49 files changed, 501 insertions(+), 501 deletions(-) diff --git a/rclpy/test/test_action_client.py b/rclpy/test/test_action_client.py index 6dfe71b0d..8e98685c8 100644 --- a/rclpy/test/test_action_client.py +++ b/rclpy/test/test_action_client.py @@ -31,7 +31,7 @@ TIME_FUDGE = 0.3 -class MockActionServer(): +class MockActionServer: def __init__(self, node): self.goal_srv = node.create_service( @@ -82,7 +82,7 @@ def tearDownClass(cls): cls.node.destroy_node() rclpy.shutdown(context=cls.context) - def setUp(self): + def setUp(self) -> None: self.feedback = None def feedback_callback(self, feedback): @@ -93,12 +93,12 @@ def timed_spin(self, duration): while (time.time() - start_time) < duration: rclpy.spin_once(self.node, executor=self.executor, timeout_sec=0.1) - def test_constructor_defaults(self): + def test_constructor_defaults(self) -> None: # Defaults ac = ActionClient(self.node, Fibonacci, 'fibonacci') ac.destroy() - def test_constructor_no_defaults(self): + def test_constructor_no_defaults(self) -> None: ac = ActionClient( self.node, Fibonacci, @@ -111,7 +111,7 @@ def test_constructor_no_defaults(self): ) ac.destroy() - def test_get_num_entities(self): + def test_get_num_entities(self) -> None: ac = ActionClient(self.node, Fibonacci, 'fibonacci') num_entities = ac.get_num_entities() self.assertEqual(num_entities.num_subscriptions, 2) @@ -121,7 +121,7 @@ def test_get_num_entities(self): self.assertEqual(num_entities.num_services, 0) ac.destroy() - def test_wait_for_server_nowait(self): + def test_wait_for_server_nowait(self) -> None: ac = ActionClient(self.node, Fibonacci, 'not_fibonacci') try: start = time.monotonic() @@ -132,7 +132,7 @@ def test_wait_for_server_nowait(self): finally: ac.destroy() - def test_wait_for_server_timeout(self): + def test_wait_for_server_timeout(self) -> None: ac = ActionClient(self.node, Fibonacci, 'not_fibonacci') try: start = time.monotonic() @@ -143,7 +143,7 @@ def test_wait_for_server_timeout(self): finally: ac.destroy() - def test_wait_for_server_exists(self): + def test_wait_for_server_exists(self) -> None: ac = ActionClient(self.node, Fibonacci, 'fibonacci') try: start = time.monotonic() @@ -154,7 +154,7 @@ def test_wait_for_server_exists(self): finally: ac.destroy() - def test_send_goal_async(self): + def test_send_goal_async(self) -> None: ac = ActionClient(self.node, Fibonacci, 'fibonacci') try: self.assertTrue(ac.wait_for_server(timeout_sec=2.0)) @@ -166,7 +166,7 @@ def test_send_goal_async(self): finally: ac.destroy() - def test_send_goal_async_with_feedback_after_goal(self): + def test_send_goal_async_with_feedback_after_goal(self) -> None: ac = ActionClient(self.node, Fibonacci, 'fibonacci') try: self.assertTrue(ac.wait_for_server(timeout_sec=2.0)) @@ -186,7 +186,7 @@ def test_send_goal_async_with_feedback_after_goal(self): finally: ac.destroy() - def test_send_goal_async_with_feedback_before_goal(self): + def test_send_goal_async_with_feedback_before_goal(self) -> None: ac = ActionClient(self.node, Fibonacci, 'fibonacci') try: self.assertTrue(ac.wait_for_server(timeout_sec=2.0)) @@ -209,7 +209,7 @@ def test_send_goal_async_with_feedback_before_goal(self): finally: ac.destroy() - def test_send_goal_async_with_feedback_after_goal_result_requested(self): + def test_send_goal_async_with_feedback_after_goal_result_requested(self) -> None: ac = ActionClient(self.node, Fibonacci, 'fibonacci') try: self.assertTrue(ac.wait_for_server(timeout_sec=2.0)) @@ -235,7 +235,7 @@ def test_send_goal_async_with_feedback_after_goal_result_requested(self): finally: ac.destroy() - def test_send_goal_async_with_feedback_for_another_goal(self): + def test_send_goal_async_with_feedback_for_another_goal(self) -> None: ac = ActionClient(self.node, Fibonacci, 'fibonacci') try: self.assertTrue(ac.wait_for_server(timeout_sec=2.0)) @@ -266,7 +266,7 @@ def test_send_goal_async_with_feedback_for_another_goal(self): finally: ac.destroy() - def test_send_goal_async_with_feedback_for_not_a_goal(self): + def test_send_goal_async_with_feedback_for_not_a_goal(self) -> None: ac = ActionClient(self.node, Fibonacci, 'fibonacci') try: self.assertTrue(ac.wait_for_server(timeout_sec=2.0)) @@ -286,7 +286,7 @@ def test_send_goal_async_with_feedback_for_not_a_goal(self): finally: ac.destroy() - def test_send_goal_multiple(self): + def test_send_goal_multiple(self) -> None: ac = ActionClient( self.node, Fibonacci, @@ -310,7 +310,7 @@ def test_send_goal_multiple(self): finally: ac.destroy() - def test_send_goal_async_no_server(self): + def test_send_goal_async_no_server(self) -> None: ac = ActionClient(self.node, Fibonacci, 'not_fibonacci') try: future = ac.send_goal_async(Fibonacci.Goal()) @@ -319,7 +319,7 @@ def test_send_goal_async_no_server(self): finally: ac.destroy() - def test_send_cancel_async(self): + def test_send_cancel_async(self) -> None: ac = ActionClient(self.node, Fibonacci, 'fibonacci') try: self.assertTrue(ac.wait_for_server(timeout_sec=2.0)) @@ -340,7 +340,7 @@ def test_send_cancel_async(self): finally: ac.destroy() - def test_get_result_async(self): + def test_get_result_async(self) -> None: ac = ActionClient(self.node, Fibonacci, 'fibonacci') try: self.assertTrue(ac.wait_for_server(timeout_sec=2.0)) @@ -358,7 +358,7 @@ def test_get_result_async(self): finally: ac.destroy() - def test_different_type_raises(self): + def test_different_type_raises(self) -> None: ac = ActionClient(self.node, Fibonacci, 'fibonacci') try: with self.assertRaises(TypeError): diff --git a/rclpy/test/test_action_graph.py b/rclpy/test/test_action_graph.py index ef1891c58..75fc8ab8a 100644 --- a/rclpy/test/test_action_graph.py +++ b/rclpy/test/test_action_graph.py @@ -87,7 +87,7 @@ def get_names_and_types( end = time.monotonic() assert len(nat) == expected_num_names - def test_get_action_client_names_and_types_by_node(self): + def test_get_action_client_names_and_types_by_node(self) -> None: self.get_names_and_types( get_action_client_names_and_types_by_node, self.node1, @@ -128,7 +128,7 @@ def test_get_action_client_names_and_types_by_node(self): assert TEST_NAMESPACE2 + '/' + TEST_ACTION0 in [name20, name21] assert TEST_NAMESPACE2 + '/' + TEST_ACTION1 in [name20, name21] - def test_get_action_server_names_and_types_by_node(self): + def test_get_action_server_names_and_types_by_node(self) -> None: self.get_names_and_types( get_action_server_names_and_types_by_node, self.node1, @@ -170,7 +170,7 @@ def test_get_action_server_names_and_types_by_node(self): assert TEST_NAMESPACE2 + '/' + TEST_ACTION0 in [name20, name21] assert TEST_NAMESPACE2 + '/' + TEST_ACTION1 in [name20, name21] - def test_get_action_names_and_types(self): + def test_get_action_names_and_types(self) -> None: names_and_types = self.get_names_and_types( get_action_names_and_types, self.node0, diff --git a/rclpy/test/test_action_server.py b/rclpy/test/test_action_server.py index fa2af1e74..648dd30f6 100644 --- a/rclpy/test/test_action_server.py +++ b/rclpy/test/test_action_server.py @@ -29,7 +29,7 @@ from unique_identifier_msgs.msg import UUID -class MockActionClient(): +class MockActionClient: def __init__(self, node): self.reset() @@ -47,7 +47,7 @@ def __init__(self, node): self.status_sub = node.create_subscription( Fibonacci.Impl.GoalStatusMessage, '/fibonacci/_action/status', self.status_callback, 1) - def reset(self): + def reset(self) -> None: self.feedback_msg = None self.status_msg = None @@ -71,14 +71,14 @@ def get_result(self, goal_uuid): class TestActionServer(unittest.TestCase): - def setUp(self): + def setUp(self) -> None: self.context = rclpy.context.Context() rclpy.init(context=self.context) self.executor = SingleThreadedExecutor(context=self.context) self.node = rclpy.create_node('TestActionServer', context=self.context) self.mock_action_client = MockActionClient(self.node) - def tearDown(self): + def tearDown(self) -> None: self.node.destroy_node() self.executor.shutdown() rclpy.shutdown(context=self.context) @@ -92,7 +92,7 @@ def execute_goal_callback(self, goal_handle): goal_handle.succeed() return Fibonacci.Result() - def test_constructor_defaults(self): + def test_constructor_defaults(self) -> None: # Defaults action_server = ActionServer( self.node, @@ -102,7 +102,7 @@ def test_constructor_defaults(self): ) action_server.destroy() - def test_constructor_no_defaults(self): + def test_constructor_no_defaults(self) -> None: action_server = ActionServer( self.node, Fibonacci, @@ -121,7 +121,7 @@ def test_constructor_no_defaults(self): ) action_server.destroy() - def test_get_num_entities(self): + def test_get_num_entities(self) -> None: action_server = ActionServer( self.node, Fibonacci, @@ -136,7 +136,7 @@ def test_get_num_entities(self): self.assertEqual(num_entities.num_services, 3) action_server.destroy() - def test_single_goal_accept(self): + def test_single_goal_accept(self) -> None: goal_uuid = UUID(uuid=list(uuid.uuid4().bytes)) goal_order = 10 @@ -174,7 +174,7 @@ def handle_accepted_callback(goal_handle): self.assertTrue(handle_accepted_callback_triggered) action_server.destroy() - def test_single_goal_reject(self): + def test_single_goal_reject(self) -> None: goal_order = 10 def goal_callback(goal): @@ -203,7 +203,7 @@ def handle_accepted_callback(goal_handle): self.assertFalse(future.result().accepted) action_server.destroy() - def test_goal_callback_invalid_return(self): + def test_goal_callback_invalid_return(self) -> None: def goal_callback(goal): return 'Invalid return type' @@ -225,7 +225,7 @@ def goal_callback(goal): self.assertFalse(future.result().accepted) action_server.destroy() - def test_multi_goal_accept(self): + def test_multi_goal_accept(self) -> None: executor = MultiThreadedExecutor(context=self.context) action_server = ActionServer( self.node, @@ -253,7 +253,7 @@ def test_multi_goal_accept(self): self.assertTrue(future2.result().accepted) action_server.destroy() - def test_duplicate_goal(self): + def test_duplicate_goal(self) -> None: executor = MultiThreadedExecutor(context=self.context) action_server = ActionServer( self.node, @@ -277,7 +277,7 @@ def test_duplicate_goal(self): self.assertNotEqual(future0.result().accepted, future1.result().accepted) action_server.destroy() - def test_cancel_goal_accept(self): + def test_cancel_goal_accept(self) -> None: def execute_callback(goal_handle): # Wait, to give the opportunity to cancel @@ -323,7 +323,7 @@ def cancel_callback(request): action_server.destroy() executor.shutdown() - def test_cancel_goal_reject(self): + def test_cancel_goal_reject(self) -> None: def execute_callback(goal_handle): # Wait, to give the opportunity to cancel @@ -368,7 +368,7 @@ def cancel_callback(request): action_server.destroy() executor.shutdown() - def test_cancel_defered_goal(self): + def test_cancel_defered_goal(self) -> None: server_goal_handle = None def handle_accepted_callback(gh): @@ -427,7 +427,7 @@ def execute_callback(gh): self.assertEqual(server_goal_handle.status, GoalStatus.STATUS_CANCELED) action_server.destroy() - def test_execute_succeed(self): + def test_execute_succeed(self) -> None: def execute_callback(goal_handle): self.assertEqual(goal_handle.status, GoalStatus.STATUS_EXECUTING) @@ -458,7 +458,7 @@ def execute_callback(goal_handle): self.assertEqual(result_response.result.sequence.tolist(), [1, 1, 2, 3, 5]) action_server.destroy() - def test_execute_abort(self): + def test_execute_abort(self) -> None: def execute_callback(goal_handle): self.assertEqual(goal_handle.status, GoalStatus.STATUS_EXECUTING) @@ -489,7 +489,7 @@ def execute_callback(goal_handle): self.assertEqual(result_response.result.sequence.tolist(), [1, 1, 2, 3, 5]) action_server.destroy() - def test_execute_no_terminal_state(self): + def test_execute_no_terminal_state(self) -> None: def execute_callback(goal_handle): # Do not set the goal handles state @@ -520,7 +520,7 @@ def execute_callback(goal_handle): self.assertEqual(result_response.result.sequence.tolist(), [1, 1, 2, 3, 5]) action_server.destroy() - def test_execute_raises_exception(self): + def test_execute_raises_exception(self) -> None: def execute_callback(goal_handle): # User callback raises @@ -549,7 +549,7 @@ def execute_callback(goal_handle): self.assertEqual(result_response.result.sequence.tolist(), []) action_server.destroy() - def test_expire_goals_none(self): + def test_expire_goals_none(self) -> None: # 1 second timeout action_server = ActionServer( @@ -572,7 +572,7 @@ def test_expire_goals_none(self): self.assertEqual(1, len(action_server._goal_handles)) action_server.destroy() - def test_expire_goals_one(self): + def test_expire_goals_one(self) -> None: # 1 second timeout action_server = ActionServer( @@ -595,7 +595,7 @@ def test_expire_goals_one(self): self.assertEqual(0, len(action_server._goal_handles)) action_server.destroy() - def test_expire_goals_multi(self): + def test_expire_goals_multi(self) -> None: # 1 second timeout action_server = ActionServer( self.node, @@ -622,7 +622,7 @@ def test_expire_goals_multi(self): self.assertEqual(0, len(action_server._goal_handles)) action_server.destroy() - def test_feedback(self): + def test_feedback(self) -> None: def execute_with_feedback(goal_handle): feedback = Fibonacci.Feedback() @@ -650,7 +650,7 @@ def execute_with_feedback(goal_handle): self.mock_action_client.feedback_msg.feedback.sequence.tolist()) action_server.destroy() - def test_different_feedback_type_raises(self): + def test_different_feedback_type_raises(self) -> None: def execute_with_feedback(goal_handle): try: diff --git a/rclpy/test/test_callback_group.py b/rclpy/test/test_callback_group.py index 8a49c346a..c5c87319a 100644 --- a/rclpy/test/test_callback_group.py +++ b/rclpy/test/test_callback_group.py @@ -37,7 +37,7 @@ def tearDownClass(cls): cls.node.destroy_node() rclpy.shutdown(context=cls.context) - def test_reentrant_group(self): + def test_reentrant_group(self) -> None: self.assertIsNotNone(self.node.handle) group = ReentrantCallbackGroup() t1 = self.node.create_timer(1.0, lambda: None, callback_group=group) @@ -48,7 +48,7 @@ def test_reentrant_group(self): self.assertTrue(group.beginning_execution(t1)) self.assertTrue(group.beginning_execution(t2)) - def test_reentrant_group_not_blocking(self): + def test_reentrant_group_not_blocking(self) -> None: self.assertIsNotNone(self.node.handle) # Create multithreaded executor needed for parallel callback handling executor = MultiThreadedExecutor(num_threads=2, context=self.context) @@ -129,7 +129,7 @@ def long_callback(msg): finally: executor.shutdown() - def test_mutually_exclusive_group(self): + def test_mutually_exclusive_group(self) -> None: self.assertIsNotNone(self.node.handle) group = MutuallyExclusiveCallbackGroup() t1 = self.node.create_timer(1.0, lambda: None, callback_group=group) @@ -146,7 +146,7 @@ def test_mutually_exclusive_group(self): self.assertTrue(group.can_execute(t2)) self.assertTrue(group.beginning_execution(t2)) - def test_create_timer_with_group(self): + def test_create_timer_with_group(self) -> None: tmr1 = self.node.create_timer(1.0, lambda: None) group = ReentrantCallbackGroup() tmr2 = self.node.create_timer(1.0, lambda: None, callback_group=group) @@ -154,7 +154,7 @@ def test_create_timer_with_group(self): self.assertFalse(group.has_entity(tmr1)) self.assertTrue(group.has_entity(tmr2)) - def test_create_subscription_with_group(self): + def test_create_subscription_with_group(self) -> None: sub1 = self.node.create_subscription(BasicTypes, 'chatter', lambda msg: print(msg), 1) group = ReentrantCallbackGroup() sub2 = self.node.create_subscription( @@ -163,7 +163,7 @@ def test_create_subscription_with_group(self): self.assertFalse(group.has_entity(sub1)) self.assertTrue(group.has_entity(sub2)) - def test_create_client_with_group(self): + def test_create_client_with_group(self) -> None: cli1 = self.node.create_client(GetParameters, 'get/parameters') group = ReentrantCallbackGroup() cli2 = self.node.create_client(GetParameters, 'get/parameters', callback_group=group) @@ -171,7 +171,7 @@ def test_create_client_with_group(self): self.assertFalse(group.has_entity(cli1)) self.assertTrue(group.has_entity(cli2)) - def test_create_service_with_group(self): + def test_create_service_with_group(self) -> None: srv1 = self.node.create_service(GetParameters, 'get/parameters', lambda req: None) group = ReentrantCallbackGroup() srv2 = self.node.create_service( diff --git a/rclpy/test/test_client.py b/rclpy/test/test_client.py index 3fddf7629..a0cf51c20 100644 --- a/rclpy/test/test_client.py +++ b/rclpy/test/test_client.py @@ -74,7 +74,7 @@ def _spin_rclpy_node( print(rclpy_node.get_name() + ': rclpy_node exit') # rclpy_node.destroy_node() - def test_wait_for_service_5sec(self): + def test_wait_for_service_5sec(self) -> None: cli = self.node.create_client(GetParameters, 'get/parameters') try: start = time.monotonic() @@ -85,7 +85,7 @@ def test_wait_for_service_5sec(self): finally: self.node.destroy_client(cli) - def test_wait_for_service_nowait(self): + def test_wait_for_service_nowait(self) -> None: cli = self.node.create_client(GetParameters, 'get/parameters') try: start = time.monotonic() @@ -96,7 +96,7 @@ def test_wait_for_service_nowait(self): finally: self.node.destroy_client(cli) - def test_wait_for_service_exists(self): + def test_wait_for_service_exists(self) -> None: cli = self.node.create_client(GetParameters, 'test_wfs_exists') srv = self.node.create_service(GetParameters, 'test_wfs_exists', lambda request: None) try: @@ -109,7 +109,7 @@ def test_wait_for_service_exists(self): self.node.destroy_client(cli) self.node.destroy_service(srv) - def test_concurrent_calls_to_service(self): + def test_concurrent_calls_to_service(self) -> None: cli = self.node.create_client(GetParameters, 'get/parameters') srv = self.node.create_service( GetParameters, 'get/parameters', @@ -130,7 +130,7 @@ def test_concurrent_calls_to_service(self): @unittest.skipIf( get_rmw_implementation_identifier() == 'rmw_connextdds' and platform.system() == 'Windows', reason='Source timestamp not implemented for Connext on Windows') - def test_service_timestamps(self): + def test_service_timestamps(self) -> None: cli = self.node.create_client(GetParameters, 'get/parameters') srv = self.node.create_service( GetParameters, 'get/parameters', @@ -153,7 +153,7 @@ def test_service_timestamps(self): self.node.destroy_client(cli) self.node.destroy_service(srv) - def test_different_type_raises(self): + def test_different_type_raises(self) -> None: cli = self.node.create_client(GetParameters, 'get/parameters') srv = self.node.create_service( GetParameters, 'get/parameters', @@ -172,7 +172,7 @@ def test_different_type_raises(self): self.node.destroy_client(cli) self.node.destroy_service(srv) - def test_get_service_name(self): + def test_get_service_name(self) -> None: test_service_name_list = [ # test_service_name, namespace, cli_args for remap, expected service name # No namespaces @@ -189,7 +189,7 @@ def test_get_service_name(self): ] TestClient.do_test_service_name(test_service_name_list) - def test_get_service_name_after_remapping(self): + def test_get_service_name_after_remapping(self) -> None: test_service_name_list = [ ('service', None, ['--ros-args', '--remap', 'service:=new_service'], '/new_service'), ('service', 'ns', ['--ros-args', '--remap', 'service:=new_service'], @@ -201,7 +201,7 @@ def test_get_service_name_after_remapping(self): ] TestClient.do_test_service_name(test_service_name_list) - def test_sync_call(self): + def test_sync_call(self) -> None: def _service(request, response): return response cli = self.node.create_client(GetParameters, 'get/parameters') @@ -221,7 +221,7 @@ def _service(request, response): self.node.destroy_client(cli) self.node.destroy_service(srv) - def test_sync_call_timeout(self): + def test_sync_call_timeout(self) -> None: def _service(request, response): time.sleep(1) return response @@ -242,7 +242,7 @@ def _service(request, response): self.node.destroy_client(cli) self.node.destroy_service(srv) - def test_sync_call_context_manager(self): + def test_sync_call_context_manager(self) -> None: def _service(request, response): return response with self.node.create_client(GetParameters, 'get/parameters') as cli: diff --git a/rclpy/test/test_clock.py b/rclpy/test/test_clock.py index 7811b5cca..4e860595c 100644 --- a/rclpy/test/test_clock.py +++ b/rclpy/test/test_clock.py @@ -34,7 +34,7 @@ A_SMALL_AMOUNT_OF_TIME = Duration(seconds=0.5) -def test_invalid_jump_threshold(): +def test_invalid_jump_threshold() -> None: with pytest.raises(ValueError, match='.*min_forward.*'): JumpThreshold( min_forward=Duration(nanoseconds=0), @@ -64,7 +64,7 @@ def test_invalid_jump_threshold(): class TestClock(unittest.TestCase): - def test_clock_construction(self): + def test_clock_construction(self) -> None: clock = Clock() with self.assertRaises(TypeError): @@ -83,7 +83,7 @@ def test_clock_construction(self): clock = ROSClock() assert clock.clock_type == ClockType.ROS_TIME - def test_clock_now(self): + def test_clock_now(self) -> None: # System time should be roughly equal to time.time() # There will still be differences between them, with the bound depending on the scheduler. clock = Clock(clock_type=ClockType.SYSTEM_TIME) @@ -106,14 +106,14 @@ def test_clock_now(self): assert now2 > now now = now2 - def test_ros_time_is_active(self): + def test_ros_time_is_active(self) -> None: clock = ROSClock() clock._set_ros_time_is_active(True) assert clock.ros_time_is_active clock._set_ros_time_is_active(False) assert not clock.ros_time_is_active - def test_triggered_time_jump_callbacks(self): + def test_triggered_time_jump_callbacks(self) -> None: one_second = Duration(seconds=1) half_second = Duration(seconds=0.5) negative_half_second = Duration(seconds=-0.5) @@ -164,7 +164,7 @@ def test_triggered_time_jump_callbacks(self): handler1.unregister() handler2.unregister() - def test_triggered_clock_change_callbacks(self): + def test_triggered_clock_change_callbacks(self) -> None: one_second = Duration(seconds=1) negative_one_second = Duration(seconds=-1) @@ -248,13 +248,13 @@ def test_sleep_for_non_default_context(non_default_context): assert clock.sleep_for(Duration(seconds=0.1), context=non_default_context) -def test_sleep_until_invalid_context(): +def test_sleep_until_invalid_context() -> None: clock = Clock() with pytest.raises(NotInitializedException): clock.sleep_until(clock.now() + Duration(seconds=0.1), context=Context()) -def test_sleep_for_invalid_context(): +def test_sleep_for_invalid_context() -> None: clock = Clock() with pytest.raises(NotInitializedException): clock.sleep_for(Duration(seconds=0.1), context=Context()) @@ -311,7 +311,7 @@ def test_sleep_until_ros_time_toggled(default_context, ros_time_enabled): retval = None - def run(): + def run() -> None: nonlocal retval retval = clock.sleep_until(clock.now() + Duration(seconds=10)) @@ -339,7 +339,7 @@ def test_sleep_for_ros_time_toggled(default_context, ros_time_enabled): retval = None - def run(): + def run() -> None: nonlocal retval retval = clock.sleep_for(Duration(seconds=10)) @@ -364,7 +364,7 @@ def test_sleep_until_context_shut_down(non_default_context): clock = Clock() retval = None - def run(): + def run() -> None: nonlocal retval retval = clock.sleep_until( clock.now() + Duration(seconds=10), context=non_default_context) @@ -390,7 +390,7 @@ def test_sleep_for_context_shut_down(non_default_context): clock = Clock() retval = None - def run(): + def run() -> None: nonlocal retval retval = clock.sleep_for(Duration(seconds=10), context=non_default_context) @@ -421,7 +421,7 @@ def test_sleep_until_ros_time_enabled(default_context): retval = None - def run(): + def run() -> None: nonlocal retval retval = clock.sleep_until(stop_time) @@ -453,7 +453,7 @@ def test_sleep_for_ros_time_enabled(default_context): retval = None - def run(): + def run() -> None: nonlocal retval retval = clock.sleep_for(sleep_duration) @@ -474,7 +474,7 @@ def run(): assert retval -def test_with_jump_handle(): +def test_with_jump_handle() -> None: clock = ROSClock() clock._set_ros_time_is_active(False) diff --git a/rclpy/test/test_context.py b/rclpy/test/test_context.py index 7831597fd..d3dcadf5c 100644 --- a/rclpy/test/test_context.py +++ b/rclpy/test/test_context.py @@ -15,7 +15,7 @@ from rclpy.context import Context -def test_on_shutdown_method(): +def test_on_shutdown_method() -> None: context = Context() context.init() assert context.ok() @@ -24,7 +24,7 @@ def test_on_shutdown_method(): class SomeClass: - def on_shutdown(self): + def on_shutdown(self) -> None: nonlocal callback_called callback_called = True @@ -37,14 +37,14 @@ def on_shutdown(self): assert callback_called -def test_on_shutdown_function(): +def test_on_shutdown_function() -> None: context = Context() context.init() assert context.ok() callback_called = False - def on_shutdown(): + def on_shutdown() -> None: nonlocal callback_called callback_called = True @@ -56,7 +56,7 @@ def on_shutdown(): assert callback_called -def test_context_manager(): +def test_context_manager() -> None: context = Context() assert not context.ok(), 'the context should not be ok() before init() is called' diff --git a/rclpy/test/test_create_node.py b/rclpy/test/test_create_node.py index 5440208ee..e0c62c4c3 100644 --- a/rclpy/test/test_create_node.py +++ b/rclpy/test/test_create_node.py @@ -32,47 +32,47 @@ def setUpClass(cls): def tearDownClass(cls): rclpy.shutdown(context=cls.context) - def test_create_node(self): + def test_create_node(self) -> None: node_name = 'create_node_test' rclpy.create_node(node_name, context=self.context).destroy_node() - def test_create_node_with_namespace(self): + def test_create_node_with_namespace(self) -> None: node_name = 'create_node_test' namespace = '/ns' rclpy.create_node(node_name, namespace=namespace, context=self.context).destroy_node() - def test_create_node_with_empty_namespace(self): + def test_create_node_with_empty_namespace(self) -> None: node_name = 'create_node_test' namespace = '' node = rclpy.create_node(node_name, namespace=namespace, context=self.context) self.assertEqual('/', node.get_namespace()) node.destroy_node() - def test_create_node_with_relative_namespace(self): + def test_create_node_with_relative_namespace(self) -> None: node_name = 'create_node_test' namespace = 'ns' node = rclpy.create_node(node_name, namespace=namespace, context=self.context) self.assertEqual('/ns', node.get_namespace()) node.destroy_node() - def test_create_node_invalid_name(self): + def test_create_node_invalid_name(self) -> None: node_name = 'create_node_test_invalid_name?' with self.assertRaisesRegex(InvalidNodeNameException, 'must not contain characters'): rclpy.create_node(node_name, context=self.context) - def test_create_node_invalid_relative_namespace(self): + def test_create_node_invalid_relative_namespace(self) -> None: node_name = 'create_node_test_invalid_namespace' namespace = 'invalid_namespace?' with self.assertRaisesRegex(InvalidNamespaceException, 'must not contain characters'): rclpy.create_node(node_name, namespace=namespace, context=self.context) - def test_create_node_invalid_namespace(self): + def test_create_node_invalid_namespace(self) -> None: node_name = 'create_node_test_invalid_namespace' namespace = '/invalid_namespace?' with self.assertRaisesRegex(InvalidNamespaceException, 'must not contain characters'): rclpy.create_node(node_name, namespace=namespace, context=self.context) - def test_create_node_with_parameter_overrides(self): + def test_create_node_with_parameter_overrides(self) -> None: node_name = 'create_node_with_parameter_overrides_test' rclpy.create_node( node_name, context=self.context, diff --git a/rclpy/test/test_create_while_spinning.py b/rclpy/test/test_create_while_spinning.py index b3e06836b..200aadb66 100644 --- a/rclpy/test/test_create_while_spinning.py +++ b/rclpy/test/test_create_while_spinning.py @@ -36,7 +36,7 @@ class TestCreateWhileSpinning(unittest.TestCase): This is a regression test for ros2/rclpy#188. """ - def setUp(self): + def setUp(self) -> None: rclpy.init() self.node = rclpy.create_node('TestCreateWhileSpinning', namespace='/rclpy') self.executor = SingleThreadedExecutor() @@ -46,20 +46,20 @@ def setUp(self): # Make sure executor is blocked by rcl_wait time.sleep(TIMEOUT) - def tearDown(self): + def tearDown(self) -> None: self.executor.shutdown() rclpy.shutdown() self.exec_thread.join() self.node.destroy_node() - def test_publish_subscribe(self): + def test_publish_subscribe(self) -> None: evt = threading.Event() self.node.create_subscription(BasicTypes, 'foo', lambda msg: evt.set(), 1) pub = self.node.create_publisher(BasicTypes, 'foo', 1) pub.publish(BasicTypes()) assert evt.wait(TIMEOUT) - def test_client_server(self): + def test_client_server(self) -> None: evt = threading.Event() def trigger_event(req, resp): @@ -73,29 +73,29 @@ def trigger_event(req, resp): cli.call_async(BasicTypesSrv.Request()) assert evt.wait(TIMEOUT) - def test_guard_condition(self): + def test_guard_condition(self) -> None: evt = threading.Event() guard = self.node.create_guard_condition(lambda: evt.set()) guard.trigger() assert evt.wait(TIMEOUT) - def test_timer(self): + def test_timer(self) -> None: evt = threading.Event() self.node.create_timer(TIMEOUT / 10, lambda: evt.set()) assert evt.wait(TIMEOUT) - def test_waitable(self): + def test_waitable(self) -> None: evt = threading.Event() class DummyWaitable(Waitable): - def __init__(self): + def __init__(self) -> None: super().__init__(ReentrantCallbackGroup()) - def __enter__(self): - return self + def __enter__(self) -> None: + pass def __exit__(self, exc_type, exc_val, exc_tb) -> None: pass @@ -103,7 +103,7 @@ def __exit__(self, exc_type, exc_val, exc_tb) -> None: def is_ready(self, wait_set): return False - def take_data(self): + def take_data(self) -> None: return None async def execute(self, taken_data): diff --git a/rclpy/test/test_destruction.py b/rclpy/test/test_destruction.py index d4e5ade08..625729386 100644 --- a/rclpy/test/test_destruction.py +++ b/rclpy/test/test_destruction.py @@ -22,7 +22,7 @@ from test_msgs.srv import BasicTypes as BasicTypesSrv -def test_destroy_node(): +def test_destroy_node() -> None: context = rclpy.context.Context() rclpy.init(context=context) try: @@ -32,7 +32,7 @@ def test_destroy_node(): rclpy.shutdown(context=context) -def test_destroy_node_twice(): +def test_destroy_node_twice() -> None: context = rclpy.context.Context() rclpy.init(context=context) try: @@ -43,14 +43,14 @@ def test_destroy_node_twice(): rclpy.shutdown(context=context) -def test_destroy_node_while_spinning(): +def test_destroy_node_while_spinning() -> None: context = rclpy.context.Context() rclpy.init(context=context) try: executor = rclpy.executors.SingleThreadedExecutor(context=context) node = rclpy.create_node('test_node1', context=context) - def spin(): + def spin() -> None: with pytest.raises(rclpy.executors.ExternalShutdownException): rclpy.spin(node, executor) @@ -73,7 +73,7 @@ def spin(): rclpy.try_shutdown(context=context) -def test_destroy_timers(): +def test_destroy_timers() -> None: context = rclpy.context.Context() rclpy.init(context=context) try: @@ -94,7 +94,7 @@ def test_destroy_timers(): rclpy.shutdown(context=context) -def test_destroy_entities(): +def test_destroy_entities() -> None: context = rclpy.context.Context() rclpy.init(context=context) try: @@ -130,7 +130,7 @@ def test_destroy_entities(): rclpy.shutdown(context=context) -def test_destroy_subscription_asap(): +def test_destroy_subscription_asap() -> None: context = rclpy.context.Context() rclpy.init(context=context) @@ -155,7 +155,7 @@ def test_destroy_subscription_asap(): rclpy.shutdown(context=context) -def test_destroy_node_asap(): +def test_destroy_node_asap() -> None: context = rclpy.context.Context() rclpy.init(context=context) @@ -172,7 +172,7 @@ def test_destroy_node_asap(): rclpy.shutdown(context=context) -def test_destroy_publisher_asap(): +def test_destroy_publisher_asap() -> None: context = rclpy.context.Context() rclpy.init(context=context) @@ -197,7 +197,7 @@ def test_destroy_publisher_asap(): rclpy.shutdown(context=context) -def test_destroy_client_asap(): +def test_destroy_client_asap() -> None: context = rclpy.context.Context() rclpy.init(context=context) @@ -222,7 +222,7 @@ def test_destroy_client_asap(): rclpy.shutdown(context=context) -def test_destroy_service_asap(): +def test_destroy_service_asap() -> None: context = rclpy.context.Context() rclpy.init(context=context) @@ -247,7 +247,7 @@ def test_destroy_service_asap(): rclpy.shutdown(context=context) -def test_destroy_timer_asap(): +def test_destroy_timer_asap() -> None: context = rclpy.context.Context() rclpy.init(context=context) diff --git a/rclpy/test/test_destruction_order.py b/rclpy/test/test_destruction_order.py index f34cb16df..862354ff2 100644 --- a/rclpy/test/test_destruction_order.py +++ b/rclpy/test/test_destruction_order.py @@ -16,7 +16,7 @@ from rclpy.node import Node -def test_destruction_order(): +def test_destruction_order() -> None: context = rclpy.context.Context() rclpy.init(context=context) node1 = Node('test_destruction_order_node_1', context=context) diff --git a/rclpy/test/test_executor.py b/rclpy/test/test_executor.py index e663d1e3c..7b7027486 100644 --- a/rclpy/test/test_executor.py +++ b/rclpy/test/test_executor.py @@ -31,12 +31,12 @@ class TestExecutor(unittest.TestCase): - def setUp(self): + def setUp(self) -> None: self.context = rclpy.context.Context() rclpy.init(context=self.context) self.node = rclpy.create_node('TestExecutor', namespace='/rclpy', context=self.context) - def tearDown(self): + def tearDown(self) -> None: self.node.destroy_node() rclpy.shutdown(context=self.context) self.context.destroy() @@ -44,7 +44,7 @@ def tearDown(self): def func_execution(self, executor): got_callback = False - def timer_callback(): + def timer_callback() -> None: nonlocal got_callback got_callback = True @@ -59,7 +59,7 @@ def timer_callback(): self.node.destroy_timer(tmr) return got_callback - def test_single_threaded_executor_executes(self): + def test_single_threaded_executor_executes(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) try: @@ -67,13 +67,13 @@ def test_single_threaded_executor_executes(self): finally: executor.shutdown() - def test_executor_immediate_shutdown(self): + def test_executor_immediate_shutdown(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) try: got_callback = False - def timer_callback(): + def timer_callback() -> None: nonlocal got_callback got_callback = True @@ -94,7 +94,7 @@ def timer_callback(): finally: executor.shutdown() - def test_shutdown_executor_before_waiting_for_callbacks(self): + def test_shutdown_executor_before_waiting_for_callbacks(self) -> None: self.assertIsNotNone(self.node.handle) for cls in [SingleThreadedExecutor, MultiThreadedExecutor]: executor = cls(context=self.context) @@ -102,7 +102,7 @@ def test_shutdown_executor_before_waiting_for_callbacks(self): with self.assertRaises(ShutdownException): executor.wait_for_ready_callbacks() - def test_shutdown_exception_from_callback_generator(self): + def test_shutdown_exception_from_callback_generator(self) -> None: self.assertIsNotNone(self.node.handle) for cls in [SingleThreadedExecutor, MultiThreadedExecutor]: executor = cls(context=self.context) @@ -111,13 +111,13 @@ def test_shutdown_exception_from_callback_generator(self): with self.assertRaises(ShutdownException): next(cb_generator) - def test_remove_node(self): + def test_remove_node(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) got_callback = False - def timer_callback(): + def timer_callback() -> None: nonlocal got_callback got_callback = True @@ -134,7 +134,7 @@ def timer_callback(): assert not got_callback - def test_multi_threaded_executor_num_threads(self): + def test_multi_threaded_executor_num_threads(self) -> None: self.assertIsNotNone(self.node.handle) # check default behavior, either platform configuration or defaults to 2 @@ -160,7 +160,7 @@ def test_multi_threaded_executor_num_threads(self): assert len(w) == 1 assert issubclass(w[0].category, UserWarning) - def test_multi_threaded_executor_executes(self): + def test_multi_threaded_executor_executes(self) -> None: self.assertIsNotNone(self.node.handle) executor = MultiThreadedExecutor(context=self.context) try: @@ -168,7 +168,7 @@ def test_multi_threaded_executor_executes(self): finally: executor.shutdown() - def test_multi_threaded_executor_closes_threads(self): + def test_multi_threaded_executor_closes_threads(self) -> None: self.assertIsNotNone(self.node.handle) def get_threads(): @@ -186,13 +186,13 @@ def get_threads(): executor.shutdown(wait_for_threads=True) self.assertTrue(main_thread_name == get_threads()) - def test_add_node_to_executor(self): + def test_add_node_to_executor(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) executor.add_node(self.node) self.assertIn(self.node, executor.get_nodes()) - def test_executor_spin_non_blocking(self): + def test_executor_spin_non_blocking(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) executor.add_node(self.node) @@ -201,7 +201,7 @@ def test_executor_spin_non_blocking(self): end = time.monotonic() self.assertLess(start - end, 0.001) - def test_execute_coroutine_timer(self): + def test_execute_coroutine_timer(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) executor.add_node(self.node) @@ -209,7 +209,7 @@ def test_execute_coroutine_timer(self): called1 = False called2 = False - async def coroutine(): + async def coroutine() -> None: nonlocal called1 nonlocal called2 called1 = True @@ -229,7 +229,7 @@ async def coroutine(): finally: self.node.destroy_timer(tmr) - def test_execute_coroutine_guard_condition(self): + def test_execute_coroutine_guard_condition(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) executor.add_node(self.node) @@ -237,7 +237,7 @@ def test_execute_coroutine_guard_condition(self): called1 = False called2 = False - async def coroutine(): + async def coroutine() -> None: nonlocal called1 nonlocal called2 called1 = True @@ -258,7 +258,7 @@ async def coroutine(): finally: self.node.destroy_guard_condition(gc) - def test_create_task_coroutine(self): + def test_create_task_coroutine(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) executor.add_node(self.node) @@ -273,7 +273,7 @@ async def coroutine(): self.assertTrue(future.done()) self.assertEqual('Sentinel Result', future.result()) - def test_create_task_normal_function(self): + def test_create_task_normal_function(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) executor.add_node(self.node) @@ -288,7 +288,7 @@ def func(): self.assertTrue(future.done()) self.assertEqual('Sentinel Result', future.result()) - def test_create_task_fifo_order(self): + def test_create_task_fifo_order(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) executor.add_node(self.node) @@ -314,7 +314,7 @@ async def coro2(): self.assertTrue(future2.done()) self.assertEqual('Sentinel Result 2', future2.result()) - def test_create_task_dependent_coroutines(self): + def test_create_task_dependent_coroutines(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) executor.add_node(self.node) @@ -344,7 +344,7 @@ async def coro2(): self.assertTrue(future1.done()) self.assertEqual('Sentinel Result 1', future1.result()) - def test_create_task_during_spin(self): + def test_create_task_during_spin(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) executor.add_node(self.node) @@ -382,12 +382,12 @@ def func(): self.assertTrue(future.done()) self.assertEqual('Sentinel Result', future.result()) - def test_global_executor_completes_async_task(self): + def test_global_executor_completes_async_task(self) -> None: self.assertIsNotNone(self.node.handle) class TriggerAwait: - def __init__(self): + def __init__(self) -> None: self.do_yield = True def __await__(self): @@ -399,7 +399,7 @@ def __await__(self): did_callback = False did_return = False - async def timer_callback(): + async def timer_callback() -> None: nonlocal trigger, did_callback, did_return did_callback = True await trigger @@ -416,7 +416,7 @@ async def timer_callback(): rclpy.spin_once(self.node, timeout_sec=0, executor=executor) self.assertTrue(did_return) - def test_executor_add_node(self): + def test_executor_add_node(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) assert executor.add_node(self.node) @@ -424,12 +424,12 @@ def test_executor_add_node(self): assert not executor.add_node(self.node) assert id(executor) == id(self.node.executor) - def test_executor_spin_until_future_complete_timeout(self): + def test_executor_spin_until_future_complete_timeout(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) executor.add_node(self.node) - def timer_callback(): + def timer_callback() -> None: pass timer = self.node.create_timer(0.003, timer_callback) @@ -446,12 +446,12 @@ def timer_callback(): timer.cancel() - def test_executor_spin_until_future_complete_future_done(self): + def test_executor_spin_until_future_complete_future_done(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) executor.add_node(self.node) - def timer_callback(): + def timer_callback() -> None: pass timer = self.node.create_timer(0.003, timer_callback) @@ -487,12 +487,12 @@ def set_future_result(future): timer.cancel() - def test_executor_spin_until_future_complete_do_not_wait(self): + def test_executor_spin_until_future_complete_do_not_wait(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) executor.add_node(self.node) - def timer_callback(): + def timer_callback() -> None: pass timer = self.node.create_timer(0.003, timer_callback) @@ -504,11 +504,11 @@ def timer_callback(): timer.cancel() - def test_executor_add_node_wakes_executor(self): + def test_executor_add_node_wakes_executor(self) -> None: self.assertIsNotNone(self.node.handle) got_callback = False - def timer_callback(): + def timer_callback() -> None: nonlocal got_callback got_callback = True @@ -532,14 +532,14 @@ def timer_callback(): executor.shutdown() self.node.destroy_timer(tmr) - def shutdown_executor_from_callback(self): + def shutdown_executor_from_callback(self) -> None: """https://github.com/ros2/rclpy/issues/944: allow for executor shutdown from callback.""" self.assertIsNotNone(self.node.handle) timer_period = 0.1 executor = SingleThreadedExecutor(context=self.context) shutdown_event = threading.Event() - def timer_callback(): + def timer_callback() -> None: nonlocal shutdown_event, executor executor.shutdown() shutdown_event.set() @@ -551,7 +551,7 @@ def timer_callback(): self.assertTrue(shutdown_event.wait(120)) self.node.destroy_timer(tmr) - def test_context_manager(self): + def test_context_manager(self) -> None: self.assertIsNotNone(self.node.handle) executor: Executor = SingleThreadedExecutor(context=self.context) @@ -567,7 +567,7 @@ def test_context_manager(self): # Make sure it does not raise (smoke test) executor.shutdown() - def test_single_threaded_spin_once_until_future(self): + def test_single_threaded_spin_once_until_future(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) @@ -595,7 +595,7 @@ def test_single_threaded_spin_once_until_future(self): executor.shutdown() - def test_multi_threaded_spin_once_until_future(self): + def test_multi_threaded_spin_once_until_future(self) -> None: self.assertIsNotNone(self.node.handle) executor = MultiThreadedExecutor(context=self.context) @@ -623,7 +623,7 @@ def test_multi_threaded_spin_once_until_future(self): executor.shutdown() - def test_not_lose_callback(self): + def test_not_lose_callback(self) -> None: self.assertIsNotNone(self.node.handle) executor = SingleThreadedExecutor(context=self.context) @@ -632,7 +632,7 @@ def test_not_lose_callback(self): cli = self.node.create_client( srv_type=Empty, srv_name='test_service', callback_group=callback_group) - async def timer1_callback(): + async def timer1_callback() -> None: timer1.cancel() await cli.call_async(Empty.Request()) @@ -640,7 +640,7 @@ async def timer1_callback(): count = 0 - def timer2_callback(): + def timer2_callback() -> None: nonlocal count count += 1 timer2 = self.node.create_timer(1.5, timer2_callback, callback_group) diff --git a/rclpy/test/test_expand_topic_name.py b/rclpy/test/test_expand_topic_name.py index 8a6a6ad94..89a396ef5 100644 --- a/rclpy/test/test_expand_topic_name.py +++ b/rclpy/test/test_expand_topic_name.py @@ -19,7 +19,7 @@ class TestExpandTopicName(unittest.TestCase): - def test_expand_topic_name(self): + def test_expand_topic_name(self) -> None: tests = { # 'expected output': ['input topic', 'node', '/ns'] '/ns/chatter': ['chatter', 'node_name', '/ns'], @@ -32,22 +32,22 @@ def test_expand_topic_name(self): expanded_topic = expand_topic_name(topic, node, namespace) self.assertEqual(expanded_topic, expected_topic) - def test_expand_topic_name_invalid_node_name(self): + def test_expand_topic_name_invalid_node_name(self) -> None: # node name may not contain '?' with self.assertRaisesRegex(ValueError, 'node name'): expand_topic_name('topic', 'invalid_node_name?', '/ns') - def test_expand_topic_name_invalid_namespace_empty(self): + def test_expand_topic_name_invalid_namespace_empty(self) -> None: # namespace may not be empty with self.assertRaisesRegex(ValueError, 'namespace'): expand_topic_name('topic', 'node_name', '') - def test_expand_topic_name_invalid_namespace_relative(self): + def test_expand_topic_name_invalid_namespace_relative(self) -> None: # namespace may not be relative with self.assertRaisesRegex(ValueError, 'namespace'): expand_topic_name('topic', 'node_name', 'ns') - def test_expand_topic_name_invalid_topic(self): + def test_expand_topic_name_invalid_topic(self) -> None: # topic may not contain '?' with self.assertRaisesRegex(ValueError, 'topic name'): expand_topic_name('invalid/topic?', 'node_name', '/ns') diff --git a/rclpy/test/test_guard_condition.py b/rclpy/test/test_guard_condition.py index f7eeb0d84..a11f9dfc8 100644 --- a/rclpy/test/test_guard_condition.py +++ b/rclpy/test/test_guard_condition.py @@ -35,10 +35,10 @@ def tearDownClass(cls): cls.node.destroy_node() rclpy.shutdown(context=cls.context) - def test_trigger(self): + def test_trigger(self) -> None: called = False - def func(): + def func() -> None: nonlocal called called = True @@ -53,15 +53,15 @@ def func(): self.node.destroy_guard_condition(gc) - def test_double_trigger(self): + def test_double_trigger(self) -> None: called1 = False called2 = False - def func1(): + def func1() -> None: nonlocal called1 called1 = True - def func2(): + def func2() -> None: nonlocal called2 called2 = True diff --git a/rclpy/test/test_init_shutdown.py b/rclpy/test/test_init_shutdown.py index 43a514448..0c3a03084 100644 --- a/rclpy/test/test_init_shutdown.py +++ b/rclpy/test/test_init_shutdown.py @@ -19,14 +19,14 @@ from rclpy.signals import SignalHandlerOptions -def test_init(): +def test_init() -> None: context = rclpy.context.Context() rclpy.init(context=context) assert context.ok() rclpy.shutdown(context=context) -def test_init_with_unknown_ros_args(): +def test_init_with_unknown_ros_args() -> None: from rclpy.impl.implementation_singleton import rclpy_implementation as _rclpy context = rclpy.context.Context() @@ -35,7 +35,7 @@ def test_init_with_unknown_ros_args(): rclpy.init(context=context, args=['--ros-args', 'unknown']) -def test_init_with_non_utf8_arguments(): +def test_init_with_non_utf8_arguments() -> None: context = rclpy.context.Context() # Embed non decodable characters e.g. due to # wrong locale settings. @@ -45,7 +45,7 @@ def test_init_with_non_utf8_arguments(): rclpy.init(context=context, args=args) -def test_init_shutdown_sequence(): +def test_init_shutdown_sequence() -> None: context = rclpy.context.Context() rclpy.init(context=context) assert context.ok() @@ -64,7 +64,7 @@ def test_init_shutdown_sequence(): rclpy.shutdown() -def test_double_init(): +def test_double_init() -> None: context = rclpy.context.Context() rclpy.init(context=context) try: @@ -74,7 +74,7 @@ def test_double_init(): rclpy.shutdown(context=context) -def test_double_shutdown(): +def test_double_shutdown() -> None: context = rclpy.context.Context() rclpy.init(context=context) assert context.ok() @@ -83,13 +83,13 @@ def test_double_shutdown(): rclpy.shutdown(context=context) -def test_create_node_without_init(): +def test_create_node_without_init() -> None: context = rclpy.context.Context() with pytest.raises(NotInitializedException): rclpy.create_node('foo', context=context) -def test_init_with_domain_id(): +def test_init_with_domain_id() -> None: rclpy.init(domain_id=123) assert rclpy.get_default_context().get_domain_id() == 123 rclpy.shutdown() @@ -99,19 +99,19 @@ def test_init_with_domain_id(): rclpy.shutdown(context=context) -def test_signal_handlers(): +def test_signal_handlers() -> None: rclpy.init() assert SignalHandlerOptions.ALL == signals.get_current_signal_handlers_options() rclpy.shutdown() assert SignalHandlerOptions.NO == signals.get_current_signal_handlers_options() -def test_init_with_invalid_domain_id(): +def test_init_with_invalid_domain_id() -> None: with pytest.raises(RuntimeError): rclpy.init(domain_id=-1) -def test_managed_init(): +def test_managed_init() -> None: with rclpy.init(domain_id=123) as init: assert init.context.get_domain_id() == 123 assert init.context.ok() diff --git a/rclpy/test/test_lifecycle.py b/rclpy/test/test_lifecycle.py index a20383c55..c77c61d81 100644 --- a/rclpy/test/test_lifecycle.py +++ b/rclpy/test/test_lifecycle.py @@ -31,7 +31,7 @@ from test_msgs.msg import BasicTypes -def test_lifecycle_node_init(): +def test_lifecycle_node_init() -> None: rclpy.init() node = LifecycleNode('test_lifecycle_node_init_1') assert node @@ -55,7 +55,7 @@ def test_lifecycle_node_init(): LifecycleNode('test_lifecycle_node_init_3', enable_communication_interface='asd') -def test_lifecycle_state_transitions(): +def test_lifecycle_state_transitions() -> None: node = LifecycleNode( 'test_lifecycle_state_transitions_1', enable_communication_interface=False) # normal transitions @@ -153,7 +153,7 @@ def test_lifecycle_services(request): thread = Thread(target=executor.spin) thread.start() - def cleanup(): + def cleanup() -> None: # Stop executor and join thread. # This cleanup is run even if an assertion fails. executor.shutdown() @@ -193,7 +193,7 @@ def cleanup(): } -def test_lifecycle_publisher(): +def test_lifecycle_publisher() -> None: node = LifecycleNode('test_lifecycle_publisher', enable_communication_interface=False) with mock.patch.object(Publisher, 'publish') as mock_publish: pub = node.create_lifecycle_publisher(BasicTypes, 'test_lifecycle_publisher_topic', 10) diff --git a/rclpy/test/test_logging.py b/rclpy/test/test_logging.py index 6f097fca7..59d4593dd 100644 --- a/rclpy/test/test_logging.py +++ b/rclpy/test/test_logging.py @@ -27,7 +27,7 @@ class TestLogging(unittest.TestCase): - def test_root_logger_level(self): + def test_root_logger_level(self) -> None: original_severity = rclpy.logging._root_logger.get_effective_level() for severity in LoggingSeverity: rclpy.logging._root_logger.set_level(severity) @@ -35,7 +35,7 @@ def test_root_logger_level(self): severity, rclpy.logging._root_logger.get_effective_level()) rclpy.logging._root_logger.set_level(original_severity) - def test_logger_level(self): + def test_logger_level(self) -> None: # We should be able to set the threshold of a nonexistent logger / one that doesn't # correspond to a python object, e.g. an RMW internal logger. name = 'my_internal_logger_name' @@ -47,14 +47,14 @@ def test_logger_level(self): severity, rclpy.logging.get_logger_effective_level(name)) rclpy.logging.set_logger_level(name, original_severity) - def test_logger_object_level(self): + def test_logger_object_level(self) -> None: logger = rclpy.logging.get_logger('test_logger') for severity in LoggingSeverity: if severity is not LoggingSeverity.UNSET: # unset causes the hierarchy to be traversed logger.set_level(severity) self.assertEqual(severity, logger.get_effective_level()) - def test_logger_effective_level(self): + def test_logger_effective_level(self) -> None: name = 'my_nonexistent_logger_name' self.assertEqual( rclpy.logging._root_logger.get_effective_level(), @@ -71,7 +71,7 @@ def test_logger_effective_level(self): LoggingSeverity.ERROR, rclpy.logging.get_logger_effective_level(name)) - def test_log_threshold(self): + def test_log_threshold(self) -> None: rclpy.logging._root_logger.set_level(LoggingSeverity.INFO) # Logging below threshold not expected to be logged @@ -83,7 +83,7 @@ def test_log_threshold(self): self.assertTrue(rclpy.logging._root_logger.error('message_error')) self.assertTrue(rclpy.logging._root_logger.fatal('message_fatal')) - def test_log_once(self): + def test_log_once(self) -> None: message_was_logged = [] for i in range(5): message_was_logged.append(rclpy.logging._root_logger.log( @@ -103,7 +103,7 @@ def test_log_once(self): )) self.assertEqual(message_was_logged, [True] * 5) - def test_log_throttle(self): + def test_log_throttle(self) -> None: message_was_logged = [] system_clock = Clock() for i in range(5): @@ -123,7 +123,7 @@ def test_log_throttle(self): False # t=1.6, throttled ]) - def test_log_throttle_ros_clock(self): + def test_log_throttle_ros_clock(self) -> None: message_was_logged = [] ros_clock = ROSClock() time_source = TimeSource() @@ -167,7 +167,7 @@ def test_log_throttle_ros_clock(self): True # t=4.0, not throttled ]) - def test_log_skip_first(self): + def test_log_skip_first(self) -> None: message_was_logged = [] for i in range(5): message_was_logged.append(rclpy.logging._root_logger.log( @@ -177,7 +177,7 @@ def test_log_skip_first(self): )) self.assertEqual(message_was_logged, [False] + [True] * 4) - def test_log_skip_first_throttle(self): + def test_log_skip_first_throttle(self) -> None: # Because of the ordering of supported_filters, first the throttle condition will be # evaluated/updated, then the skip_first condition message_was_logged = [] @@ -200,7 +200,7 @@ def test_log_skip_first_throttle(self): False # t=1.6, throttled ]) - def test_log_skip_first_once(self): + def test_log_skip_first_once(self) -> None: # Because of the ordering of supported_filters, first the skip_first condition will be # evaluated/updated, then the once condition message_was_logged = [] @@ -214,7 +214,7 @@ def test_log_skip_first_once(self): time.sleep(0.3) self.assertEqual(message_was_logged, [False, True] + [False] * 3) - def test_log_arguments(self): + def test_log_arguments(self) -> None: system_clock = Clock() # Check half-specified filter not allowed if a required parameter is missing with self.assertRaisesRegex(TypeError, 'required parameter .* not specified'): @@ -241,7 +241,7 @@ def test_log_arguments(self): unused_kwarg='unused_kwarg', ) - def test_log_parameters_changing(self): + def test_log_parameters_changing(self) -> None: # Check changing log call parameters is not allowed with self.assertRaisesRegex(ValueError, 'parameters cannot be changed between'): # Start at 1 because a throttle_duration_sec of 0 causes the filter to be ignored. @@ -267,7 +267,7 @@ def test_log_parameters_changing(self): severity, ) - def test_named_logger(self): + def test_named_logger(self) -> None: my_logger = rclpy.logging.get_logger('my_logger') my_logger.set_level(LoggingSeverity.INFO) @@ -299,7 +299,7 @@ def test_named_logger(self): )) self.assertEqual(message_was_logged, [True] + [False] * 4) - def test_named_logger_hierarchy(self): + def test_named_logger_hierarchy(self) -> None: # Create a logger that implicitly is a child of the un-named root logger with self.assertRaisesRegex(ValueError, 'Logger name must not be empty'): my_logger = rclpy.logging.get_logger('') @@ -351,7 +351,7 @@ def test_named_logger_hierarchy(self): rclpy.logging._root_logger.set_level(original_severity) - def test_clear_config(self): + def test_clear_config(self) -> None: my_logger = rclpy.logging.get_logger('my_temp_logger') my_logger.set_level(LoggingSeverity.WARN) self.assertEqual(LoggingSeverity.WARN, my_logger.get_effective_level()) @@ -361,16 +361,16 @@ def test_clear_config(self): rclpy.logging._root_logger.get_effective_level(), my_logger.get_effective_level()) - def test_logging_severity_from_string(self): + def test_logging_severity_from_string(self) -> None: for severity in rclpy.logging.LoggingSeverity: self.assertEqual( rclpy.logging.get_logging_severity_from_string(severity.name), severity) - def test_nonexistent_logging_severity_from_string(self): + def test_nonexistent_logging_severity_from_string(self) -> None: with self.assertRaises(RuntimeError): rclpy.logging.get_logging_severity_from_string('non_existent_severity') - def test_get_logging_directory(self): + def test_get_logging_directory(self) -> None: os.environ['HOME'] = '/fake_home_dir' os.environ.pop('USERPROFILE', None) os.environ.pop('ROS_LOG_DIR', None) diff --git a/rclpy/test/test_logging_service.py b/rclpy/test/test_logging_service.py index ac0897cab..f1ff05ed0 100644 --- a/rclpy/test/test_logging_service.py +++ b/rclpy/test/test_logging_service.py @@ -26,7 +26,7 @@ class TestLoggingService(unittest.TestCase): - def setUp(self): + def setUp(self) -> None: self.context = rclpy.context.Context() rclpy.init(context=self.context) self.test_node_with_logger_service = rclpy.create_node( @@ -49,7 +49,7 @@ def setUp(self): self.thread = threading.Thread(target=self.executor1.spin, daemon=True) self.thread.start() - def tearDown(self): + def tearDown(self) -> None: self.executor1.shutdown() self.thread.join() self.executor2.shutdown() @@ -57,7 +57,7 @@ def tearDown(self): self.test_node_with_logger_service.destroy_node() rclpy.shutdown(context=self.context) - def test_connect_get_logging_service(self): + def test_connect_get_logging_service(self) -> None: client = self.test_node.create_client( GetLoggerLevels, '/rclpy/test_node_with_logger_service_enabled/get_logger_levels') @@ -66,7 +66,7 @@ def test_connect_get_logging_service(self): finally: self.test_node.destroy_client(client) - def test_connect_set_logging_service(self): + def test_connect_set_logging_service(self) -> None: client = self.test_node.create_client( SetLoggerLevels, '/rclpy/test_node_with_logger_service_enabled/set_logger_levels' @@ -76,7 +76,7 @@ def test_connect_set_logging_service(self): finally: self.test_node.destroy_client(client) - def test_set_and_get_one_logging_level(self): + def test_set_and_get_one_logging_level(self) -> None: test_log_name = 'rcl' test_log_level = 10 @@ -115,7 +115,7 @@ def test_set_and_get_one_logging_level(self): self.assertEqual(response.levels[0].level, test_log_level) self.test_node.destroy_client(get_client) - def test_set_and_get_multi_logging_level(self): + def test_set_and_get_multi_logging_level(self) -> None: test_log_name1 = 'rcl' test_log_level1 = 20 @@ -175,7 +175,7 @@ def test_set_and_get_multi_logging_level(self): self.assertEqual(response.levels[2].level, test_log_level3) self.test_node.destroy_client(get_client) - def test_set_logging_level_with_invalid_param(self): + def test_set_logging_level_with_invalid_param(self) -> None: set_client = self.test_node.create_client( SetLoggerLevels, '/rclpy/test_node_with_logger_service_enabled/set_logger_levels') @@ -201,7 +201,7 @@ def test_set_logging_level_with_invalid_param(self): self.assertEqual(response.results[1].reason, 'Failed reason: Invalid logger level.') self.test_node.destroy_client(set_client) - def test_set_logging_level_with_partial_invalid_param(self): + def test_set_logging_level_with_partial_invalid_param(self) -> None: set_client = self.test_node.create_client( SetLoggerLevels, '/rclpy/test_node_with_logger_service_enabled/set_logger_levels') diff --git a/rclpy/test/test_messages.py b/rclpy/test/test_messages.py index b36ac4a91..ebd3f2ca6 100644 --- a/rclpy/test/test_messages.py +++ b/rclpy/test/test_messages.py @@ -40,21 +40,21 @@ def tearDownClass(cls): cls.node.destroy_node() rclpy.shutdown(context=cls.context) - def test_unicode_string(self): + def test_unicode_string(self) -> None: msg = Strings() msg.string_value = 'ñu' pub = self.node.create_publisher(Strings, 'chatter', 1) pub.publish(msg) self.node.destroy_publisher(pub) - def test_different_type_raises(self): + def test_different_type_raises(self) -> None: pub = self.node.create_publisher( BasicTypes, 'chatter_different_message_type', 1) with self.assertRaises(TypeError): pub.publish('different message type') self.node.destroy_publisher(pub) - def test_serialized_publish(self): + def test_serialized_publish(self) -> None: msg = Strings() msg.string_value = 'ñu' pub = self.node.create_publisher(Strings, 'chatter', 1) diff --git a/rclpy/test/test_node.py b/rclpy/test/test_node.py index dfd9ad9be..369bc401d 100644 --- a/rclpy/test/test_node.py +++ b/rclpy/test/test_node.py @@ -72,15 +72,15 @@ def setUpClass(cls): def tearDownClass(cls): rclpy.shutdown(context=cls.context) - def setUp(self): + def setUp(self) -> None: self.node = rclpy.create_node( TEST_NODE, namespace=TEST_NAMESPACE, context=self.context, allow_undeclared_parameters=True) - def tearDown(self): + def tearDown(self) -> None: self.node.destroy_node() - def test_accessors(self): + def test_accessors(self) -> None: self.assertIsNotNone(self.node.handle) with self.assertRaises(AttributeError): self.node.handle = 'garbage' @@ -88,7 +88,7 @@ def test_accessors(self): self.assertEqual(self.node.get_namespace(), TEST_NAMESPACE) self.assertEqual(self.node.get_clock().clock_type, ClockType.ROS_TIME) - def test_create_publisher(self): + def test_create_publisher(self) -> None: self.node.create_publisher(BasicTypes, 'chatter', 1) self.node.create_publisher(BasicTypes, 'chatter', qos_profile_sensor_data) with self.assertRaisesRegex(InvalidTopicNameException, 'must not contain characters'): @@ -102,7 +102,7 @@ def test_create_publisher(self): with self.assertRaisesRegex(TypeError, 'Expected QoSProfile or int'): self.node.create_publisher(BasicTypes, 'chatter', 'foo') - def test_create_subscription(self): + def test_create_subscription(self) -> None: self.node.create_subscription(BasicTypes, 'chatter', lambda msg: print(msg), 1) self.node.create_subscription( BasicTypes, 'chatter', lambda msg: print(msg), qos_profile_sensor_data) @@ -121,7 +121,7 @@ def raw_subscription_callback(self, msg): print('Raw subscription callback: %s length %d' % (msg, len(msg))) self.raw_subscription_msg = msg - def test_create_raw_subscription(self): + def test_create_raw_subscription(self) -> None: executor = SingleThreadedExecutor(context=self.context) executor.add_node(self.node) basic_types_pub = self.node.create_publisher(BasicTypes, 'raw_subscription_test', 1) @@ -153,7 +153,7 @@ def dummy_cb(self, msg): @unittest.skipIf( get_rmw_implementation_identifier() == 'rmw_connextdds' and platform.system() == 'Windows', reason='Source timestamp not implemented for Connext on Windows') - def test_take(self): + def test_take(self) -> None: basic_types_pub = self.node.create_publisher(BasicTypes, 'take_test', 1) sub = self.node.create_subscription( BasicTypes, @@ -172,7 +172,7 @@ def test_take(self): else: time.sleep(0.2) - def test_create_client(self): + def test_create_client(self) -> None: self.node.create_client(GetParameters, 'get/parameters') with self.assertRaisesRegex(InvalidServiceNameException, 'must not contain characters'): self.node.create_client(GetParameters, 'get/parameters?') @@ -181,7 +181,7 @@ def test_create_client(self): with self.assertRaisesRegex(ValueError, 'unknown substitution'): self.node.create_client(GetParameters, 'foo/{bad_sub}') - def test_create_service(self): + def test_create_service(self) -> None: self.node.create_service(GetParameters, 'get/parameters', lambda req: None) with self.assertRaisesRegex(InvalidServiceNameException, 'must not contain characters'): self.node.create_service(GetParameters, 'get/parameters?', lambda req: None) @@ -190,32 +190,32 @@ def test_create_service(self): with self.assertRaisesRegex(ValueError, 'unknown substitution'): self.node.create_service(GetParameters, 'foo/{bad_sub}', lambda req: None) - def test_service_names_and_types(self): + def test_service_names_and_types(self) -> None: # test that it doesn't raise self.node.get_service_names_and_types() - def test_service_names_and_types_by_node(self): + def test_service_names_and_types_by_node(self) -> None: # test that it doesn't raise self.node.get_service_names_and_types_by_node(TEST_NODE, TEST_NAMESPACE) - def test_client_names_and_types_by_node(self): + def test_client_names_and_types_by_node(self) -> None: # test that it doesn't raise self.node.get_client_names_and_types_by_node(TEST_NODE, TEST_NAMESPACE) - def test_topic_names_and_types(self): + def test_topic_names_and_types(self) -> None: # test that it doesn't raise self.node.get_topic_names_and_types(no_demangle=True) self.node.get_topic_names_and_types(no_demangle=False) - def test_node_names(self): + def test_node_names(self) -> None: # test that it doesn't raise self.node.get_node_names() - def test_node_names_and_namespaces(self): + def test_node_names_and_namespaces(self) -> None: # test that it doesn't raise self.node.get_node_names_and_namespaces() - def test_node_names_and_namespaces_with_enclaves(self): + def test_node_names_and_namespaces_with_enclaves(self) -> None: # test that it doesn't raise self.node.get_node_names_and_namespaces_with_enclaves() @@ -247,7 +247,7 @@ def assert_qos_equal(self, expected_qos_profile, actual_qos_profile, *, is_publi actual_qos_profile.liveliness_lease_duration, 'liveliness_lease_duration is unequal') - def test_get_publishers_subscriptions_info_by_topic(self): + def test_get_publishers_subscriptions_info_by_topic(self) -> None: topic_name = 'test_topic_endpoint_info' fq_topic_name = '{namespace}/{name}'.format(namespace=TEST_NAMESPACE, name=topic_name) # Lists should be empty @@ -311,7 +311,7 @@ def test_get_publishers_subscriptions_info_by_topic(self): self.node.get_subscriptions_info_by_topic('13') self.node.get_publishers_info_by_topic('13') - def test_count_publishers_subscribers(self): + def test_count_publishers_subscribers(self) -> None: short_topic_name = 'chatter' fq_topic_name = '%s/%s' % (TEST_NAMESPACE, short_topic_name) @@ -341,7 +341,7 @@ def test_count_publishers_subscribers(self): with self.assertRaisesRegex(ValueError, 'is invalid'): self.node.count_publishers('42') - def test_count_clients_services(self): + def test_count_clients_services(self) -> None: short_service_name = 'add_two_ints' fq_service_name = '%s/%s' % (TEST_NAMESPACE, short_service_name) @@ -382,7 +382,7 @@ def test_count_clients_services(self): with self.assertRaisesRegex(ValueError, 'is invalid'): self.node.count_services('42') - def test_node_logger(self): + def test_node_logger(self) -> None: node_logger = self.node.get_logger() expected_name = '%s.%s' % (TEST_NAMESPACE.replace('/', '.')[1:], TEST_NODE) self.assertEqual(node_logger.name, expected_name) @@ -397,7 +397,7 @@ def modify_parameter_callback(self, parameters_list: List[Parameter]): return modified_list - def test_node_set_parameters(self): + def test_node_set_parameters(self) -> None: results = self.node.set_parameters([ Parameter('foo', Parameter.Type.INTEGER, 42), Parameter('bar', Parameter.Type.STRING, 'hello'), @@ -435,11 +435,11 @@ def test_node_set_parameters(self): self.assertEqual(self.node.get_parameter('bar').value, 'hello') self.assertEqual(self.node.get_parameter('baz').value, 2.41) - def test_node_cannot_set_invalid_parameters(self): + def test_node_cannot_set_invalid_parameters(self) -> None: with self.assertRaises(TypeError): self.node.set_parameters([42]) - def test_node_set_parameters_atomically(self): + def test_node_set_parameters_atomically(self) -> None: result = self.node.set_parameters_atomically([ Parameter('foo', Parameter.Type.INTEGER, 42), Parameter('bar', Parameter.Type.STRING, 'hello'), @@ -474,13 +474,13 @@ def test_node_set_parameters_atomically(self): self.assertEqual(self.node.get_parameter('bar').value, 'hello') self.assertEqual(self.node.get_parameter('baz').value, 2.41) - def test_describe_undeclared_parameter(self): + def test_describe_undeclared_parameter(self) -> None: self.assertFalse(self.node.has_parameter('foo')) descriptor = self.node.describe_parameter('foo') self.assertEqual(descriptor, ParameterDescriptor()) - def test_describe_undeclared_parameters(self): + def test_describe_undeclared_parameters(self) -> None: self.assertFalse(self.node.has_parameter('foo')) self.assertFalse(self.node.has_parameter('bar')) @@ -491,36 +491,36 @@ def test_describe_undeclared_parameters(self): self.assertEqual(descriptor_list[0], ParameterDescriptor()) self.assertEqual(descriptor_list[1], ParameterDescriptor()) - def test_node_get_parameter(self): + def test_node_get_parameter(self) -> None: self.node.set_parameters([Parameter('foo', Parameter.Type.INTEGER, 42)]) self.assertIsInstance(self.node.get_parameter('foo'), Parameter) self.assertEqual(self.node.get_parameter('foo').value, 42) - def test_node_get_parameter_returns_parameter_not_set(self): + def test_node_get_parameter_returns_parameter_not_set(self) -> None: self.assertIsInstance(self.node.get_parameter('unset'), Parameter) self.assertEqual(self.node.get_parameter('unset').type_, Parameter.Type.NOT_SET) - def test_node_declare_static_parameter(self): + def test_node_declare_static_parameter(self) -> None: value = self.node.declare_parameter('an_integer', 5) self.assertEqual(value.value, 5) self.assertFalse( self.node.set_parameters([Parameter('an_integer', value='asd')])[0].successful) self.assertEqual(self.node.get_parameter('an_integer').value, 5) - def test_node_undeclared_parameters_are_dynamically_typed(self): + def test_node_undeclared_parameters_are_dynamically_typed(self) -> None: self.assertTrue(self.node.set_parameters([Parameter('my_param', value=5)])[0].successful) self.assertEqual(self.node.get_parameter('my_param').value, 5) self.assertTrue( self.node.set_parameters([Parameter('my_param', value='asd')])[0].successful) self.assertEqual(self.node.get_parameter('my_param').value, 'asd') - def test_node_cannot_declare_after_set(self): + def test_node_cannot_declare_after_set(self) -> None: self.assertTrue(self.node.set_parameters([Parameter('my_param', value=5)])[0].successful) self.assertEqual(self.node.get_parameter('my_param').value, 5) with pytest.raises(rclpy.exceptions.ParameterAlreadyDeclaredException): self.node.declare_parameter('my_param', 5) - def test_node_has_parameter_services(self): + def test_node_has_parameter_services(self) -> None: service_names_and_types = self.node.get_service_names_and_types() self.assertIn( ('/my_ns/my_node/describe_parameters', ['rcl_interfaces/srv/DescribeParameters']), @@ -561,23 +561,23 @@ def setUpClass(cls): def tearDownClass(cls): rclpy.shutdown(context=cls.context) - def setUp(self): + def setUp(self) -> None: self.node = rclpy.create_node(TEST_NODE, context=self.context) - def tearDown(self): + def tearDown(self) -> None: self.node.destroy_node() - def test_initially_no_executor(self): + def test_initially_no_executor(self) -> None: assert self.node.executor is None - def test_set_executor_adds_node_to_it(self): + def test_set_executor_adds_node_to_it(self) -> None: executor = Mock() executor.add_node.return_value = True self.node.executor = executor assert id(executor) == id(self.node.executor) executor.add_node.assert_called_once_with(self.node) - def test_set_executor_removes_node_from_old_executor(self): + def test_set_executor_removes_node_from_old_executor(self) -> None: old_executor = Mock() old_executor.add_node.return_value = True new_executor = Mock() @@ -589,7 +589,7 @@ def test_set_executor_removes_node_from_old_executor(self): old_executor.remove_node.assert_called_once_with(self.node) new_executor.remove_node.assert_not_called() - def test_set_executor_clear_executor(self): + def test_set_executor_clear_executor(self) -> None: executor = Mock() executor.add_node.return_value = True self.node.executor = executor @@ -609,7 +609,7 @@ def setUpClass(cls): def tearDownClass(cls): rclpy.shutdown(context=cls.context) - def setUp(self): + def setUp(self) -> None: self.node = rclpy.create_node( TEST_NODE, namespace=TEST_NAMESPACE, @@ -635,10 +635,10 @@ def setUp(self): automatically_declare_parameters_from_overrides=False ) - def tearDown(self): + def tearDown(self) -> None: self.node.destroy_node() - def test_declare_parameter(self): + def test_declare_parameter(self) -> None: with pytest.raises(ValueError): result_initial_foo = self.node.declare_parameter( 'initial_foo', ParameterValue(), ParameterDescriptor()) @@ -748,7 +748,7 @@ def test_declare_parameter(self): Parameter.Type.DOUBLE, descriptor=ParameterDescriptor(dynamic_typing=True)) - def test_declare_parameters(self): + def test_declare_parameters(self) -> None: parameters = [ ('initial_foo', 0, ParameterDescriptor()), ('foo', 42, ParameterDescriptor()), @@ -921,7 +921,7 @@ def reject_parameter_callback_1(self, parameter_list): param for param in parameter_list if 'refuse' in param.name) return SetParametersResult(successful=(not any(rejected_parameters))) - def test_node_undeclare_parameter_has_parameter(self): + def test_node_undeclare_parameter_has_parameter(self) -> None: # Undeclare unexisting parameter. with self.assertRaises(ParameterNotDeclaredException): self.node.undeclare_parameter('foo') @@ -953,7 +953,7 @@ def test_node_undeclare_parameter_has_parameter(self): self.assertTrue(self.node.has_parameter('immutable_foo')) self.assertEqual(self.node.get_parameter('immutable_foo').value, 'I am immutable') - def test_node_set_undeclared_parameters(self): + def test_node_set_undeclared_parameters(self) -> None: with self.assertRaises(ParameterNotDeclaredException): self.node.set_parameters([ Parameter('foo', Parameter.Type.INTEGER, 42), @@ -961,7 +961,7 @@ def test_node_set_undeclared_parameters(self): Parameter('baz', Parameter.Type.DOUBLE, 2.41) ]) - def test_node_set_undeclared_parameters_atomically(self): + def test_node_set_undeclared_parameters_atomically(self) -> None: with self.assertRaises(ParameterNotDeclaredException): self.node.set_parameters_atomically([ Parameter('foo', Parameter.Type.INTEGER, 42), @@ -969,17 +969,17 @@ def test_node_set_undeclared_parameters_atomically(self): Parameter('baz', Parameter.Type.DOUBLE, 2.41) ]) - def test_node_get_undeclared_parameter(self): + def test_node_get_undeclared_parameter(self) -> None: with self.assertRaises(ParameterNotDeclaredException): self.node.get_parameter('initial_foo') - def test_node_get_undeclared_parameter_or(self): + def test_node_get_undeclared_parameter_or(self) -> None: result = self.node.get_parameter_or( 'initial_foo', Parameter('foo', Parameter.Type.INTEGER, 152)) self.assertEqual(result.name, 'foo') self.assertEqual(result.value, 152) - def test_node_get_uninitialized_parameter_or(self): + def test_node_get_uninitialized_parameter_or(self) -> None: # Statically typed parameter self.node.declare_parameter('uninitialized_foo', Parameter.Type.INTEGER) result = self.node.get_parameter_or( @@ -995,7 +995,7 @@ def test_node_get_uninitialized_parameter_or(self): self.assertEqual(result.name, 'foo') self.assertEqual(result.value, 153) - def test_node_get_parameters_by_prefix(self): + def test_node_get_parameters_by_prefix(self) -> None: parameters = [ ('foo_prefix.foo', 43), ('foo_prefix.bar', 'hello'), @@ -1052,7 +1052,7 @@ def test_node_get_parameters_by_prefix(self): self.assertFalse(parameters) self.assertIsInstance(parameters, dict) - def test_node_set_parameters(self): + def test_node_set_parameters(self) -> None: integer_value = 42 string_value = 'hello' float_value = 2.41 @@ -1150,7 +1150,7 @@ def test_node_set_parameters(self): with self.assertRaises(ParameterNotDeclaredException): self.node.get_parameter('foobar') - def test_node_set_parameters_rejection(self): + def test_node_set_parameters_rejection(self) -> None: # Declare a new parameter and set a callback so that it's rejected when set. reject_parameter_tuple = ( 'reject_me', @@ -1171,7 +1171,7 @@ def test_node_set_parameters_rejection(self): self.assertIsInstance(result[0], SetParametersResult) self.assertFalse(result[0].successful) - def test_node_set_parameters_rejection_list(self): + def test_node_set_parameters_rejection_list(self) -> None: # Declare a new parameters and set a list of callbacks so that it's rejected when set. reject_list_parameter_tuple = [ ('reject', True, ParameterDescriptor()), @@ -1207,7 +1207,7 @@ def test_node_set_parameters_rejection_list(self): self.assertIsInstance(result[2], SetParametersResult) self.assertTrue(result[2].successful) - def test_node_list_parameters(self): + def test_node_list_parameters(self) -> None: parameters = [ ('foo_prefix.foo', 43), ('foo_prefix.bar', 'hello'), @@ -1366,7 +1366,7 @@ def modify_parameter_callback(self, parameter_list: List[Parameter]): def empty_parameter_callback(self, parameter_list: List[Parameter]): return [] - def test_add_remove_pre_set_parameter_callback(self): + def test_add_remove_pre_set_parameter_callback(self) -> None: callbacks = [self.modify_parameter_callback, self.empty_parameter_callback] for callback in callbacks: @@ -1410,7 +1410,7 @@ def test_add_remove_pre_set_parameter_callback(self): 'parameter list cannot be empty, this might be due to ' 'pre_set_parameters_callback modifying the original parameters list.') - def test_node_add_on_set_parameter_callback(self): + def test_node_add_on_set_parameter_callback(self) -> None: # Add callbacks to the list of callbacks. callbacks = [ self.reject_parameter_callback, @@ -1452,7 +1452,7 @@ def test_node_add_on_set_parameter_callback(self): self.assertIsInstance(result[1], SetParametersResult) self.assertTrue(result[1].successful) - def test_node_remove_from_set_callback(self): + def test_node_remove_from_set_callback(self) -> None: # Remove callbacks from list of callbacks. parameter_tuple = ( 'refuse', True, ParameterDescriptor() @@ -1499,7 +1499,7 @@ def test_node_remove_from_set_callback(self): self.assertIsInstance(result[0], SetParametersResult) self.assertTrue(result[0].successful) - def test_add_remove_post_set_parameter_callback(self): + def test_add_remove_post_set_parameter_callback(self) -> None: def successful_parameter_set_callback(parameter_list: List[Parameter]): for param in parameter_list: if param.name == 'param1': @@ -1538,7 +1538,7 @@ def successful_parameter_set_callback(parameter_list: List[Parameter]): self.assertTrue(self.track_value1 == 1.0) self.assertTrue(self.track_value2 == 2.0) - def test_node_set_parameters_read_only(self): + def test_node_set_parameters_read_only(self) -> None: integer_value = 42 string_value = 'hello' float_value = 2.41 @@ -1614,7 +1614,7 @@ def test_node_set_parameters_read_only(self): self.assertEqual(self.node.get_parameter('bar').value, 'bye') self.assertEqual(self.node.get_parameter('immutable_baz').value, 2.41) - def test_node_set_parameters_pre_set_parameter_callback(self): + def test_node_set_parameters_pre_set_parameter_callback(self) -> None: # parameter 'bar' not declared here, only declare 'foo' default_value = 0 self.node.declare_parameter('foo', default_value) @@ -1641,7 +1641,7 @@ def test_node_set_parameters_pre_set_parameter_callback(self): self.assertTrue(self.node.get_parameter('foo').value == default_value) self.assertFalse(self.node.has_parameter('bar')) - def test_node_set_parameters_implicit_undeclare(self): + def test_node_set_parameters_implicit_undeclare(self) -> None: parameter_tuples = [ ( 'foo', @@ -1673,7 +1673,7 @@ def test_node_set_parameters_implicit_undeclare(self): self.assertFalse(self.node.has_parameter('bar')) self.assertEqual(self.node.get_parameter('baz').value, 2.41) - def test_node_set_parameters_atomically(self): + def test_node_set_parameters_atomically(self) -> None: integer_value = 42 string_value = 'hello' float_value = 2.41 @@ -1767,7 +1767,7 @@ def test_node_set_parameters_atomically(self): with self.assertRaises(ParameterNotDeclaredException): self.node.get_parameter('foobar') - def test_node_set_parameters_atomically_pre_set_parameter_callback(self): + def test_node_set_parameters_atomically_pre_set_parameter_callback(self) -> None: # parameter 'bar' not declared here, only declare 'foo' default_value = 0 self.node.declare_parameter('foo', default_value) @@ -1795,7 +1795,7 @@ def test_node_set_parameters_atomically_pre_set_parameter_callback(self): self.assertTrue(self.node.get_parameter('foo').value == default_value) self.assertFalse(self.node.has_parameter('bar')) - def test_node_set_parameters_atomically_rejection(self): + def test_node_set_parameters_atomically_rejection(self) -> None: # Declare a new parameter and set a callback so that it's rejected when set. reject_parameter_tuple = ( 'reject_me', @@ -1816,7 +1816,7 @@ def test_node_set_parameters_atomically_rejection(self): self.assertIsInstance(result, SetParametersResult) self.assertFalse(result.successful) - def test_node_set_parameters_atomically_read_only(self): + def test_node_set_parameters_atomically_read_only(self) -> None: integer_value = 42 string_value = 'hello' float_value = 2.41 @@ -1886,7 +1886,7 @@ def test_node_set_parameters_atomically_read_only(self): self.assertEqual(self.node.get_parameter('bar').value, 'hello') self.assertEqual(self.node.get_parameter('immutable_baz').value, 2.41) - def test_node_set_parameters_atomically_implicit_undeclare(self): + def test_node_set_parameters_atomically_implicit_undeclare(self) -> None: parameter_tuples = [ ( 'foo', @@ -1920,7 +1920,7 @@ def test_node_set_parameters_atomically_implicit_undeclare(self): self.assertFalse(self.node.has_parameter('bar')) self.assertEqual(self.node.get_parameter('baz').value, 2.41) - def test_describe_parameter(self): + def test_describe_parameter(self) -> None: with self.assertRaises(ParameterNotDeclaredException): self.node.describe_parameter('foo') @@ -1950,7 +1950,7 @@ def test_describe_parameter(self): self.assertEqual(descriptor.integer_range[0].to_value, 10) self.assertEqual(descriptor.integer_range[0].step, 2) - def test_describe_parameters(self): + def test_describe_parameters(self) -> None: with self.assertRaises(ParameterNotDeclaredException): self.node.describe_parameter('foo') with self.assertRaises(ParameterNotDeclaredException): @@ -2013,7 +2013,7 @@ def test_describe_parameters(self): self.assertEqual(bar_descriptor.integer_range[0].to_value, 20) self.assertEqual(bar_descriptor.integer_range[0].step, 3) - def test_set_descriptor(self): + def test_set_descriptor(self) -> None: with self.assertRaises(ParameterNotDeclaredException): self.node.set_descriptor('foo', ParameterDescriptor()) @@ -2077,7 +2077,7 @@ def test_set_descriptor(self): self.assertEqual(descriptor.floating_point_range[0].to_value, 2.0) self.assertEqual(descriptor.floating_point_range[0].step, 0.1) - def test_set_descriptor_read_only(self): + def test_set_descriptor_read_only(self) -> None: with self.assertRaises(ParameterNotDeclaredException): self.node.set_descriptor('foo', ParameterDescriptor()) @@ -2104,7 +2104,7 @@ def test_set_descriptor_read_only(self): ) ) - def test_floating_point_range_descriptor(self): + def test_floating_point_range_descriptor(self) -> None: # OK cases; non-floats are not affected by the range. fp_range = FloatingPointRange(from_value=0.0, to_value=10.0, step=0.5) parameters = [ @@ -2186,7 +2186,7 @@ def test_floating_point_range_descriptor(self): self.assertAlmostEqual(self.node.get_parameter('to_value_no_step').value, 10.0) self.assertAlmostEqual(self.node.get_parameter('in_range_no_step').value, 5.37) - def test_integer_range_descriptor(self): + def test_integer_range_descriptor(self) -> None: # OK cases; non-integers are not affected by the range. integer_range = IntegerRange(from_value=0, to_value=10, step=2) parameters = [ @@ -2268,7 +2268,7 @@ def test_integer_range_descriptor(self): self.assertEqual(self.node.get_parameter('to_value_no_step').value, 10) self.assertEqual(self.node.get_parameter('in_range_no_step').value, 5) - def test_static_dynamic_typing(self): + def test_static_dynamic_typing(self) -> None: parameters = [ ('int_param', 0), ('int_param_no_default', Parameter.Type.INTEGER), @@ -2317,7 +2317,7 @@ def test_static_dynamic_typing(self): self.assertEqual(self.node.get_parameter('int_param').value, 4) self.assertFalse(self.node.has_parameter('dynamic_param')) - def test_wait_for_node(self): + def test_wait_for_node(self) -> None: node = rclpy.create_node( 'waiting_for_this_node', namespace=TEST_NAMESPACE, context=self.context) try: @@ -2325,13 +2325,13 @@ def test_wait_for_node(self): finally: node.destroy_node() - def test_wait_for_node_timeout(self): + def test_wait_for_node_timeout(self) -> None: self.assertFalse(self.node.wait_for_node('node_does_not_exist', 0.1)) class TestCreateNode(unittest.TestCase): - def test_use_global_arguments(self): + def test_use_global_arguments(self) -> None: context = rclpy.context.Context() rclpy.init( args=['process_name', '--ros-args', '-r', '__node:=global_node_name'], @@ -2357,7 +2357,7 @@ def test_use_global_arguments(self): finally: rclpy.shutdown(context=context) - def test_node_arguments(self): + def test_node_arguments(self) -> None: context = rclpy.context.Context() rclpy.init(context=context) try: @@ -2374,7 +2374,7 @@ def test_node_arguments(self): finally: rclpy.shutdown(context=context) - def test_bad_node_arguments(self): + def test_bad_node_arguments(self) -> None: context = rclpy.context.Context() rclpy.init(context=context) @@ -2399,7 +2399,7 @@ def test_bad_node_arguments(self): finally: rclpy.shutdown(context=context) - def test_node_get_fully_qualified_name(self): + def test_node_get_fully_qualified_name(self) -> None: context = rclpy.context.Context() rclpy.init(context=context) @@ -2458,7 +2458,7 @@ def test_node_get_fully_qualified_name(self): finally: rclpy.shutdown(context=context) - def test_node_get_fully_qualified_name_global_remap(self): + def test_node_get_fully_qualified_name_global_remap(self) -> None: g_context = rclpy.context.Context() global_remap_name = 'global_node_name' rclpy.init( @@ -2491,7 +2491,7 @@ def test_node_get_fully_qualified_name_global_remap(self): finally: rclpy.shutdown(context=g_context) - def test_no_use_sim_time(self): + def test_no_use_sim_time(self) -> None: context = rclpy.context.Context() rclpy.init(context=context) @@ -2505,7 +2505,7 @@ def test_no_use_sim_time(self): finally: rclpy.shutdown(context=context) - def test_use_sim_time(self): + def test_use_sim_time(self) -> None: context = rclpy.context.Context() rclpy.init(context=context) @@ -2528,7 +2528,7 @@ def test_use_sim_time(self): finally: rclpy.shutdown(context=context) - def test_node_context_manager(self): + def test_node_context_manager(self) -> None: context = rclpy.context.Context() rclpy.init(context=context) @@ -2540,7 +2540,7 @@ def test_node_context_manager(self): rclpy.shutdown(context=context) -def test_node_resolve_name(): +def test_node_resolve_name() -> None: context = rclpy.Context() rclpy.init( args=['--ros-args', '-r', 'foo:=bar'], @@ -2575,7 +2575,7 @@ def setUpClass(cls): def tearDownClass(cls): rclpy.shutdown() - def test_node_ns_params_file_with_wildcards(self): + def test_node_ns_params_file_with_wildcards(self) -> None: node = rclpy.create_node( 'node2', namespace='/ns', @@ -2604,7 +2604,7 @@ def test_node_ns_params_file_with_wildcards(self): finally: node.destroy_node() - def test_node_params_file_with_wildcards(self): + def test_node_params_file_with_wildcards(self) -> None: node = rclpy.create_node( 'node2', cli_args=[ @@ -2632,7 +2632,7 @@ def test_node_params_file_with_wildcards(self): finally: node.destroy_node() - def test_node_ns_params_file_by_order(self): + def test_node_ns_params_file_by_order(self) -> None: node = rclpy.create_node( 'node2', namespace='/ns', @@ -2648,7 +2648,7 @@ def test_node_ns_params_file_by_order(self): finally: node.destroy_node() - def test_node_ns_params_file_with_complicated_wildcards(self): + def test_node_ns_params_file_with_complicated_wildcards(self) -> None: # regex matched: /**/foo/*/bar node = rclpy.create_node( 'node2', diff --git a/rclpy/test/test_parameter.py b/rclpy/test/test_parameter.py index bc474333b..5c7d8672c 100644 --- a/rclpy/test/test_parameter.py +++ b/rclpy/test/test_parameter.py @@ -29,7 +29,7 @@ class TestParameter(unittest.TestCase): - def test_create_boolean_parameter(self): + def test_create_boolean_parameter(self) -> None: p = Parameter('myparam', Parameter.Type.BOOL, True) self.assertEqual(p.name, 'myparam') self.assertEqual(p.value, True) @@ -38,7 +38,7 @@ def test_create_boolean_parameter(self): self.assertEqual(p.name, 'myparam') self.assertEqual(p.value, True) - def test_create_bytes_parameter(self): + def test_create_bytes_parameter(self) -> None: p = Parameter('myparam', Parameter.Type.BYTE_ARRAY, [b'p', b'v', b'a', b'l', b'u', b'e']) self.assertEqual(p.name, 'myparam') self.assertEqual(p.value, [b'p', b'v', b'a', b'l', b'u', b'e']) @@ -48,7 +48,7 @@ def test_create_bytes_parameter(self): self.assertEqual(p.type_, Parameter.Type.BYTE_ARRAY) self.assertEqual(p.value, [b'p', b'v', b'a', b'l', b'u', b'e']) - def test_create_float_parameter(self): + def test_create_float_parameter(self) -> None: p = Parameter('myparam', Parameter.Type.DOUBLE, 2.41) self.assertEqual(p.name, 'myparam') self.assertEqual(p.value, 2.41) @@ -58,7 +58,7 @@ def test_create_float_parameter(self): self.assertEqual(p.type_, Parameter.Type.DOUBLE) self.assertEqual(p.value, 2.41) - def test_create_integer_parameter(self): + def test_create_integer_parameter(self) -> None: p = Parameter('myparam', Parameter.Type.INTEGER, 42) self.assertEqual(p.name, 'myparam') self.assertEqual(p.value, 42) @@ -68,7 +68,7 @@ def test_create_integer_parameter(self): self.assertEqual(p.type_, Parameter.Type.INTEGER) self.assertEqual(p.value, 42) - def test_create_string_parameter(self): + def test_create_string_parameter(self) -> None: p = Parameter('myparam', Parameter.Type.STRING, 'pvalue') self.assertEqual(p.name, 'myparam') self.assertEqual(p.value, 'pvalue') @@ -78,7 +78,7 @@ def test_create_string_parameter(self): self.assertEqual(p.type_, Parameter.Type.STRING) self.assertEqual(p.value, 'pvalue') - def test_create_boolean_array_parameter(self): + def test_create_boolean_array_parameter(self) -> None: p = Parameter('myparam', Parameter.Type.BOOL_ARRAY, [True, False, True]) self.assertEqual(p.value, [True, False, True]) @@ -86,7 +86,7 @@ def test_create_boolean_array_parameter(self): self.assertEqual(p.type_, Parameter.Type.BOOL_ARRAY) self.assertEqual(p.value, [True, False, True]) - def test_create_float_array_parameter(self): + def test_create_float_array_parameter(self) -> None: p = Parameter('myparam', Parameter.Type.DOUBLE_ARRAY, [2.41, 6.28]) self.assertEqual(p.value, [2.41, 6.28]) @@ -94,7 +94,7 @@ def test_create_float_array_parameter(self): self.assertEqual(p.type_, Parameter.Type.DOUBLE_ARRAY) self.assertEqual(p.value, [2.41, 6.28]) - def test_create_integer_array_parameter(self): + def test_create_integer_array_parameter(self) -> None: p = Parameter('myparam', Parameter.Type.INTEGER_ARRAY, [1, 2, 3]) self.assertEqual(p.value, [1, 2, 3]) @@ -102,7 +102,7 @@ def test_create_integer_array_parameter(self): self.assertEqual(p.type_, Parameter.Type.INTEGER_ARRAY) self.assertEqual(p.value, [1, 2, 3]) - def test_create_string_array_parameter(self): + def test_create_string_array_parameter(self) -> None: p = Parameter('myparam', Parameter.Type.STRING_ARRAY, ['hello', 'world']) self.assertEqual(p.value, ['hello', 'world']) @@ -110,7 +110,7 @@ def test_create_string_array_parameter(self): self.assertEqual(p.type_, Parameter.Type.STRING_ARRAY) self.assertEqual(p.value, ['hello', 'world']) - def test_create_not_set_parameter(self): + def test_create_not_set_parameter(self) -> None: p = Parameter('myparam', Parameter.Type.NOT_SET) self.assertIsNone(p.value) @@ -122,20 +122,20 @@ def test_create_not_set_parameter(self): self.assertIsNone(p.value) self.assertEqual(p.type_, Parameter.Type.NOT_SET) - def test_value_and_type_must_agree(self): + def test_value_and_type_must_agree(self) -> None: with self.assertRaises(ValueError): Parameter('myparam', Parameter.Type.NOT_SET, 42) with self.assertRaises(ValueError): Parameter('myparam', Parameter.Type.BOOL_ARRAY, 42) - def test_error_on_illegal_value_type(self): + def test_error_on_illegal_value_type(self) -> None: with self.assertRaises(TypeError): Parameter('illegaltype', 'mytype', 'myvalue') with self.assertRaises(TypeError): Parameter('illegaltype', value={'invalid': 'type'}) - def test_integer_tuple_array(self): + def test_integer_tuple_array(self) -> None: # list int_list = [1, 2, 3] self.assertEqual( @@ -148,7 +148,7 @@ def test_integer_tuple_array(self): Parameter.Type.INTEGER_ARRAY, Parameter.Type.from_parameter_value(int_tuple)) self.assertTrue(Parameter.Type.check(Parameter.Type.INTEGER_ARRAY, int_tuple)) - def test_integer_array(self): + def test_integer_array(self) -> None: int_array = array('i', [1, 2, 3]) self.assertEqual( Parameter.Type.INTEGER_ARRAY, Parameter.Type.from_parameter_value(int_array)) @@ -158,7 +158,7 @@ def test_integer_array(self): value=ParameterValue(type=7, integer_array_value=[1, 2, 3]) )) - def test_double_array(self): + def test_double_array(self) -> None: double_array = array('d', [1.0, 2.0, 3.0]) self.assertEqual( Parameter.Type.DOUBLE_ARRAY, Parameter.Type.from_parameter_value(double_array)) @@ -168,7 +168,7 @@ def test_double_array(self): value=ParameterValue(type=8, double_array_value=[1.0, 2.0, 3.0]) )) - def test_get_parameter_value(self): + def test_get_parameter_value(self) -> None: """Test the get_parameter_value function.""" test_cases = [ (True, ParameterValue(type=int(ParameterType.PARAMETER_BOOL), bool_value=True)), @@ -210,7 +210,7 @@ def test_get_parameter_value(self): assert False, f'failed to get param_value, reason: {e}' self.assertEqual(p, expected_value) - def test_parameter_value_to_python(self): + def test_parameter_value_to_python(self) -> None: """Test the parameter_value_to_python conversion function.""" test_cases = [ (ParameterValue(type=int(ParameterType.PARAMETER_NOT_SET)), None), @@ -258,7 +258,7 @@ def test_parameter_value_to_python(self): with pytest.raises(RuntimeError): parameter_value_to_python(parameter_value) - def test_parameter_dict_from_yaml_file(self): + def test_parameter_dict_from_yaml_file(self) -> None: yaml_string = """/param_test_target: ros__parameters: param_1: 1 diff --git a/rclpy/test/test_parameter_event_handler.py b/rclpy/test/test_parameter_event_handler.py index 27d67f21e..b4532aa6b 100644 --- a/rclpy/test/test_parameter_event_handler.py +++ b/rclpy/test/test_parameter_event_handler.py @@ -38,7 +38,7 @@ def test_event(self, parameter_event: ParameterEvent): class CallbackChecker: - def __init__(self): + def __init__(self) -> None: self.received = False def callback(self, _: Union[Parameter, ParameterEvent]): @@ -47,7 +47,7 @@ def callback(self, _: Union[Parameter, ParameterEvent]): class CallCounter: - def __init__(self): + def __init__(self) -> None: self.counter = 0 self.first_callback_call_order = 0 self.second_callback_call_order = 0 @@ -63,7 +63,7 @@ def second_callback(self, _: Union[Parameter, ParameterEvent]): class TestParameterEventHandler(unittest.TestCase): - def setUp(self): + def setUp(self) -> None: self.context = rclpy.context.Context() rclpy.init(context=self.context) self.handler_node = rclpy.create_node( @@ -88,13 +88,13 @@ def setUp(self): self.executor.add_node(self.handler_node) self.executor.add_node(self.target_node) - def tearDown(self): + def tearDown(self) -> None: self.executor.shutdown() self.handler_node.destroy_node() self.target_node.destroy_node() rclpy.shutdown(context=self.context) - def test_register_parameter_callback(self): + def test_register_parameter_callback(self) -> None: self.parameter_event_handler._callbacks.parameter_callbacks.clear() parameter_name = 'double_param' @@ -109,7 +109,7 @@ def test_register_parameter_callback(self): assert {(parameter_name, node_name): [handle]} ==\ self.parameter_event_handler._callbacks.parameter_callbacks - def test_get_parameter_from_event(self): + def test_get_parameter_from_event(self) -> None: int_param = Parameter('int_param', Parameter.Type.INTEGER, 1) str_param = Parameter('str_param', Parameter.Type.STRING, 'hello world') @@ -150,7 +150,7 @@ def test_get_parameter_from_event(self): new_params_event, 'wrong_str_param', '/wrong_node_name' ) - def test_get_parameters_from_event(self): + def test_get_parameters_from_event(self) -> None: int_param = Parameter('int_param', Parameter.Type.INTEGER, 1) str_param = Parameter('str_param', Parameter.Type.STRING, 'hello world') @@ -163,7 +163,7 @@ def test_get_parameters_from_event(self): assert {int_param, str_param} == set(res) - def test_register_parameter_event_callback(self): + def test_register_parameter_event_callback(self) -> None: self.parameter_event_handler._callbacks.event_callbacks.clear() handle = self.parameter_event_handler.add_parameter_event_callback( @@ -173,7 +173,7 @@ def test_register_parameter_event_callback(self): assert isinstance(handle, ParameterEventCallbackHandle) assert [handle] == self.parameter_event_handler._callbacks.event_callbacks - def test_parameter_callback(self): + def test_parameter_callback(self) -> None: callback_checker = CallbackChecker() parameter_name = 'int_param' @@ -202,7 +202,7 @@ def test_parameter_callback(self): with pytest.raises(RuntimeError): self.parameter_event_handler.remove_parameter_callback(callback_handle) - def test_parameter_event_callback(self): + def test_parameter_event_callback(self) -> None: callback_checker = CallbackChecker() parameter_name = 'int_param' @@ -231,7 +231,7 @@ def test_parameter_event_callback(self): with pytest.raises(RuntimeError): self.parameter_event_handler.remove_parameter_event_callback(callback_handle) - def test_last_in_first_call_for_parameter_callbacks(self): + def test_last_in_first_call_for_parameter_callbacks(self) -> None: call_counter = CallCounter() parameter_name = 'int_param' @@ -258,7 +258,7 @@ def test_last_in_first_call_for_parameter_callbacks(self): assert call_counter.first_callback_call_order == 2 assert call_counter.second_callback_call_order == 1 - def test_last_in_first_call_for_parameter_event_callbacks(self): + def test_last_in_first_call_for_parameter_event_callbacks(self) -> None: call_counter = CallCounter() parameter_name = 'int_param' @@ -285,14 +285,14 @@ def test_last_in_first_call_for_parameter_event_callbacks(self): assert call_counter.first_callback_call_order == 2 assert call_counter.second_callback_call_order == 1 - def test_resolve_path_empty_path(self): + def test_resolve_path_empty_path(self) -> None: assert '/rclpy/test_parameter_event_handler' ==\ self.parameter_event_handler._resolve_path() - def test_resolve_path_same_namespace(self): + def test_resolve_path_same_namespace(self) -> None: assert '/rclpy/test_node' == self.parameter_event_handler._resolve_path('test_node') - def test_resolve_path_other_namespace(self): + def test_resolve_path_other_namespace(self) -> None: assert '/test_node' == self.parameter_event_handler._resolve_path('/test_node') diff --git a/rclpy/test/test_parameter_service.py b/rclpy/test/test_parameter_service.py index fc036e600..8edb3ba96 100644 --- a/rclpy/test/test_parameter_service.py +++ b/rclpy/test/test_parameter_service.py @@ -26,7 +26,7 @@ class TestParameterService(unittest.TestCase): - def setUp(self): + def setUp(self) -> None: self.context = rclpy.context.Context() rclpy.init(context=self.context) self.test_node = rclpy.create_node( @@ -47,12 +47,12 @@ def setUp(self): self.executor = SingleThreadedExecutor(context=self.context) self.executor.add_node(self.test_node) - def tearDown(self): + def tearDown(self) -> None: self.executor.shutdown() self.test_node.destroy_node() rclpy.shutdown(context=self.context) - def test_get_uninitialized_parameter(self): + def test_get_uninitialized_parameter(self) -> None: self.test_node.declare_parameter('uninitialized_parameter', Parameter.Type.STRING) # The type in description should be STRING diff --git a/rclpy/test/test_publisher.py b/rclpy/test/test_publisher.py index 0565cb071..564bdc848 100644 --- a/rclpy/test/test_publisher.py +++ b/rclpy/test/test_publisher.py @@ -74,7 +74,7 @@ def do_test_topic_name(cls, test_topics, node): assert publisher.topic_name == target_topic publisher.destroy() - def test_topic_name(self): + def test_topic_name(self) -> None: test_topics = [ (TEST_TOPIC, '/' + TEST_TOPIC), ('/' + TEST_TOPIC, '/' + TEST_TOPIC), @@ -92,7 +92,7 @@ def test_topic_name(self): ] TestPublisher.do_test_topic_name(test_topics, self.node_with_ns) - def test_topic_name_remapping(self): + def test_topic_name_remapping(self) -> None: test_topics = [ (TEST_TOPIC_FROM, '/' + TEST_TOPIC_TO), ('/' + TEST_TOPIC_FROM, '/' + TEST_TOPIC_TO), @@ -102,7 +102,7 @@ def test_topic_name_remapping(self): ] TestPublisher.do_test_topic_name(test_topics, self.node) - def test_wait_for_all_acked(self): + def test_wait_for_all_acked(self) -> None: qos = rclpy.qos.QoSProfile( depth=1, reliability=rclpy.qos.QoSReliabilityPolicy.RELIABLE) @@ -126,7 +126,7 @@ def test_wait_for_all_acked(self): sub.destroy() -def test_publisher_context_manager(): +def test_publisher_context_manager() -> None: rclpy.init() try: with rclpy.create_node('pub_node', namespace='/pub_node_ns') as node: diff --git a/rclpy/test/test_qos.py b/rclpy/test/test_qos.py index 38c2c4db6..697f623e5 100644 --- a/rclpy/test/test_qos.py +++ b/rclpy/test/test_qos.py @@ -36,12 +36,12 @@ def convert_and_assert_equality(self, qos_profile): converted_profile = QoSProfile(**c_qos_profile.to_dict()) self.assertEqual(qos_profile, converted_profile) - def test_depth_only_constructor(self): + def test_depth_only_constructor(self) -> None: qos = QoSProfile(depth=1) assert qos.depth == 1 assert qos.history == QoSHistoryPolicy.KEEP_LAST - def test_eq_operator(self): + def test_eq_operator(self) -> None: profile_1 = QoSProfile(history=QoSHistoryPolicy.KEEP_LAST, depth=1) profile_same = QoSProfile( history=QoSHistoryPolicy.KEEP_LAST, depth=1) @@ -61,11 +61,11 @@ def test_eq_operator(self): self.assertNotEqual(profile_1, profile_different_duration) self.assertEqual(profile_different_duration, profile_equal_duration) - def test_simple_round_trip(self): + def test_simple_round_trip(self) -> None: source_profile = QoSProfile(history=QoSHistoryPolicy.KEEP_ALL) self.convert_and_assert_equality(source_profile) - def test_big_nanoseconds(self): + def test_big_nanoseconds(self) -> None: # Under 31 bits no_problem = QoSProfile( history=QoSHistoryPolicy.KEEP_ALL, @@ -84,7 +84,7 @@ def test_big_nanoseconds(self): lifespan=Duration(seconds=5)) self.convert_and_assert_equality(uint32_problem) - def test_alldata_round_trip(self): + def test_alldata_round_trip(self) -> None: source_profile = QoSProfile( history=QoSHistoryPolicy.KEEP_ALL, depth=12, @@ -98,7 +98,7 @@ def test_alldata_round_trip(self): ) self.convert_and_assert_equality(source_profile) - def test_invalid_qos(self): + def test_invalid_qos(self) -> None: with self.assertRaises(InvalidQoSProfileException): # No history or depth settings provided QoSProfile() @@ -106,7 +106,7 @@ def test_invalid_qos(self): # History is KEEP_LAST, but no depth is provided QoSProfile(history=QoSHistoryPolicy.KEEP_LAST) - def test_policy_short_names(self): + def test_policy_short_names(self) -> None: # Full test on History to show the mechanism works assert ( QoSHistoryPolicy.short_keys() == @@ -121,14 +121,14 @@ def test_policy_short_names(self): QoSHistoryPolicy.get_from_short_key('KEEP_last') == QoSHistoryPolicy.KEEP_LAST.value) - def test_preset_profiles(self): + def test_preset_profiles(self) -> None: # Make sure the Enum does what we expect assert QoSPresetProfiles.SYSTEM_DEFAULT.value == qos_profile_system_default assert ( QoSPresetProfiles.SYSTEM_DEFAULT.value == QoSPresetProfiles.get_from_short_key('system_default')) - def test_keep_last_zero_depth_constructor(self): + def test_keep_last_zero_depth_constructor(self) -> None: with warnings.catch_warnings(record=True) as caught_warnings: warnings.simplefilter('always', category=UserWarning) qos = QoSProfile(history=QoSHistoryPolicy.KEEP_LAST, depth=0) @@ -137,7 +137,7 @@ def test_keep_last_zero_depth_constructor(self): assert "A zero depth with KEEP_LAST doesn't make sense" in str(caught_warnings[0]) assert qos.history == QoSHistoryPolicy.KEEP_LAST - def test_keep_last_zero_depth_set(self): + def test_keep_last_zero_depth_set(self) -> None: qos = QoSProfile(history=QoSHistoryPolicy.KEEP_LAST, depth=1) assert qos.depth == 1 @@ -151,7 +151,7 @@ def test_keep_last_zero_depth_set(self): class TestCheckQosCompatibility(unittest.TestCase): - def test_compatible(self): + def test_compatible(self) -> None: qos = QoSProfile( depth=1, reliability=QoSReliabilityPolicy.RELIABLE, @@ -168,7 +168,7 @@ def test_compatible(self): assert compatibility == QoSCompatibility.OK assert reason == '' - def test_incompatible(self): + def test_incompatible(self) -> None: """ This test is assuming a DDS implementation. @@ -195,7 +195,7 @@ def test_incompatible(self): assert compatibility == QoSCompatibility.OK assert reason == '' - def test_warn_of_possible_incompatibility(self): + def test_warn_of_possible_incompatibility(self) -> None: """ This test is assuming a DDS implementation. diff --git a/rclpy/test/test_qos_event.py b/rclpy/test/test_qos_event.py index 1345aab84..c6870ba42 100644 --- a/rclpy/test/test_qos_event.py +++ b/rclpy/test/test_qos_event.py @@ -41,14 +41,14 @@ class TestQoSEvent(unittest.TestCase): topic_name = 'test_topic' - def setUp(self): + def setUp(self) -> None: self.context = rclpy.context.Context() rclpy.init(context=self.context) self.node = rclpy.create_node('TestQoSEvent', namespace='/rclpy/test', context=self.context) - def tearDown(self): + def tearDown(self) -> None: # These tests create a bunch of events by hand instead of using Node APIs, # so they won't be cleaned up when calling `node.destroy_node()`, but they could still # keep the node alive from one test to the next. @@ -57,7 +57,7 @@ def tearDown(self): self.node.destroy_node() rclpy.shutdown(context=self.context) - def test_publisher_constructor(self): + def test_publisher_constructor(self) -> None: callbacks = PublisherEventCallbacks() liveliness_callback = Mock() deadline_callback = Mock() @@ -99,7 +99,7 @@ def test_publisher_constructor(self): self.assertEqual(len(publisher.event_handlers), 4) self.node.destroy_publisher(publisher) - def test_subscription_constructor(self): + def test_subscription_constructor(self) -> None: callbacks = SubscriptionEventCallbacks() liveliness_callback = Mock() deadline_callback = Mock() @@ -143,7 +143,7 @@ def test_subscription_constructor(self): self.assertEqual(len(subscription.event_handlers), 4) self.node.destroy_subscription(subscription) - def test_default_incompatible_qos_callbacks(self): + def test_default_incompatible_qos_callbacks(self) -> None: original_logger = rclpy.logging._root_logger pub_log_msg = None @@ -208,7 +208,7 @@ def _do_create_destroy(self, parent_entity, event_type): handle = self._create_event_handle(parent_entity, event_type) handle.destroy_when_not_in_use() - def test_publisher_event_create_destroy(self): + def test_publisher_event_create_destroy(self) -> None: publisher = self.node.create_publisher(EmptyMsg, self.topic_name, 10) if _rclpy.rclpy_get_rmw_implementation_identifier() != 'rmw_zenoh_cpp': @@ -222,7 +222,7 @@ def test_publisher_event_create_destroy(self): publisher, QoSPublisherEventType.RCL_PUBLISHER_MATCHED) self.node.destroy_publisher(publisher) - def test_subscription_event_create_destroy(self): + def test_subscription_event_create_destroy(self) -> None: message_callback = Mock() subscription = self.node.create_subscription( EmptyMsg, self.topic_name, message_callback, 10) @@ -237,7 +237,7 @@ def test_subscription_event_create_destroy(self): subscription, QoSSubscriptionEventType.RCL_SUBSCRIPTION_MATCHED) self.node.destroy_subscription(subscription) - def test_call_publisher_rclpy_event_apis(self): + def test_call_publisher_rclpy_event_apis(self) -> None: # Go through the exposed apis and ensure that things don't explode when called # Make no assumptions about being able to actually receive the events publisher = self.node.create_publisher(EmptyMsg, self.topic_name, 10) @@ -305,7 +305,7 @@ def test_call_publisher_rclpy_event_apis(self): self.node.destroy_publisher(publisher) - def test_call_subscription_rclpy_event_apis(self): + def test_call_subscription_rclpy_event_apis(self) -> None: # Go through the exposed apis and ensure that things don't explode when called # Make no assumptions about being able to actually receive the events subscription = self.node.create_subscription(EmptyMsg, self.topic_name, Mock(), 10) @@ -375,7 +375,7 @@ def test_call_subscription_rclpy_event_apis(self): self.node.destroy_subscription(subscription) - def test_call_publisher_rclpy_event_matched(self): + def test_call_publisher_rclpy_event_matched(self) -> None: publisher = self.node.create_publisher(EmptyMsg, self.topic_name, 10) with self.context.handle: wait_set = _rclpy.WaitSet(0, 0, 0, 0, 0, 2, self.context.handle) @@ -422,7 +422,7 @@ def test_call_publisher_rclpy_event_matched(self): self.assertEqual(matched_status.current_count, 0) self.assertEqual(matched_status.current_count_change, -1) - def test_call_subscription_rclpy_event_matched_unmatched(self): + def test_call_subscription_rclpy_event_matched_unmatched(self) -> None: message_callback = Mock() subscription = self.node.create_subscription( EmptyMsg, self.topic_name, message_callback, 10) diff --git a/rclpy/test/test_qos_overriding_options.py b/rclpy/test/test_qos_overriding_options.py index d55b3ae2b..918c07c93 100644 --- a/rclpy/test/test_qos_overriding_options.py +++ b/rclpy/test/test_qos_overriding_options.py @@ -39,7 +39,7 @@ def init_shutdown(): rclpy.shutdown() -def test_get_qos_policy_parameter(): +def test_get_qos_policy_parameter() -> None: qos = QoSProfile( history=QoSHistoryPolicy.KEEP_LAST, depth=10, @@ -68,7 +68,7 @@ def test_get_qos_policy_parameter(): assert value == qos.liveliness_lease_duration.nanoseconds -def test_declare_qos_parameters(): +def test_declare_qos_parameters() -> None: node = Node('my_node') _declare_qos_parameters( Publisher, node, '/my_topic', QoSProfile(depth=10), @@ -88,7 +88,7 @@ def test_declare_qos_parameters(): assert actual[1].value == expected[1] # same param value -def test_declare_qos_parameters_with_overrides(): +def test_declare_qos_parameters_with_overrides() -> None: node = Node('my_node', parameter_overrides=[ Parameter('qos_overrides./my_topic.publisher.depth', value=100), Parameter('qos_overrides./my_topic.publisher.reliability', value='best_effort'), @@ -112,7 +112,7 @@ def test_declare_qos_parameters_with_overrides(): assert actual[1].value == expected[1] # same param value -def test_declare_qos_parameters_with_happy_callback(): +def test_declare_qos_parameters_with_happy_callback() -> None: def qos_validation_callback(qos): result = QosCallbackResult() result.successful = True @@ -137,7 +137,7 @@ def qos_validation_callback(qos): assert actual[1].value == expected[1] # same param value -def test_declare_qos_parameters_with_unhappy_callback(): +def test_declare_qos_parameters_with_unhappy_callback() -> None: def qos_validation_callback(qos): result = QosCallbackResult() result.successful = False @@ -154,7 +154,7 @@ def qos_validation_callback(qos): assert 'my_custom_error_message' in str(err.value) -def test_declare_qos_parameters_with_id(): +def test_declare_qos_parameters_with_id() -> None: node = Node('my_node') _declare_qos_parameters( Publisher, node, '/my_topic', QoSProfile(depth=10), diff --git a/rclpy/test/test_rate.py b/rclpy/test/test_rate.py index e1554765b..a948f53e8 100644 --- a/rclpy/test/test_rate.py +++ b/rclpy/test/test_rate.py @@ -67,19 +67,19 @@ def _run(self, rate): class TestRate: - def setup_method(self): + def setup_method(self) -> None: self.context = rclpy.context.Context() rclpy.init(context=self.context) self.node = rclpy.create_node('test_rate', context=self.context) self.executor = SingleThreadedExecutor(context=self.context) self.executor.add_node(self.node) - def teardown_method(self): + def teardown_method(self) -> None: self.executor.shutdown() self.node.destroy_node() rclpy.shutdown(context=self.context) - def test_rate_valid_period(self): + def test_rate_valid_period(self) -> None: rate = self.node.create_rate(FREQ) runner = RateRunner(rate) @@ -89,7 +89,7 @@ def test_rate_valid_period(self): assert runner.max_jitter <= PASS_MAX_SINGLE_JITTER, str(runner) assert abs(runner.avg_period - PERIOD) <= PASS_MAX_AVERAGE_JITTER, str(runner) - def test_rate_invalid_period(self): + def test_rate_invalid_period(self) -> None: with pytest.raises(TypeError): self.node.create_rate(None) @@ -99,11 +99,11 @@ def test_rate_invalid_period(self): with pytest.raises(ValueError): self.node.create_rate(-1.0) - def test_destroy(self): + def test_destroy(self) -> None: rate = self.node.create_rate(FREQ) assert self.node.destroy_rate(rate) - def test_destroy_wakes_rate(self): + def test_destroy_wakes_rate(self) -> None: rate = self.node.create_rate(0.0000001) self._thread = threading.Thread(target=rate.sleep, daemon=True) @@ -121,7 +121,7 @@ def sleep_check_exception(rate): pass -def test_shutdown_wakes_rate(): +def test_shutdown_wakes_rate() -> None: context = rclpy.context.Context() rclpy.init(context=context) node = rclpy.create_node('test_rate_shutdown', context=context) diff --git a/rclpy/test/test_rosout_subscription.py b/rclpy/test/test_rosout_subscription.py index f6332f973..31b86a79f 100644 --- a/rclpy/test/test_rosout_subscription.py +++ b/rclpy/test/test_rosout_subscription.py @@ -35,7 +35,7 @@ def tearDownClass(cls): cls.node.destroy_node() rclpy.shutdown(context=cls.context) - def setUp(self): + def setUp(self) -> None: # create subscriber of 'rosout' topic self.sub = self.node.create_subscription( Log, @@ -50,14 +50,14 @@ def _rosout_subscription_callback(self, msg): if msg.name == self.rosout_msg_name: self.fut.set_result(None) - def test_parent_log(self): + def test_parent_log(self) -> None: self.rosout_msg_name = 'test_rosout_subscription' logger = self.node.get_logger() logger.info('test') self.executor.spin_until_future_complete(self.fut, 3) self.assertTrue(self.fut.done()) - def test_child_log(self): + def test_child_log(self) -> None: self.rosout_msg_name = 'test_rosout_subscription.child1' logger = self.node.get_logger() logger.info('test') @@ -80,14 +80,14 @@ def test_child_log(self): self.executor.spin_until_future_complete(self.fut, 3) self.assertTrue(self.fut.done()) - def test_child_hierarchy(self): + def test_child_hierarchy(self) -> None: self.rosout_msg_name = 'test_rosout_subscription.child.grandchild' logger = self.node.get_logger().get_child('child').get_child('grandchild') logger.info('test') self.executor.spin_until_future_complete(self.fut, 3) self.assertTrue(self.fut.done()) - def test_first_child_removed(self): + def test_first_child_removed(self) -> None: self.rosout_msg_name = 'test_rosout_subscription.child' logger = self.node.get_logger().get_child('child') logger2 = self.node.get_logger().get_child('child') @@ -99,7 +99,7 @@ def test_first_child_removed(self): self.executor.spin_until_future_complete(self.fut, 3) self.assertTrue(self.fut.done()) - def test_logger_parameter(self): + def test_logger_parameter(self) -> None: self.rosout_msg_name = 'test_rosout_subscription.child' logger = self.node.get_logger().get_child('child') @@ -114,7 +114,7 @@ def call_logger(logger): self.executor.spin_until_future_complete(self.fut, 3) self.assertTrue(self.fut.done()) - def test_logger_rosout_disabled_without_exception(self): + def test_logger_rosout_disabled_without_exception(self) -> None: node = rclpy.create_node('mynode', context=self.context, enable_rosout=False) try: logger = node.get_logger().get_child('child') diff --git a/rclpy/test/test_serialization.py b/rclpy/test/test_serialization.py index f74215657..aa8a74e42 100644 --- a/rclpy/test/test_serialization.py +++ b/rclpy/test/test_serialization.py @@ -56,7 +56,7 @@ def test_serialize_deserialize(msgs, msg_type): assert msg == msg_deserialized -def test_set_float32(): +def test_set_float32() -> None: """Test message serialization/deserialization of float32 type.""" # During (de)serialization we convert to a C float before converting to a PyObject. # This can result in a loss of precision diff --git a/rclpy/test/test_service.py b/rclpy/test/test_service.py index 13f118026..bb15e7b34 100644 --- a/rclpy/test/test_service.py +++ b/rclpy/test/test_service.py @@ -80,7 +80,7 @@ def test_get_service_name_after_remapping(service_name, namespace, cli_args, exp node.destroy_node() -def test_service_context_manager(): +def test_service_context_manager() -> None: with rclpy.create_node('ctx_mgr_test') as node: with node.create_service( srv_type=Empty, srv_name='empty_service', callback=lambda _: None) as srv: diff --git a/rclpy/test/test_service_introspection.py b/rclpy/test/test_service_introspection.py index 909a5e776..09133d2bb 100644 --- a/rclpy/test/test_service_introspection.py +++ b/rclpy/test/test_service_introspection.py @@ -31,7 +31,7 @@ def setUpClass(cls): cls.context = rclpy.context.Context() rclpy.init(context=cls.context) - def setUp(self): + def setUp(self) -> None: self.node = rclpy.create_node( 'TestServiceIntrospection', context=self.context) self.executor = rclpy.executors.SingleThreadedExecutor(context=self.context) @@ -42,7 +42,7 @@ def setUp(self): self.sub_callback, 10) self.event_messages: List[BasicTypes.Event] = [] - def tearDown(self): + def tearDown(self) -> None: self.node.destroy_node() @classmethod @@ -57,7 +57,7 @@ def srv_callback(self, req, resp): resp.int64_value = req.int64_value return resp - def test_service_introspection_metadata(self): + def test_service_introspection_metadata(self) -> None: req = BasicTypes.Request() req.bool_value = False req.int64_value = 12345 @@ -103,7 +103,7 @@ def test_service_introspection_metadata(self): self.assertEqual(len(result_dict[ServiceEventInfo.RESPONSE_RECEIVED].request), 0) self.assertEqual(len(result_dict[ServiceEventInfo.RESPONSE_RECEIVED].response), 0) - def test_service_introspection_contents(self): + def test_service_introspection_contents(self) -> None: req = BasicTypes.Request() req.bool_value = False req.int64_value = 12345 diff --git a/rclpy/test/test_subscription.py b/rclpy/test/test_subscription.py index c947b0724..615587daf 100644 --- a/rclpy/test/test_subscription.py +++ b/rclpy/test/test_subscription.py @@ -24,7 +24,7 @@ @pytest.fixture(scope='session', autouse=True) -def setup_ros(): +def setup_ros() -> None: rclpy.init() @@ -79,7 +79,7 @@ def test_get_subscription_topic_name_after_remapping(topic_name, namespace, cli_ node.destroy_node() -def test_subscription_callback_type(): +def test_subscription_callback_type() -> None: node = Node('test_node', namespace='test_subscription/test_subscription_callback_type') sub = node.create_subscription( msg_type=Empty, @@ -107,7 +107,7 @@ def test_subscription_callback_type(): node.destroy_node() -def test_subscription_context_manager(): +def test_subscription_context_manager() -> None: node = Node('test_node', namespace='test_subscription/test_subscription_callback_type') with node.create_subscription( msg_type=Empty, @@ -126,7 +126,7 @@ def test_subscription_context_manager(): node.destroy_node() -def test_subscription_publisher_count(): +def test_subscription_publisher_count() -> None: topic_name = 'test_subscription/test_subscription_publisher_count/topic' node = Node('test_node', namespace='test_subscription/test_subscription_publisher_count') sub = node.create_subscription( diff --git a/rclpy/test/test_task.py b/rclpy/test/test_task.py index f0e92ccf9..c742896a9 100644 --- a/rclpy/test/test_task.py +++ b/rclpy/test/test_task.py @@ -21,7 +21,7 @@ class DummyExecutor: - def __init__(self): + def __init__(self) -> None: self.done_callbacks = [] def create_task(self, cb, *args): @@ -30,7 +30,7 @@ def create_task(self, cb, *args): class TestTask(unittest.TestCase): - def test_task_normal_callable(self): + def test_task_normal_callable(self) -> None: def func(): return 'Sentinel Result' @@ -40,7 +40,7 @@ def func(): self.assertTrue(t.done()) self.assertEqual('Sentinel Result', t.result()) - def test_task_lambda(self): + def test_task_lambda(self) -> None: def func(): return 'Sentinel Result' @@ -50,7 +50,7 @@ def func(): self.assertTrue(t.done()) self.assertEqual('Sentinel Result', t.result()) - def test_coroutine(self): + def test_coroutine(self) -> None: called1 = False called2 = False @@ -74,7 +74,7 @@ async def coro(): self.assertTrue(t.done()) self.assertEqual('Sentinel Result', t.result()) - def test_done_callback_scheduled(self): + def test_done_callback_scheduled(self) -> None: executor = DummyExecutor() t = Task(lambda: None, executor=executor) @@ -87,7 +87,7 @@ def test_done_callback_scheduled(self): self.assertEqual(1, len(args)) self.assertEqual(t, args[0]) - def test_done_task_done_callback_scheduled(self): + def test_done_task_done_callback_scheduled(self) -> None: executor = DummyExecutor() t = Task(lambda: None, executor=executor) @@ -100,10 +100,10 @@ def test_done_task_done_callback_scheduled(self): self.assertEqual(1, len(args)) self.assertEqual(t, args[0]) - def test_done_task_called(self): + def test_done_task_called(self) -> None: called = False - def func(): + def func() -> None: nonlocal called called = True @@ -116,20 +116,20 @@ def func(): self.assertFalse(called) self.assertTrue(t.done()) - def test_cancelled(self): + def test_cancelled(self) -> None: t = Task(lambda: None) t.cancel() self.assertTrue(t.cancelled()) - def test_done_task_cancelled(self): + def test_done_task_cancelled(self) -> None: t = Task(lambda: None) t() t.cancel() self.assertFalse(t.cancelled()) - def test_exception(self): + def test_exception(self) -> None: - def func(): + def func() -> None: e = Exception() e.sentinel_value = 'Sentinel Exception' raise e @@ -141,9 +141,9 @@ def func(): with self.assertRaises(Exception): t.result() - def test_coroutine_exception(self): + def test_coroutine_exception(self) -> None: - async def coro(): + async def coro() -> None: e = Exception() e.sentinel_value = 'Sentinel Exception' raise e @@ -155,7 +155,7 @@ async def coro(): with self.assertRaises(Exception): t.result() - def test_task_normal_callable_args(self): + def test_task_normal_callable_args(self) -> None: arg_in = 'Sentinel Arg' def func(arg): @@ -165,7 +165,7 @@ def func(arg): t() self.assertEqual('Sentinel Arg', t.result()) - def test_coroutine_args(self): + def test_coroutine_args(self) -> None: arg_in = 'Sentinel Arg' async def coro(arg): @@ -175,7 +175,7 @@ async def coro(arg): t() self.assertEqual('Sentinel Arg', t.result()) - def test_task_normal_callable_kwargs(self): + def test_task_normal_callable_kwargs(self) -> None: arg_in = 'Sentinel Arg' def func(kwarg=None): @@ -185,7 +185,7 @@ def func(kwarg=None): t() self.assertEqual('Sentinel Arg', t.result()) - def test_coroutine_kwargs(self): + def test_coroutine_kwargs(self) -> None: arg_in = 'Sentinel Arg' async def coro(kwarg=None): @@ -195,37 +195,37 @@ async def coro(kwarg=None): t() self.assertEqual('Sentinel Arg', t.result()) - def test_executing(self): + def test_executing(self) -> None: t = Task(lambda: None) self.assertFalse(t.executing()) class TestFuture(unittest.TestCase): - def test_cancelled(self): + def test_cancelled(self) -> None: f = Future() f.cancel() self.assertTrue(f.cancelled()) - def test_done(self): + def test_done(self) -> None: f = Future() self.assertFalse(f.done()) f.set_result(None) self.assertTrue(f.done()) - def test_set_result(self): + def test_set_result(self) -> None: f = Future() f.set_result('Sentinel Result') self.assertEqual('Sentinel Result', f.result()) self.assertTrue(f.done()) - def test_set_exception(self): + def test_set_exception(self) -> None: f = Future() f.set_exception('Sentinel Exception') self.assertEqual('Sentinel Exception', f.exception()) self.assertTrue(f.done()) - def test_await(self): + def test_await(self) -> None: f = Future() async def coro(): @@ -240,7 +240,7 @@ async def coro(): except StopIteration as e: self.assertEqual('Sentinel Result', e.value) - def test_await_exception(self): + def test_await_exception(self) -> None: f = Future() async def coro(): @@ -253,28 +253,28 @@ async def coro(): with self.assertRaises(RuntimeError): c.send(None) - def test_cancel_schedules_callbacks(self): + def test_cancel_schedules_callbacks(self) -> None: executor = DummyExecutor() f = Future(executor=executor) f.add_done_callback(lambda f: None) f.cancel() self.assertTrue(executor.done_callbacks) - def test_set_result_schedules_callbacks(self): + def test_set_result_schedules_callbacks(self) -> None: executor = DummyExecutor() f = Future(executor=executor) f.add_done_callback(lambda f: None) f.set_result('Anything') self.assertTrue(executor.done_callbacks) - def test_set_exception_schedules_callbacks(self): + def test_set_exception_schedules_callbacks(self) -> None: executor = DummyExecutor() f = Future(executor=executor) f.add_done_callback(lambda f: None) f.set_exception('Anything') self.assertTrue(executor.done_callbacks) - def test_cancel_invokes_callbacks(self): + def test_cancel_invokes_callbacks(self) -> None: called = False def cb(fut): @@ -286,7 +286,7 @@ def cb(fut): f.cancel() assert called - def test_set_result_invokes_callbacks(self): + def test_set_result_invokes_callbacks(self) -> None: called = False def cb(fut): @@ -298,7 +298,7 @@ def cb(fut): f.set_result('Anything') assert called - def test_set_exception_invokes_callbacks(self): + def test_set_exception_invokes_callbacks(self) -> None: called = False def cb(fut): @@ -310,7 +310,7 @@ def cb(fut): f.set_exception('Anything') assert called - def test_add_done_callback_invokes_callback(self): + def test_add_done_callback_invokes_callback(self) -> None: called = False def cb(fut): diff --git a/rclpy/test/test_time.py b/rclpy/test/test_time.py index 9323afe96..68df6ee13 100644 --- a/rclpy/test/test_time.py +++ b/rclpy/test/test_time.py @@ -24,7 +24,7 @@ class TestTime(unittest.TestCase): - def test_time_construction(self): + def test_time_construction(self) -> None: time = Time() assert time.nanoseconds == 0 @@ -44,7 +44,7 @@ def test_time_construction(self): with self.assertRaises(TypeError): time = Time(clock_type='SYSTEM_TIME') - def test_duration_construction(self): + def test_duration_construction(self) -> None: duration = Duration() assert duration.nanoseconds == 0 @@ -68,7 +68,7 @@ def test_duration_construction(self): with self.assertRaises(OverflowError): Duration(nanoseconds=-2**63 - 1) - def test_time_operators(self): + def test_time_operators(self) -> None: time1 = Time(nanoseconds=1, clock_type=ClockType.STEADY_TIME) # Addition/subtraction of time and duration @@ -113,7 +113,7 @@ def test_time_operators(self): with self.assertRaises(TypeError): duration - time1 - def test_time_comparators(self): + def test_time_comparators(self) -> None: # Times with the same clock type time1 = Time(nanoseconds=1) time2 = Time(nanoseconds=2) @@ -159,7 +159,7 @@ def test_time_comparators(self): with self.assertRaises(TypeError): time1 <= duration - def test_duration_comparators(self): + def test_duration_comparators(self) -> None: duration1 = Duration(nanoseconds=1) duration2 = Duration(nanoseconds=2) self.assertFalse(duration1 == duration2) @@ -188,7 +188,7 @@ def test_duration_comparators(self): with self.assertRaises(TypeError): duration1 <= time - def test_time_message_conversions(self): + def test_time_message_conversions(self) -> None: time1 = Time(nanoseconds=1, clock_type=ClockType.ROS_TIME) builtins_msg = Builtins() builtins_msg.time_value = time1.to_msg() @@ -201,7 +201,7 @@ def test_time_message_conversions(self): time3 = Time.from_msg(builtins_msg.time_value, clock_type=ClockType.SYSTEM_TIME) assert time3.clock_type == ClockType.SYSTEM_TIME - def test_time_message_conversions_big_nanoseconds(self): + def test_time_message_conversions_big_nanoseconds(self) -> None: time1 = Time(nanoseconds=1553575413247045598, clock_type=ClockType.ROS_TIME) builtins_msg = Builtins() builtins_msg.time_value = time1.to_msg() @@ -211,7 +211,7 @@ def test_time_message_conversions_big_nanoseconds(self): assert isinstance(time2, Time) assert time1 == time2 - def test_duration_message_conversions(self): + def test_duration_message_conversions(self) -> None: duration = Duration(nanoseconds=1) builtins_msg = Builtins() builtins_msg.duration_value = duration.to_msg() @@ -219,11 +219,11 @@ def test_duration_message_conversions(self): assert isinstance(duration2, Duration) assert duration2.nanoseconds == 1 - def test_seconds_nanoseconds(self): + def test_seconds_nanoseconds(self) -> None: assert (1, int(5e8)) == Time(seconds=1, nanoseconds=5e8).seconds_nanoseconds() assert (1, int(5e8)) == Time(seconds=0, nanoseconds=15e8).seconds_nanoseconds() assert (0, 0) == Time().seconds_nanoseconds() - def test_infinite_duration(self): + def test_infinite_duration(self) -> None: duration = Infinite assert str(duration) == 'Infinite' diff --git a/rclpy/test/test_time_source.py b/rclpy/test/test_time_source.py index 787dc0e96..7b06eb4c2 100644 --- a/rclpy/test/test_time_source.py +++ b/rclpy/test/test_time_source.py @@ -32,18 +32,18 @@ class TestTimeSource(unittest.TestCase): - def setUp(self): + def setUp(self) -> None: self.context = rclpy.context.Context() rclpy.init(context=self.context) self.node = rclpy.create_node( 'TestTimeSource', namespace='/rclpy', context=self.context, allow_undeclared_parameters=True) - def tearDown(self): + def tearDown(self) -> None: self.node.destroy_node() rclpy.shutdown(context=self.context) - def publish_clock_messages(self): + def publish_clock_messages(self) -> None: clock_pub = self.node.create_publisher(rosgraph_msgs.msg.Clock, CLOCK_TOPIC, 1) cycle_count = 0 time_msg = rosgraph_msgs.msg.Clock() @@ -56,7 +56,7 @@ def publish_clock_messages(self): # TODO(dhood): use rate once available time.sleep(1) - def publish_reversed_clock_messages(self): + def publish_reversed_clock_messages(self) -> None: clock_pub = self.node.create_publisher(rosgraph_msgs.msg.Clock, CLOCK_TOPIC, 1) cycle_count = 0 time_msg = rosgraph_msgs.msg.Clock() @@ -83,7 +83,7 @@ def set_use_sim_time_parameter(self, value): time.sleep(1) return use_sim_time_param.value == value - def test_time_source_attach_clock(self): + def test_time_source_attach_clock(self) -> None: time_source = TimeSource(node=self.node) # ROSClock is a specialization of Clock with ROS time methods. @@ -96,7 +96,7 @@ def test_time_source_attach_clock(self): with self.assertRaises(ValueError): time_source.attach_clock(Clock(clock_type=ClockType.STEADY_TIME)) - def test_time_source_not_using_sim_time(self): + def test_time_source_not_using_sim_time(self) -> None: time_source = TimeSource(node=self.node) clock = ROSClock() time_source.attach_clock(clock) @@ -122,7 +122,7 @@ def test_time_source_not_using_sim_time(self): self.assertFalse(clock2.ros_time_is_active) assert time_source._clock_sub is None - def test_time_source_using_sim_time(self): + def test_time_source_using_sim_time(self) -> None: time_source = TimeSource(node=self.node) clock = ROSClock() time_source.attach_clock(clock) @@ -160,7 +160,7 @@ def test_time_source_using_sim_time(self): assert time_source._get_node() == node2 assert time_source._clock_sub is None - def test_forwards_jump(self): + def test_forwards_jump(self) -> None: time_source = TimeSource(node=self.node) clock = ROSClock() time_source.attach_clock(clock) @@ -180,7 +180,7 @@ def test_forwards_jump(self): assert post_cb.call_args[0][0].clock_change == ClockChange.ROS_TIME_NO_CHANGE handler.unregister() - def test_backwards_jump(self): + def test_backwards_jump(self) -> None: time_source = TimeSource(node=self.node) clock = ROSClock() time_source.attach_clock(clock) @@ -200,7 +200,7 @@ def test_backwards_jump(self): assert post_cb.call_args[0][0].clock_change == ClockChange.ROS_TIME_NO_CHANGE handler.unregister() - def test_clock_change(self): + def test_clock_change(self) -> None: time_source = TimeSource(node=self.node) clock = ROSClock() time_source.attach_clock(clock) @@ -226,7 +226,7 @@ def test_clock_change(self): assert post_cb.call_args[0][0].clock_change == ClockChange.ROS_TIME_ACTIVATED handler.unregister() - def test_no_pre_callback(self): + def test_no_pre_callback(self) -> None: time_source = TimeSource(node=self.node) clock = ROSClock() time_source.attach_clock(clock) @@ -242,7 +242,7 @@ def test_no_pre_callback(self): assert post_cb.call_args[0][0].clock_change == ClockChange.ROS_TIME_DEACTIVATED handler.unregister() - def test_no_post_callback(self): + def test_no_post_callback(self) -> None: time_source = TimeSource(node=self.node) clock = ROSClock() time_source.attach_clock(clock) diff --git a/rclpy/test/test_timer.py b/rclpy/test/test_timer.py index 8e1fdb219..0eba4a470 100644 --- a/rclpy/test/test_timer.py +++ b/rclpy/test/test_timer.py @@ -154,7 +154,7 @@ def test_cancel_reset(period): rclpy.shutdown(context=context) -def test_time_until_next_call(): +def test_time_until_next_call() -> None: node = None executor = None timer = None @@ -185,7 +185,7 @@ def test_time_until_next_call(): rclpy.shutdown(context=context) -def test_timer_without_autostart(): +def test_timer_without_autostart() -> None: node = None timer = None rclpy.init() @@ -207,7 +207,7 @@ def test_timer_without_autostart(): rclpy.shutdown() -def test_timer_context_manager(): +def test_timer_context_manager() -> None: rclpy.init() try: with rclpy.create_node('test_timer_without_autostart') as node: @@ -223,7 +223,7 @@ def test_timer_context_manager(): rclpy.shutdown() -def test_timer_info_construction(): +def test_timer_info_construction() -> None: timer_info = TimerInfo() assert timer_info.expected_call_time.nanoseconds == 0 assert timer_info.actual_call_time.nanoseconds == 0 @@ -247,7 +247,7 @@ def test_timer_info_construction(): assert timer_info_copy.actual_call_time.clock_type == ClockType.STEADY_TIME -def test_timer_with_info(): +def test_timer_with_info() -> None: node = None executor = None timer = None @@ -283,7 +283,7 @@ def timer_callback(info: TimerInfo): rclpy.shutdown(context=context) -def test_timer_info_with_partial(): +def test_timer_info_with_partial() -> None: node = None executor = None timer = None diff --git a/rclpy/test/test_topic_endpoint_info.py b/rclpy/test/test_topic_endpoint_info.py index f27ba02ff..10db6e321 100644 --- a/rclpy/test/test_topic_endpoint_info.py +++ b/rclpy/test/test_topic_endpoint_info.py @@ -21,7 +21,7 @@ class TestQosProfile(unittest.TestCase): - def test_node_name_only_constructor(self): + def test_node_name_only_constructor(self) -> None: test_node_name = 'test_string' info_for_ref = TopicEndpointInfo() @@ -32,7 +32,7 @@ def test_node_name_only_constructor(self): self.assertEqual(info_for_ref, info_from_ctor) self.assertEqual(test_node_name, info_from_ctor.node_name) - def test_node_namespace_only_constructor(self): + def test_node_namespace_only_constructor(self) -> None: test_node_namespace = 'test_string' info_for_ref = TopicEndpointInfo() @@ -43,7 +43,7 @@ def test_node_namespace_only_constructor(self): self.assertEqual(info_for_ref, info_from_ctor) self.assertEqual(test_node_namespace, info_from_ctor.node_namespace) - def test_topic_type_only_constructor(self): + def test_topic_type_only_constructor(self) -> None: test_topic_type = 'test_string' info_for_ref = TopicEndpointInfo() @@ -54,7 +54,7 @@ def test_topic_type_only_constructor(self): self.assertEqual(info_for_ref, info_from_ctor) self.assertEqual(test_topic_type, info_from_ctor.topic_type) - def test_endpoint_type_only_constructor(self): + def test_endpoint_type_only_constructor(self) -> None: test_endpoint_type = TopicEndpointTypeEnum.SUBSCRIPTION info_for_ref = TopicEndpointInfo() @@ -65,7 +65,7 @@ def test_endpoint_type_only_constructor(self): self.assertEqual(info_for_ref, info_from_ctor) self.assertEqual(test_endpoint_type, info_from_ctor.endpoint_type) - def test_endpoint_gid_only_constructor(self): + def test_endpoint_gid_only_constructor(self) -> None: test_endpoint_gid = [0, 0, 0, 0, 0] info_for_ref = TopicEndpointInfo() @@ -76,7 +76,7 @@ def test_endpoint_gid_only_constructor(self): self.assertEqual(info_for_ref, info_from_ctor) self.assertEqual(test_endpoint_gid, info_from_ctor.endpoint_gid) - def test_qos_profile_only_constructor(self): + def test_qos_profile_only_constructor(self) -> None: c_qos_profile = _rclpy.rmw_qos_profile_t.predefined('qos_profile_default') test_qos_profile = QoSProfile(**c_qos_profile.to_dict()) @@ -88,7 +88,7 @@ def test_qos_profile_only_constructor(self): self.assertEqual(info_for_ref, info_from_ctor) self.assertEqual(test_qos_profile, info_from_ctor.qos_profile) - def test_print(self): + def test_print(self) -> None: actual_info_str = str(TopicEndpointInfo()) expected_info_str = 'Node name: \n' \ 'Node namespace: \n' \ diff --git a/rclpy/test/test_topic_or_service_is_hidden.py b/rclpy/test/test_topic_or_service_is_hidden.py index 8a7f77837..d42681d56 100644 --- a/rclpy/test/test_topic_or_service_is_hidden.py +++ b/rclpy/test/test_topic_or_service_is_hidden.py @@ -19,7 +19,7 @@ class TestTopicOrServiceIsHidden(unittest.TestCase): - def test_topic_or_service_is_hidden(self): + def test_topic_or_service_is_hidden(self) -> None: tests = [ ('/chatter', False), ('chatter', False), diff --git a/rclpy/test/test_type_description_service.py b/rclpy/test/test_type_description_service.py index e3f7a7c69..90abcea63 100644 --- a/rclpy/test/test_type_description_service.py +++ b/rclpy/test/test_type_description_service.py @@ -24,7 +24,7 @@ class TestTypeDescriptionService(unittest.TestCase): - def setUp(self): + def setUp(self) -> None: self.context = rclpy.context.Context() rclpy.init(context=self.context) @@ -43,12 +43,12 @@ def setUp(self): self.executor = SingleThreadedExecutor(context=self.context) self.executor.add_node(self.test_node) - def tearDown(self): + def tearDown(self) -> None: self.executor.shutdown() self.test_node.destroy_node() rclpy.shutdown(context=self.context) - def test_get_type_description(self): + def test_get_type_description(self) -> None: pub_infos = self.test_node.get_publishers_info_by_topic(self.test_topic) assert len(pub_infos) type_hash = pub_infos[0].topic_type_hash diff --git a/rclpy/test/test_type_hash.py b/rclpy/test/test_type_hash.py index 91318b706..299b71c74 100644 --- a/rclpy/test/test_type_hash.py +++ b/rclpy/test/test_type_hash.py @@ -28,22 +28,22 @@ class TestTypeHash(unittest.TestCase): - def test_dict_constructor(self): + def test_dict_constructor(self) -> None: type_hash = TypeHash(**STD_MSGS_STRING_TYPE_HASH_DICT) self.assertTrue(hasattr(type_hash, '__slots__')) self.assertEqual(STD_MSGS_STRING_TYPE_HASH_DICT['version'], type_hash.version) self.assertEqual(STD_MSGS_STRING_TYPE_HASH_DICT['value'], type_hash.value) - def test_print_valid(self): + def test_print_valid(self) -> None: actual_str = str(TypeHash(**STD_MSGS_STRING_TYPE_HASH_DICT)) expected_str = STD_MSGS_STRING_TYPE_HASH_STR self.assertEqual(expected_str, actual_str) - def test_print_invalid(self): + def test_print_invalid(self) -> None: actual_str = str(TypeHash()) expected_str = 'INVALID' self.assertEqual(expected_str, actual_str) - def test_equals(self): + def test_equals(self) -> None: self.assertEqual(TypeHash(), TypeHash()) self.assertNotEqual(TypeHash(version=5), TypeHash()) diff --git a/rclpy/test/test_type_support.py b/rclpy/test/test_type_support.py index 12b7290fe..a253e36e0 100644 --- a/rclpy/test/test_type_support.py +++ b/rclpy/test/test_type_support.py @@ -33,7 +33,7 @@ class MockType(metaclass=MockTypeMetaclass): pass -def test_check_for_type_support(): +def test_check_for_type_support() -> None: type_support.check_for_type_support(Strings) type_support.check_for_type_support(Empty) with pytest.raises(AttributeError): @@ -42,13 +42,13 @@ def test_check_for_type_support(): type_support.check_for_type_support(MockType) -def test_check_valid_msg_type(): +def test_check_valid_msg_type() -> None: type_support.check_is_valid_msg_type(Strings) with pytest.raises(RuntimeError): type_support.check_is_valid_msg_type(Empty) -def test_check_valid_srv_type(): +def test_check_valid_srv_type() -> None: type_support.check_is_valid_srv_type(Empty) with pytest.raises(RuntimeError): type_support.check_is_valid_srv_type(Strings) diff --git a/rclpy/test/test_utilities.py b/rclpy/test/test_utilities.py index 2068a8aca..b649452ed 100644 --- a/rclpy/test/test_utilities.py +++ b/rclpy/test/test_utilities.py @@ -20,7 +20,7 @@ class TestValidateRemoveRosArgs(unittest.TestCase): - def test_remove_ros_args(self): + def test_remove_ros_args(self) -> None: args = [ 'process_name', '-d', @@ -41,7 +41,7 @@ def test_remove_ros_args(self): class TestUtilities(unittest.TestCase): - def test_timeout_sec_to_nsec(self): + def test_timeout_sec_to_nsec(self) -> None: self.assertGreater(0, rclpy.utilities.timeout_sec_to_nsec(None)) self.assertGreater(0, rclpy.utilities.timeout_sec_to_nsec(-1)) self.assertEqual(0, rclpy.utilities.timeout_sec_to_nsec(0)) diff --git a/rclpy/test/test_validate_full_topic_name.py b/rclpy/test/test_validate_full_topic_name.py index 0e0eeede9..5d5670708 100644 --- a/rclpy/test/test_validate_full_topic_name.py +++ b/rclpy/test/test_validate_full_topic_name.py @@ -21,7 +21,7 @@ class TestValidateFullTopicName(unittest.TestCase): - def test_validate_full_topic_name(self): + def test_validate_full_topic_name(self) -> None: tests = [ '/chatter', '/node_name/chatter', @@ -31,7 +31,7 @@ def test_validate_full_topic_name(self): # Will raise if invalid validate_full_topic_name(topic) - def test_validate_full_topic_name_failures(self): + def test_validate_full_topic_name_failures(self) -> None: # topic name may not contain '?' with self.assertRaisesRegex(InvalidTopicNameException, 'must not contain characters'): validate_full_topic_name('/invalid_topic?') @@ -39,7 +39,7 @@ def test_validate_full_topic_name_failures(self): with self.assertRaisesRegex(InvalidTopicNameException, 'must be absolute'): validate_full_topic_name('invalid_topic') - def test_validate_full_topic_name_failures_services(self): + def test_validate_full_topic_name_failures_services(self) -> None: # service name may not contain '?' with self.assertRaisesRegex(InvalidServiceNameException, 'must not contain characters'): validate_full_topic_name('/invalid_service?', is_service=True) diff --git a/rclpy/test/test_validate_namespace.py b/rclpy/test/test_validate_namespace.py index 673dcca06..da49cd99b 100644 --- a/rclpy/test/test_validate_namespace.py +++ b/rclpy/test/test_validate_namespace.py @@ -20,7 +20,7 @@ class TestValidateNamespace(unittest.TestCase): - def test_validate_namespace(self): + def test_validate_namespace(self) -> None: tests = [ '/my_ns', '/', @@ -29,7 +29,7 @@ def test_validate_namespace(self): # Will raise if invalid validate_namespace(topic) - def test_validate_namespace_failures(self): + def test_validate_namespace_failures(self) -> None: # namespace must not be empty with self.assertRaisesRegex(InvalidNamespaceException, 'empty'): validate_namespace('') diff --git a/rclpy/test/test_validate_node_name.py b/rclpy/test/test_validate_node_name.py index 6fbd4e4b3..7d853c305 100644 --- a/rclpy/test/test_validate_node_name.py +++ b/rclpy/test/test_validate_node_name.py @@ -20,7 +20,7 @@ class TestValidateNodeName(unittest.TestCase): - def test_validate_node_name(self): + def test_validate_node_name(self) -> None: tests = [ 'my_node', ] @@ -28,7 +28,7 @@ def test_validate_node_name(self): # Will raise if invalid validate_node_name(topic) - def test_validate_node_name_failures(self): + def test_validate_node_name_failures(self) -> None: # node name must not be empty with self.assertRaisesRegex(InvalidNodeNameException, 'must not be empty'): validate_node_name('') diff --git a/rclpy/test/test_validate_topic_name.py b/rclpy/test/test_validate_topic_name.py index 5c6baa356..899e7f8aa 100644 --- a/rclpy/test/test_validate_topic_name.py +++ b/rclpy/test/test_validate_topic_name.py @@ -21,7 +21,7 @@ class TestValidateTopicName(unittest.TestCase): - def test_validate_topic_name(self): + def test_validate_topic_name(self) -> None: tests = [ 'chatter', '{node}/chatter', @@ -31,7 +31,7 @@ def test_validate_topic_name(self): # Will raise if invalid validate_topic_name(topic) - def test_validate_topic_name_failures(self): + def test_validate_topic_name_failures(self) -> None: # topic name may not contain '?' with self.assertRaisesRegex(InvalidTopicNameException, 'must not contain characters'): validate_topic_name('/invalid_topic?') @@ -39,7 +39,7 @@ def test_validate_topic_name_failures(self): with self.assertRaisesRegex(InvalidTopicNameException, 'must not start with a number'): validate_topic_name('invalid/42topic') - def test_validate_topic_name_failures_service(self): + def test_validate_topic_name_failures_service(self) -> None: # service name may not contain '?' with self.assertRaisesRegex(InvalidServiceNameException, 'must not contain characters'): validate_topic_name('/invalid_service?', is_service=True) diff --git a/rclpy/test/test_wait_for_message.py b/rclpy/test/test_wait_for_message.py index 1aa8175fd..e587ea97a 100644 --- a/rclpy/test/test_wait_for_message.py +++ b/rclpy/test/test_wait_for_message.py @@ -38,7 +38,7 @@ def tearDownClass(cls): cls.node.destroy_node() rclpy.shutdown(context=cls.context) - def _publish_message(self): + def _publish_message(self) -> None: pub = self.node.create_publisher(BasicTypes, TOPIC_NAME, 1) msg = BasicTypes() msg.int32_value = MSG_DATA @@ -49,7 +49,7 @@ def _publish_message(self): time.sleep(1) pub.destroy() - def test_wait_for_message(self): + def test_wait_for_message(self) -> None: t = threading.Thread(target=self._publish_message) t.start() ret, msg = wait_for_message(BasicTypes, self.node, TOPIC_NAME, qos_profile=1) @@ -57,7 +57,7 @@ def test_wait_for_message(self): self.assertEqual(msg.int32_value, MSG_DATA) t.join() - def test_wait_for_message_qos(self): + def test_wait_for_message_qos(self) -> None: t = threading.Thread(target=self._publish_message) t.start() ret, msg = wait_for_message( @@ -66,7 +66,7 @@ def test_wait_for_message_qos(self): self.assertEqual(msg.int32_value, MSG_DATA) t.join() - def test_wait_for_message_timeout(self): + def test_wait_for_message_timeout(self) -> None: ret, _ = wait_for_message(BasicTypes, self.node, TOPIC_NAME, time_to_wait=1) self.assertFalse(ret) diff --git a/rclpy/test/test_waitable.py b/rclpy/test/test_waitable.py index 96b22f6c6..f243606ce 100644 --- a/rclpy/test/test_waitable.py +++ b/rclpy/test/test_waitable.py @@ -288,7 +288,7 @@ def add_to_wait_set(self, wait_set): class MutuallyExclusiveWaitable(Waitable): - def __init__(self): + def __init__(self) -> None: super().__init__(MutuallyExclusiveCallbackGroup()) def __enter__(self): @@ -300,7 +300,7 @@ def __exit__(self, exc_type, exc_val, exc_tb) -> None: def is_ready(self, wait_set): return False - def take_data(self): + def take_data(self) -> None: return None async def execute(self, taken_data): @@ -338,15 +338,15 @@ def start_spin_thread(self, waitable): self.thr.start() return self.thr - def setUp(self): + def setUp(self) -> None: pass - def tearDown(self): + def tearDown(self) -> None: self.node.remove_waitable(self.waitable) # Ensure resources inside the waitable are destroyed before the node in tearDownClass del self.waitable - def test_waitable_with_client(self): + def test_waitable_with_client(self) -> None: self.waitable = ClientWaitable(self.node) self.node.add_waitable(self.waitable) @@ -363,7 +363,7 @@ def test_waitable_with_client(self): assert isinstance(self.waitable.future.result()['client'], EmptySrv.Response) self.node.destroy_service(server) - def test_waitable_with_server(self): + def test_waitable_with_server(self) -> None: self.waitable = ServerWaitable(self.node) self.node.add_waitable(self.waitable) client = self.node.create_client(EmptySrv, 'test_server') @@ -376,7 +376,7 @@ def test_waitable_with_server(self): assert isinstance(self.waitable.future.result()['server'], EmptySrv.Request) self.node.destroy_client(client) - def test_waitable_with_timer(self): + def test_waitable_with_timer(self) -> None: self.waitable = TimerWaitable(self.node) self.node.add_waitable(self.waitable) @@ -386,7 +386,7 @@ def test_waitable_with_timer(self): assert self.waitable.future.done() assert self.waitable.future.result()['timer'] - def test_waitable_with_subscription(self): + def test_waitable_with_subscription(self) -> None: self.waitable = SubscriptionWaitable(self.node) self.node.add_waitable(self.waitable) pub = self.node.create_publisher(EmptyMsg, 'test_topic', 1) @@ -399,7 +399,7 @@ def test_waitable_with_subscription(self): assert isinstance(self.waitable.future.result()['subscription'], EmptyMsg) self.node.destroy_publisher(pub) - def test_waitable_with_guard_condition(self): + def test_waitable_with_guard_condition(self) -> None: self.waitable = GuardConditionWaitable(self.node) self.node.add_waitable(self.waitable) @@ -412,7 +412,7 @@ def test_waitable_with_guard_condition(self): # Test that waitable doesn't crash with MutuallyExclusiveCallbackGroup # https://github.com/ros2/rclpy/issues/264 - def test_waitable_with_mutually_exclusive_callback_group(self): + def test_waitable_with_mutually_exclusive_callback_group(self) -> None: self.waitable = MutuallyExclusiveWaitable() self.node.add_waitable(self.waitable) self.executor.spin_once(timeout_sec=0.1) @@ -420,7 +420,7 @@ def test_waitable_with_mutually_exclusive_callback_group(self): class TestNumberOfEntities(unittest.TestCase): - def test_add(self): + def test_add(self) -> None: n1 = NumberOfEntities(1, 2, 3, 4, 5, 6) n2 = NumberOfEntities(10, 20, 30, 40, 50, 60) n = n1 + n2 @@ -431,7 +431,7 @@ def test_add(self): assert n.num_services == 55 assert n.num_events == 66 - def test_add_assign(self): + def test_add_assign(self) -> None: n1 = NumberOfEntities(1, 2, 3, 4, 5, 6) n2 = NumberOfEntities(10, 20, 30, 40, 50, 60) n1 += n2