forked from felixdivo/ros2-easy-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixture_test.py
37 lines (26 loc) · 1.2 KB
/
fixture_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
# Standard library
import unittest
# Testing and interfaces
import pytest
from std_msgs.msg import String
# Testing
from ros2_easy_test import ROS2TestEnvironment, with_single_node
# Module under test
from ..example_nodes.well_behaved import EchoNode
@pytest.fixture(autouse=True)
def the_message() -> str:
return "The message which should get echoed back!"
@with_single_node(EchoNode, watch_topics={"/mouth": String})
def test_fixture_in_beginning(the_message: str, env: ROS2TestEnvironment) -> None:
"""A demo for combining a pytest fixture and ros2_easy_test."""
env.publish("/ear", String(data=the_message))
response: str = env.assert_message_published("/mouth").data
assert response == the_message, (response, the_message)
@with_single_node(EchoNode, watch_topics={"/mouth": String})
def test_fixture_as_last_argument(env: ROS2TestEnvironment, the_message: str) -> None:
"""The same as :func:`~test_fixture_in_beginning`, but with a different parameter order."""
env.publish("/ear", String(data=the_message))
response: str = env.assert_message_published("/mouth").data
assert response == the_message, (response, the_message)
if __name__ == "__main__":
unittest.main()