Test that Cmd2BaseConsole.log() calls prepare_objects_for_rendering() and increments _stack_offset.
(mocker: MockerFixture)
| 153 | |
| 154 | |
| 155 | def test_cmd2_base_console_log(mocker: MockerFixture) -> None: |
| 156 | """Test that Cmd2BaseConsole.log() calls prepare_objects_for_rendering() and increments _stack_offset.""" |
| 157 | # Mock prepare_objects_for_rendering to return a specific value |
| 158 | prepared_val = ("prepared",) |
| 159 | mock_prepare = mocker.patch("cmd2.rich_utils.prepare_objects_for_rendering", return_value=prepared_val) |
| 160 | |
| 161 | # Mock the superclass log() method |
| 162 | mock_super_log = mocker.patch("rich.console.Console.log") |
| 163 | |
| 164 | console = ru.Cmd2BaseConsole() |
| 165 | console.log("test", _stack_offset=2) |
| 166 | |
| 167 | # Verify that prepare_objects_for_rendering() was called with the input objects |
| 168 | mock_prepare.assert_called_once_with("test") |
| 169 | |
| 170 | # Verify that the superclass log() method was called with the prepared objects |
| 171 | # and that the stack offset was correctly incremented. |
| 172 | args, kwargs = mock_super_log.call_args |
| 173 | assert args == prepared_val |
| 174 | assert kwargs["_stack_offset"] == 3 |
| 175 | |
| 176 | |
| 177 | @with_ansi_style(ru.AllowStyle.ALWAYS) |
nothing calls this directly
no test coverage detected
searching dependent graphs…