Issue #27209: Fix doctests in Doc/library/email*.rst

Patch by Jelle Zijlstra.
This commit is contained in:
Zachary Ware 2016-08-10 00:39:41 -05:00
parent c90fccdff6
commit 640b1ca507
3 changed files with 29 additions and 30 deletions

View File

@ -50,9 +50,9 @@ The following function has been added as a useful debugging tool. It should
.. testsetup:: .. testsetup::
>>> import email import email
>>> from email.iterators import _structure from email.iterators import _structure
>>> somefile = open('Lib/test/test_email/data/msg_02.txt') somefile = open('../Lib/test/test_email/data/msg_02.txt')
.. doctest:: .. doctest::
@ -74,9 +74,9 @@ The following function has been added as a useful debugging tool. It should
text/plain text/plain
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 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. suitable for Python's :func:`print` function. *level* is used internally.

View File

@ -602,10 +602,10 @@ Here are the methods of the :class:`Message` class:
.. testsetup:: .. testsetup::
>>> from email import message_from_binary_file from email import message_from_binary_file
>>> with open('Lib/test/test_email/data/msg_16.txt', 'rb') as f: with open('../Lib/test/test_email/data/msg_16.txt', 'rb') as f:
... msg = message_from_binary_file(f) msg = message_from_binary_file(f)
>>> from email.iterators import _structure from email.iterators import _structure
.. doctest:: .. doctest::
@ -628,7 +628,7 @@ Here are the methods of the :class:`Message` class:
.. doctest:: .. doctest::
>>> for part in msg.walk(): >>> for part in msg.walk():
... print(part.get_content_maintype() == 'multipart'), ... print(part.get_content_maintype() == 'multipart',
... part.is_multipart()) ... part.is_multipart())
True True True True
False False False False
@ -640,11 +640,11 @@ Here are the methods of the :class:`Message` class:
>>> _structure(msg) >>> _structure(msg)
multipart/report multipart/report
text/plain text/plain
message/delivery-status message/delivery-status
text/plain text/plain
text/plain text/plain
message/rfc822 message/rfc822
text/plain text/plain
Here the ``message`` parts are not ``multiparts``, but they do contain Here the ``message`` parts are not ``multiparts``, but they do contain
subparts. ``is_multipart()`` returns ``True`` and ``walk`` descends subparts. ``is_multipart()`` returns ``True`` and ``walk`` descends

View File

@ -63,16 +63,15 @@ file on disk and pass it to the system ``sendmail`` program on a Unix system:
.. testsetup:: .. testsetup::
>>> from unittest import mock from unittest import mock
>>> mocker = mock.patch('subprocess.Popen') mocker = mock.patch('subprocess.Popen')
>>> m = mocker.start() m = mocker.start()
>>> proc = mock.MagicMock() proc = mock.MagicMock()
>>> m.return_value = proc m.return_value = proc
>>> proc.stdin.close.return_value = None proc.stdin.close.return_value = None
>>> mymsg = open('mymsg.txt', 'w') mymsg = open('mymsg.txt', 'w')
>>> mymsg.write('To: abc@xyz.com\n\n') mymsg.write('To: abc@xyz.com\n\n')
17 mymsg.flush()
>>> mymsg.flush()
.. doctest:: .. doctest::
@ -88,12 +87,12 @@ file on disk and pass it to the system ``sendmail`` program on a Unix system:
>>> p.stdin.close() >>> p.stdin.close()
>>> rc = p.wait() >>> rc = p.wait()
.. testsetup:: .. testcleanup::
>>> mymsg.close() mymsg.close()
>>> mocker.stop() mocker.stop()
>>> import os import os
>>> os.remove('mymsg.txt') os.remove('mymsg.txt')
Here we are telling :class:`~email.generator.BytesGenerator` to use the RFC Here we are telling :class:`~email.generator.BytesGenerator` to use the RFC
correct line separator characters when creating the binary string to feed into correct line separator characters when creating the binary string to feed into