|
| 1 | +# Copyright 2025 Polymath Robotics, 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 | +from launch.action import Action |
| 16 | +from launch.frontend import expose_action |
| 17 | +import pytest |
| 18 | + |
| 19 | + |
| 20 | +@expose_action('while') |
| 21 | +class BuiltinNameTest(Action): |
| 22 | + """Test action that exposes a Python builtin name.""" |
| 23 | + |
| 24 | + def __init__(self, **kwargs): |
| 25 | + super().__init__(**kwargs) |
| 26 | + |
| 27 | + @classmethod |
| 28 | + def parse(cls, entity, parser): |
| 29 | + _, kwargs = super().parse(entity, parser) |
| 30 | + return cls, kwargs |
| 31 | + |
| 32 | + def execute(self, context): |
| 33 | + del context |
| 34 | + |
| 35 | + |
| 36 | +from launch_py import actions # noqa: I100, E402 |
| 37 | + |
| 38 | + |
| 39 | +def test_dynamic_attrs(): |
| 40 | + name = actions.let.__name__ |
| 41 | + assert name == 'let' |
| 42 | + str_repr = str(actions.let) |
| 43 | + assert str_repr.startswith('<function let') |
| 44 | + |
| 45 | + assert actions.while_.__name__ == 'while_' |
| 46 | + |
| 47 | + with pytest.raises(AttributeError): |
| 48 | + getattr(actions, 'non_existent_action') |
| 49 | + |
| 50 | + test_group = actions.group() |
| 51 | + assert test_group.type_name == 'group' |
| 52 | + |
| 53 | + test_arg = actions.arg(name='argname', default='argvalue') |
| 54 | + assert test_arg.type_name == 'arg' |
| 55 | + assert test_arg.get_attr('name') == 'argname' |
| 56 | + assert test_arg.get_attr('default') == 'argvalue' |
| 57 | + |
| 58 | + with pytest.raises(AttributeError): |
| 59 | + test_arg.get_attr('non_existent_attr') |
0 commit comments