|
| 1 | +# Copyright 2026 Ekumen, 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 | +"""Unit tests for the shell class in lambkin.core.shell.""" |
| 16 | + |
| 17 | +import pytest |
| 18 | + |
| 19 | +from lambkin.core.shell import ShellProxy |
| 20 | + |
| 21 | + |
| 22 | +@pytest.fixture |
| 23 | +def shell(): |
| 24 | + """Return a fresh ShellProxy instance for each test.""" |
| 25 | + return ShellProxy() |
| 26 | + |
| 27 | + |
| 28 | +def test_simple_command(shell, capsys): |
| 29 | + """Test that a simple single-level command is printed correctly.""" |
| 30 | + shell.ros2.launch("beluga.launch.xml") |
| 31 | + assert capsys.readouterr().out == "[CMD]: ros2 launch beluga.launch.xml\n" |
| 32 | + |
| 33 | + |
| 34 | +def test_chained_command(shell, capsys): |
| 35 | + """Test that chained attribute access builds the command word by word.""" |
| 36 | + shell.ros2.bag.play("my_bag") |
| 37 | + assert capsys.readouterr().out == "[CMD]: ros2 bag play my_bag\n" |
| 38 | + |
| 39 | + |
| 40 | +def test_multiple_args(shell, capsys): |
| 41 | + """Test that multiple positional arguments are appended in order.""" |
| 42 | + shell.ros2.bag.play("my_bag", "--clock", "-r", "1.0") |
| 43 | + assert capsys.readouterr().out == "[CMD]: ros2 bag play my_bag --clock -r 1.0\n" |
| 44 | + |
| 45 | + |
| 46 | +def test_kwarg_becomes_flag(shell, capsys): |
| 47 | + """Test that keyword arguments are converted to --flag value pairs.""" |
| 48 | + shell.evo_ape.bag2("output.mcap", save_results="out.zip") |
| 49 | + assert ( |
| 50 | + capsys.readouterr().out |
| 51 | + == "[CMD]: evo_ape bag2 output.mcap --save-results out.zip\n" |
| 52 | + ) |
| 53 | + |
| 54 | + |
| 55 | +def test_arbitrary_tool(shell, capsys): |
| 56 | + """Test that any top-level tool name works without hardcoding.""" |
| 57 | + shell.evo.traj("output.mcap") |
| 58 | + assert capsys.readouterr().out == "[CMD]: evo traj output.mcap\n" |
0 commit comments