|
| 1 | +# Copyright 2020 Sony Corporation. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import argparse |
| 16 | + |
| 17 | +import pytest |
| 18 | + |
| 19 | +from ros2cli.node.direct import add_arguments as add_direct_node_arguments |
| 20 | +from ros2cli.node.direct import DEFAULT_TIMEOUT |
| 21 | +from ros2cli.node.direct import DirectNode |
| 22 | + |
| 23 | +TEST_NODE_NAME = 'test_node' |
| 24 | + |
| 25 | + |
| 26 | +@pytest.fixture(scope='function') |
| 27 | +def test_arguments_parser(): |
| 28 | + parser = argparse.ArgumentParser() |
| 29 | + add_direct_node_arguments(parser) |
| 30 | + return parser |
| 31 | + |
| 32 | + |
| 33 | +def test_default_arguments(test_arguments_parser): |
| 34 | + args = test_arguments_parser.parse_args() |
| 35 | + assert not args.use_sim_time |
| 36 | + assert DEFAULT_TIMEOUT == args.spin_time |
| 37 | + |
| 38 | + |
| 39 | +def test_use_sim_time_arguments(test_arguments_parser): |
| 40 | + args = test_arguments_parser.parse_args(['--use-sim-time']) |
| 41 | + assert args.use_sim_time |
| 42 | + assert DEFAULT_TIMEOUT == args.spin_time |
| 43 | + |
| 44 | + |
| 45 | +def test_spin_time_arguments(test_arguments_parser): |
| 46 | + args = test_arguments_parser.parse_args(['--spin-time', '10.0']) |
| 47 | + assert not args.use_sim_time |
| 48 | + assert 10.0 == args.spin_time |
| 49 | + |
| 50 | + |
| 51 | +def test_use_sim_time_parameter(): |
| 52 | + with DirectNode(args=[], node_name=TEST_NODE_NAME) as direct_node: |
| 53 | + assert not direct_node.node.get_parameter('use_sim_time').value |
| 54 | + |
| 55 | + args = argparse.Namespace(use_sim_time=False) |
| 56 | + with DirectNode(args, node_name=TEST_NODE_NAME) as direct_node: |
| 57 | + assert not direct_node.node.get_parameter('use_sim_time').value |
| 58 | + |
| 59 | + # TODO(fujitatomoya): enable this test once /clock callback thread is insulated. |
| 60 | + # see https://github.com/ros2/rclcpp/issues/1542 |
| 61 | + # args = argparse.Namespace(use_sim_time=True) |
| 62 | + # with DirectNode(args, node_name=TEST_NODE_NAME) as direct_node: |
| 63 | + # assert direct_node.node.get_parameter('use_sim_time').value |
0 commit comments