|
| 1 | +# Copyright 2021 Open Source Robotics Foundation, Inc. |
| 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 filecmp |
| 16 | +import pathlib |
| 17 | + |
| 18 | +from rosidl_cli.command.translate.api import translate |
| 19 | + |
| 20 | + |
| 21 | +DATA_PATH = pathlib.Path(__file__).parent / 'data' |
| 22 | + |
| 23 | + |
| 24 | +def test_translation_extensions(tmp_path, capsys): |
| 25 | + # NOTE(hidmic): pytest and empy do not play along, |
| 26 | + # the latter expects some proxy will stay in sys.stdout |
| 27 | + # and the former insists in overwriting it |
| 28 | + |
| 29 | + with capsys.disabled(): # so do everything in one run |
| 30 | + # Test .msg to .idl translation |
| 31 | + idl_files = translate( |
| 32 | + package_name='test_msgs', |
| 33 | + interface_files=[ |
| 34 | + f'{DATA_PATH}:msg/Test.msg'], |
| 35 | + output_path=tmp_path, |
| 36 | + output_format='idl', |
| 37 | + translators=['msg2idl'] |
| 38 | + ) |
| 39 | + |
| 40 | + assert len(idl_files) == 1 |
| 41 | + idl_file = idl_files[0] |
| 42 | + assert idl_file == f'{tmp_path}:msg/Test.idl' |
| 43 | + assert filecmp.cmp( |
| 44 | + tmp_path / 'msg' / 'Test.idl', |
| 45 | + DATA_PATH / 'msg' / 'Test.expected.idl', |
| 46 | + shallow=False |
| 47 | + ) |
| 48 | + |
| 49 | + # Test .srv to .idl translation |
| 50 | + idl_files = translate( |
| 51 | + package_name='test_msgs', |
| 52 | + interface_files=[ |
| 53 | + f'{DATA_PATH}:srv/Test.srv'], |
| 54 | + output_path=tmp_path, |
| 55 | + output_format='idl', |
| 56 | + translators=['srv2idl'] |
| 57 | + ) |
| 58 | + |
| 59 | + assert len(idl_files) == 1 |
| 60 | + idl_file = idl_files[0] |
| 61 | + assert idl_file == f'{tmp_path}:srv/Test.idl' |
| 62 | + assert filecmp.cmp( |
| 63 | + tmp_path / 'srv' / 'Test.idl', |
| 64 | + DATA_PATH / 'srv' / 'Test.expected.idl', |
| 65 | + shallow=False |
| 66 | + ) |
| 67 | + |
| 68 | + # Test .action to .idl translation |
| 69 | + idl_files = translate( |
| 70 | + package_name='test_msgs', |
| 71 | + interface_files=[ |
| 72 | + f'{DATA_PATH}:action/Test.action'], |
| 73 | + output_path=tmp_path, |
| 74 | + output_format='idl', |
| 75 | + translators=['action2idl'] |
| 76 | + ) |
| 77 | + |
| 78 | + assert len(idl_files) == 1 |
| 79 | + idl_file = idl_files[0] |
| 80 | + assert idl_file == f'{tmp_path}:action/Test.idl' |
| 81 | + assert filecmp.cmp( |
| 82 | + tmp_path / 'action' / 'Test.idl', |
| 83 | + DATA_PATH / 'action' / 'Test.expected.idl', |
| 84 | + shallow=False |
| 85 | + ) |
0 commit comments