MCPcopy Index your code
hub / github.com/pyinvoke/invoke / UnexpectedExit_str_encodes_stdout_and_err

Method UnexpectedExit_str_encodes_stdout_and_err

tests/program.py:462–496  ·  view source on GitHub ↗
(self, mock_exit)

Source from the content-addressed store, hash-verified

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
482Command: 'meh'
483
484Exit code: 54
485
486Stdout:
487
488this is not ascii: \xe1\x88\xb4
489
490Stderr:
491
492this 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")

Callers

nothing calls this directly

Calls 4

runMethod · 0.95
ProgramClass · 0.90
UnexpectedExitClass · 0.90
ResultClass · 0.90

Tested by

no test coverage detected