Skip to content

Commit 6cd6fd1

Browse files
authored
call ok() to see if rclpy and context is initialized. (#1198)
Signed-off-by: Tomoya.Fujita <[email protected]>
1 parent b4b4702 commit 6cd6fd1

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

rclpy/rclpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#. Process node callbacks
2323
#. Shutdown
2424
25-
Inititalization is done by calling :func:`init` for a particular :class:`.Context`.
25+
Initialization is done by calling :func:`init` for a particular :class:`.Context`.
2626
This must be done before any ROS nodes can be created.
2727
2828
Creating a ROS node is done by calling :func:`create_node` or by instantiating a

rclpy/test/test_context.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
def test_on_shutdown_method():
1919
context = Context()
2020
context.init()
21+
assert context.ok()
2122

2223
callback_called = False
2324

@@ -31,13 +32,15 @@ def on_shutdown(self):
3132
context.on_shutdown(instance.on_shutdown)
3233

3334
context.shutdown()
35+
assert not context.ok()
3436

3537
assert callback_called
3638

3739

3840
def test_on_shutdown_function():
3941
context = Context()
4042
context.init()
43+
assert context.ok()
4144

4245
callback_called = False
4346

@@ -48,6 +51,7 @@ def on_shutdown():
4851
context.on_shutdown(on_shutdown)
4952

5053
context.shutdown()
54+
assert not context.ok()
5155

5256
assert callback_called
5357

rclpy/test/test_init_shutdown.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
def test_init():
2323
context = rclpy.context.Context()
2424
rclpy.init(context=context)
25+
assert context.ok()
2526
rclpy.shutdown(context=context)
2627

2728

@@ -47,15 +48,19 @@ def test_init_with_non_utf8_arguments():
4748
def test_init_shutdown_sequence():
4849
context = rclpy.context.Context()
4950
rclpy.init(context=context)
51+
assert context.ok()
5052
rclpy.shutdown(context=context)
5153
context = rclpy.context.Context() # context cannot be reused but should not interfere
5254
rclpy.init(context=context)
55+
assert context.ok()
5356
rclpy.shutdown(context=context)
5457

5558
# global
5659
rclpy.init()
60+
assert rclpy.ok()
5761
rclpy.shutdown()
5862
rclpy.init()
63+
assert rclpy.ok()
5964
rclpy.shutdown()
6065

6166

@@ -72,6 +77,7 @@ def test_double_init():
7277
def test_double_shutdown():
7378
context = rclpy.context.Context()
7479
rclpy.init(context=context)
80+
assert context.ok()
7581
rclpy.shutdown(context=context)
7682
with pytest.raises(RuntimeError):
7783
rclpy.shutdown(context=context)

0 commit comments

Comments
 (0)