Patch by Jelle Zijlstra.
.. testsetup::
- >>> import email
- >>> from email.iterators import _structure
- >>> somefile = open('Lib/test/test_email/data/msg_02.txt')
+ import email
+ from email.iterators import _structure
+ somefile = open('../Lib/test/test_email/data/msg_02.txt')
.. doctest::
text/plain
text/plain
- .. testsetup::
+ .. testcleanup::
- >>> somefile.close()
+ somefile.close()
Optional *fp* is a file-like object to print the output to. It must be
suitable for Python's :func:`print` function. *level* is used internally.
.. testsetup::
- >>> from email import message_from_binary_file
- >>> with open('Lib/test/test_email/data/msg_16.txt', 'rb') as f:
- ... msg = message_from_binary_file(f)
- >>> from email.iterators import _structure
+ from email import message_from_binary_file
+ with open('../Lib/test/test_email/data/msg_16.txt', 'rb') as f:
+ msg = message_from_binary_file(f)
+ from email.iterators import _structure
.. doctest::
.. doctest::
>>> for part in msg.walk():
- ... print(part.get_content_maintype() == 'multipart'),
+ ... print(part.get_content_maintype() == 'multipart',
... part.is_multipart())
True True
False False
>>> _structure(msg)
multipart/report
text/plain
- message/delivery-status
- text/plain
- text/plain
- message/rfc822
- text/plain
+ message/delivery-status
+ text/plain
+ text/plain
+ message/rfc822
+ text/plain
Here the ``message`` parts are not ``multiparts``, but they do contain
subparts. ``is_multipart()`` returns ``True`` and ``walk`` descends
.. testsetup::
- >>> from unittest import mock
- >>> mocker = mock.patch('subprocess.Popen')
- >>> m = mocker.start()
- >>> proc = mock.MagicMock()
- >>> m.return_value = proc
- >>> proc.stdin.close.return_value = None
- >>> mymsg = open('mymsg.txt', 'w')
- >>> mymsg.write('To: abc@xyz.com\n\n')
- 17
- >>> mymsg.flush()
+ from unittest import mock
+ mocker = mock.patch('subprocess.Popen')
+ m = mocker.start()
+ proc = mock.MagicMock()
+ m.return_value = proc
+ proc.stdin.close.return_value = None
+ mymsg = open('mymsg.txt', 'w')
+ mymsg.write('To: abc@xyz.com\n\n')
+ mymsg.flush()
.. doctest::
>>> p.stdin.close()
>>> rc = p.wait()
-.. testsetup::
+.. testcleanup::
- >>> mymsg.close()
- >>> mocker.stop()
- >>> import os
- >>> os.remove('mymsg.txt')
+ mymsg.close()
+ mocker.stop()
+ import os
+ os.remove('mymsg.txt')
Here we are telling :class:`~email.generator.BytesGenerator` to use the RFC
correct line separator characters when creating the binary string to feed into