Skip to content

Commit 00c870a

Browse files
committed
use support.run_with_tz
1 parent 3a8abdd commit 00c870a

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

Doc/library/smtplib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ An :class:`SMTP` instance has the following methods:
519519
is no way to unambiguously detect the most recent set of
520520
:mailheader:`Resent-` headers.
521521

522-
.. versionchanged:: 3.15
522+
.. versionchanged:: next
523523
Support to add :mailheader:`Date` header to the message if one does not exist.
524524

525525
``send_message`` serializes *msg* using

Lib/test/test_smtplib.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from unittest.mock import Mock
2727

2828

29+
2930
support.requires_working_socket(module=True)
3031

3132
HOST = socket_helper.HOST
@@ -1393,11 +1394,6 @@ class SMTPUTF8SimTests(unittest.TestCase):
13931394

13941395
maxDiff = None
13951396

1396-
def _is_local(self, date: str) -> bool:
1397-
dt = email.utils.parsedate_to_datetime(date)
1398-
local_offset = dt.now().astimezone().utcoffset()
1399-
return dt.utcoffset() == local_offset
1400-
14011397
def setUp(self):
14021398
self.thread_key = threading_helper.threading_setup()
14031399
self.real_getfqdn = socket.getfqdn
@@ -1472,6 +1468,7 @@ def test_send_unicode_with_SMTPUTF8_via_low_level_API(self):
14721468
self.assertIn('SMTPUTF8', self.serv.last_mail_options)
14731469
self.assertEqual(self.serv.last_rcpt_options, [])
14741470

1471+
@support.run_with_tz('UTC-2')
14751472
def test_send_message_uses_smtputf8_if_addrs_non_ascii(self):
14761473
msg = EmailMessage()
14771474
msg['From'] = "Páolo <fő[email protected]>"
@@ -1491,7 +1488,10 @@ def test_send_message_uses_smtputf8_if_addrs_non_ascii(self):
14911488
last_message = self.serv.last_message.decode()
14921489
date = email.message_from_string(last_message)['Date']
14931490
# asserts RFC 5322 section 3.3 4th Paragraph
1494-
self.assertTrue(self._is_local(date))
1491+
self.assertEqual(
1492+
email.utils.parsedate_to_datetime(date).tzname(),
1493+
"UTC+02:00"
1494+
)
14951495

14961496
expected = textwrap.dedent("""\
14971497
From: Páolo <fő[email protected]>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Fix ``smtplib.send_message`` to add a ``Date`` header if it is missing as
2-
per RFC5322.
2+
per :rfc:`5322`.

0 commit comments

Comments
 (0)