def test_report_undecodable_stdout_and_stderr(mocker: MockerFixture) -> None: from_addr = Address("Command Reporter", addr_spec="*****@*****.**") to_addrs = [Address("Re Cipient", addr_spec="*****@*****.**")] result = CommandResult( argv=["foo", "-x", "bar.txt"], rc=0, start=datetime(2020, 3, 10, 15, 0, 28, 123456, w4), end=datetime(2020, 3, 10, 15, 1, 27, 654321, w4), stdout=b"\xD0is is i\xF1 L\xE1tin\xB9.\n", stderr=b"\xE3\x88\x89\xA2@\x89\xA2@\x89\x95@\xC5\xC2\xC3\xC4\xC9\xC3K%", ) reporter = CommandReporter( encoding="utf-8", failure_only=False, from_addr=from_addr, mime_type=None, nonempty=False, stderr_encoding="utf-8", stdout_filename=None, to_addrs=to_addrs, utc=False, ) show_argv_spy = mocker.spy(util, "show_argv") msg = reporter.report(result) assert isinstance(msg, DraftMessage) assert attr.asdict(msg, recurse=False) == { "to_addrs": to_addrs, "subject": "[DONE] foo -x bar.txt", "from_addr": from_addr, "parts": [ ("Start Time: 2020-03-10 15:00:28.123456-04:00\n" "End Time: 2020-03-10 15:01:27.654321-04:00\n" "Exit Status: 0\n" "\n" "Output:\n"), BytesAttachment( b"\xD0is is i\xF1 L\xE1tin\xB9.\n", "stdout", content_type="application/octet-stream", inline=True, ), "\nError Output:\n", BytesAttachment( b"\xE3\x88\x89\xA2@\x89\xA2@\x89\x95@\xC5\xC2\xC3\xC4\xC9\xC3K%", "stderr", content_type="application/octet-stream", inline=True, ), ], } show_argv_spy.assert_called_once_with(*result.argv)
def test_report_utc(mocker: MockerFixture) -> None: from_addr = Address("Command Reporter", addr_spec="*****@*****.**") to_addrs = [Address("Re Cipient", addr_spec="*****@*****.**")] result = CommandResult( argv=["foo", "-x", "bar.txt"], rc=0, start=datetime(2020, 3, 10, 15, 0, 28, 123456, w4), end=datetime(2020, 3, 10, 15, 1, 27, 654321, w4), stdout=b"This is the output.\n", stderr=b"", ) reporter = CommandReporter( encoding="utf-8", failure_only=False, from_addr=from_addr, mime_type=None, nonempty=False, stderr_encoding="utf-8", stdout_filename=None, to_addrs=to_addrs, utc=True, ) show_argv_spy = mocker.spy(util, "show_argv") msg = reporter.report(result) assert isinstance(msg, DraftMessage) assert attr.asdict(msg) == { "to_addrs": to_addrs, "subject": "[DONE] foo -x bar.txt", "from_addr": from_addr, "parts": [ "Start Time: 2020-03-10 19:00:28.123456Z\n" "End Time: 2020-03-10 19:01:27.654321Z\n" "Exit Status: 0\n" "\n" "Output:\n" "> This is the output.\n", ], } show_argv_spy.assert_called_once_with(*result.argv)
False, False, False, { "stdout": subprocess.PIPE, "stderr": subprocess.STDOUT }, SimpleNamespace( returncode=sentinel.rc, stdout=sentinel.stdout, stderr=sentinel.stderr, ), CommandResult( argv=ARGV, rc=sentinel.rc, start=MOCK_START, end=MOCK_END, stdout=sentinel.stdout, stderr=sentinel.stderr, ), ), ( False, False, False, { "stdout": subprocess.PIPE, "stderr": subprocess.STDOUT }, ERROR, CommandError( argv=ARGV,
from daemail import util from daemail.message import DraftMessage from daemail.reporter import CommandReporter from daemail.runner import CommandError, CommandResult w4 = timezone(timedelta(hours=-4)) @pytest.mark.parametrize( "result,subject,body", [ ( CommandResult( argv=["foo", "-x", "bar.txt"], rc=0, start=datetime(2020, 3, 10, 15, 0, 28, 123456, w4), end=datetime(2020, 3, 10, 15, 1, 27, 654321, w4), stdout=b"This is the output.\n", stderr=b"", ), "[DONE] foo -x bar.txt", "Start Time: 2020-03-10 15:00:28.123456-04:00\n" "End Time: 2020-03-10 15:01:27.654321-04:00\n" "Exit Status: 0\n" "\n" "Output:\n" "> This is the output.\n", ), ( CommandResult( argv=["foo", "-x", "bar.txt"], rc=0,