(self, mock_exit)
| 460 | @trap |
| 461 | @patch("invoke.program.sys.exit") |
| 462 | def UnexpectedExit_str_encodes_stdout_and_err(self, mock_exit): |
| 463 | p = Program() |
| 464 | oops = UnexpectedExit( |
| 465 | Result( |
| 466 | command="meh", |
| 467 | exited=54, |
| 468 | stdout="this is not ascii: \u1234", |
| 469 | stderr="this is also not ascii: \u4321", |
| 470 | encoding="utf-8", |
| 471 | hide=("stdout", "stderr"), |
| 472 | ) |
| 473 | ) |
| 474 | p.execute = Mock(side_effect=oops) |
| 475 | p.run("myapp foo") |
| 476 | # NOTE: using explicit binary ASCII here, & accessing raw |
| 477 | # getvalue() of the faked sys.stderr (spec.trap auto-decodes it |
| 478 | # normally) to have a not-quite-tautological test. otherwise we'd |
| 479 | # just be comparing unicode to unicode. shrug? |
| 480 | expected = b"""Encountered a bad command exit code! |
| 481 | |
| 482 | Command: 'meh' |
| 483 | |
| 484 | Exit code: 54 |
| 485 | |
| 486 | Stdout: |
| 487 | |
| 488 | this is not ascii: \xe1\x88\xb4 |
| 489 | |
| 490 | Stderr: |
| 491 | |
| 492 | this is also not ascii: \xe4\x8c\xa1 |
| 493 | |
| 494 | """ |
| 495 | got = BytesIO.getvalue(sys.stderr) |
| 496 | assert got == expected |
| 497 | |
| 498 | class Exit_: |
| 499 | @patch("invoke.program.sys.exit") |
nothing calls this directly
no test coverage detected