Test that _read_command_line uses a dynamic prompt when provided prompt matches app.prompt
(base_app: cmd2.Cmd)
| 4393 | |
| 4394 | |
| 4395 | def test_read_command_line_dynamic_prompt(base_app: cmd2.Cmd) -> None: |
| 4396 | """Test that _read_command_line uses a dynamic prompt when provided prompt matches app.prompt""" |
| 4397 | |
| 4398 | # Mock patch_stdout to prevent it from attempting to access the Windows |
| 4399 | # console buffer in a Windows test environment. |
| 4400 | with mock.patch("cmd2.cmd2.patch_stdout"): |
| 4401 | # Set input to something other than DummyInput so _read_raw_input() |
| 4402 | # will go down the TTY route. |
| 4403 | mock_session = mock.MagicMock() |
| 4404 | mock_session.input = mock.MagicMock() |
| 4405 | base_app.main_session = mock_session |
| 4406 | base_app._read_command_line(base_app.prompt) |
| 4407 | |
| 4408 | # Check that mock_prompt was called with a callable for the prompt |
| 4409 | args, _ = mock_session.prompt.call_args |
| 4410 | prompt_arg = args[0] |
| 4411 | assert callable(prompt_arg) |
| 4412 | |
| 4413 | # Verify the callable returns the expected ANSI formatted prompt |
| 4414 | from prompt_toolkit.formatted_text import ANSI |
| 4415 | |
| 4416 | result = prompt_arg() |
| 4417 | assert isinstance(result, ANSI) |
| 4418 | assert result.value == ANSI(base_app.prompt).value |
| 4419 | |
| 4420 | |
| 4421 | def test_read_input_history_isolation(base_app: cmd2.Cmd) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…