forked from felixdivo/ros2-easy-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreuse_decorator_test.py
38 lines (26 loc) · 944 Bytes
/
reuse_decorator_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Standard library
import unittest
from functools import partial
# ROS2 interfaces
from std_msgs.msg import String
# Testing
from ros2_easy_test import ROS2TestEnvironment, with_single_node
# Module under test and interfaces
from ..example_nodes.well_behaved import EchoNode
# This does not work:
# alias = with_single_node(EchoNode, watch_topics={"/mouth": String})
# Use this instead:
alias = partial(with_single_node, EchoNode, watch_topics={"/mouth": String})
def base_function(env: ROS2TestEnvironment) -> None:
the_message = "some kind words"
env.publish("/ear", String(data=the_message))
response: str = env.assert_message_published("/mouth").data
assert response == the_message, (response, the_message)
@alias()
def test_1(env: ROS2TestEnvironment) -> None:
base_function(env)
@alias()
def test_2(env: ROS2TestEnvironment) -> None:
base_function(env)
if __name__ == "__main__":
unittest.main()