From 640b1ca50779cd40427a4ebfe8ea56f58a0d935d Mon Sep 17 00:00:00 2001
From: Zachary Ware <zachary.ware@gmail.com>
Date: Wed, 10 Aug 2016 00:39:41 -0500
Subject: [PATCH] Issue #27209: Fix doctests in Doc/library/email*.rst

Patch by Jelle Zijlstra.
---
 Doc/library/email.iterators.rst | 10 +++++-----
 Doc/library/email.message.rst   | 20 ++++++++++----------
 Doc/library/email.policy.rst    | 29 ++++++++++++++---------------
 3 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/Doc/library/email.iterators.rst b/Doc/library/email.iterators.rst
index f3e9e184a5..d53ab33b89 100644
--- a/Doc/library/email.iterators.rst
+++ b/Doc/library/email.iterators.rst
@@ -50,9 +50,9 @@ The following function has been added as a useful debugging tool.  It should
 
    .. 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::
 
@@ -74,9 +74,9 @@ The following function has been added as a useful debugging tool.  It should
                   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.
diff --git a/Doc/library/email.message.rst b/Doc/library/email.message.rst
index 91a694f3ec..2907975357 100644
--- a/Doc/library/email.message.rst
+++ b/Doc/library/email.message.rst
@@ -602,10 +602,10 @@ Here are the methods of the :class:`Message` class:
 
       .. 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::
 
@@ -628,7 +628,7 @@ Here are the methods of the :class:`Message` class:
       .. 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
@@ -640,11 +640,11 @@ Here are the methods of the :class:`Message` class:
          >>> _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
diff --git a/Doc/library/email.policy.rst b/Doc/library/email.policy.rst
index 47f321227a..2a6047d3a4 100644
--- a/Doc/library/email.policy.rst
+++ b/Doc/library/email.policy.rst
@@ -63,16 +63,15 @@ file on disk and pass it to the system ``sendmail`` program on a Unix system:
 
 .. 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::
 
@@ -88,12 +87,12 @@ file on disk and pass it to the system ``sendmail`` program on a Unix system:
    >>> 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
-- 
2.40.0