MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / test_cmd2_base_console_log

Function test_cmd2_base_console_log

tests/test_rich_utils.py:155–174  ·  view source on GitHub ↗

Test that Cmd2BaseConsole.log() calls prepare_objects_for_rendering() and increments _stack_offset.

(mocker: MockerFixture)

Source from the content-addressed store, hash-verified

153
154
155def 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)

Callers

nothing calls this directly

Calls 1

logMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…