Skip to content

Commit 22c3175

Browse files
email parse depends on python patch version (move-coop#1146)
1 parent 710532a commit 22c3175

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

test/test_gmail/test_gmail.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import json
33
import os
44
import requests_mock
5+
import email
56
import unittest
67
import shutil
78
import base64
8-
import email
99

1010

1111
_dir = os.path.dirname(__file__)
@@ -516,10 +516,27 @@ def test__validate_email_string(self):
516516
{"email": "<[email protected]>", "expected": True},
517517
{"email": "Sender [email protected]", "expected": False},
518518
{"email": "Sender <sender2email.com>", "expected": False},
519-
{"email": "Sender <sender@email,com>", "expected": True},
520-
{"email": "Sender <sender+alias@email,com>", "expected": True},
521519
]
522520

521+
# The behavior of email.parseaddr depends on the python patch version
522+
# See https://github.com/python/cpython/issues/102988
523+
# or associated changelogs, e.g.
524+
# https://docs.python.org/3.8/whatsnew/changelog.html#python-3-8-20-final
525+
if getattr(email.utils, "supports_strict_parsing", False):
526+
emails.extend(
527+
[
528+
{"email": "Sender <sender@email,com>", "expected": False},
529+
{"email": "Sender <sender+alias@email,com>", "expected": False},
530+
]
531+
)
532+
else:
533+
emails.extend(
534+
[
535+
{"email": "Sender <sender@email,com>", "expected": True},
536+
{"email": "Sender <sender+alias@email,com>", "expected": True},
537+
]
538+
)
539+
523540
for e in emails:
524541
if e["expected"]:
525542
self.assertTrue(self.gmail._validate_email_string(e["email"]))

0 commit comments

Comments
 (0)