(base_app: cmd2.Cmd)
| 3466 | |
| 3467 | |
| 3468 | def test_ppretty(base_app: cmd2.Cmd) -> None: |
| 3469 | # Mock the Pretty class and the print_to() method |
| 3470 | with mock.patch("cmd2.cmd2.Pretty") as mock_pretty, mock.patch.object(cmd2.Cmd, "print_to") as mock_print_to: |
| 3471 | # Set up the mock return value for Pretty |
| 3472 | mock_pretty_obj = mock.Mock() |
| 3473 | mock_pretty.return_value = mock_pretty_obj |
| 3474 | |
| 3475 | test_obj = {"key": "value"} |
| 3476 | |
| 3477 | # Call ppretty() with some custom arguments |
| 3478 | base_app.ppretty( |
| 3479 | test_obj, |
| 3480 | indent_size=2, |
| 3481 | max_depth=5, |
| 3482 | expand_all=True, |
| 3483 | end="\n\n", |
| 3484 | ) |
| 3485 | |
| 3486 | # Verify Pretty was instantiated with the correct arguments |
| 3487 | mock_pretty.assert_called_once_with( |
| 3488 | test_obj, |
| 3489 | indent_size=2, |
| 3490 | indent_guides=True, |
| 3491 | max_length=None, |
| 3492 | max_string=None, |
| 3493 | max_depth=5, |
| 3494 | expand_all=True, |
| 3495 | overflow="ignore", |
| 3496 | ) |
| 3497 | |
| 3498 | # Verify print_to() was called with the mock pretty object and soft_wrap=True |
| 3499 | # It should default to self.stdout when no file is provided |
| 3500 | mock_print_to.assert_called_once_with( |
| 3501 | base_app.stdout, |
| 3502 | mock_pretty_obj, |
| 3503 | soft_wrap=True, |
| 3504 | end="\n\n", |
| 3505 | ) |
| 3506 | |
| 3507 | |
| 3508 | # we override cmd.parseline() so we always get consistent |
nothing calls this directly
no test coverage detected
searching dependent graphs…