aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_email/test_email.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2022-04-14 17:48:59 -0700
committerGitHub <noreply@github.com>2022-04-14 17:48:59 -0700
commit1fcb39ea64192fc83e7b52f067856bdf977ec2c1 (patch)
treedff4a834789692a338f8d210690a6bbfbb614dc4 /Lib/test/test_email/test_email.py
parentee475430d431814cbb6eb5e8a6c0ae51943349d4 (diff)
downloadcpython-1fcb39ea64192fc83e7b52f067856bdf977ec2c1.tar.gz
cpython-1fcb39ea64192fc83e7b52f067856bdf977ec2c1.zip
gh-91520: Rewrite imghdr inlining for clarity and completeness (#91521)
* Rewrite imghdr inlining for clarity and completeness * Move MIMEImage class back closer to the top of the file since it's the important thing. * Use a decorate to mark a given rule function and simplify the rule function names for clarity. * Copy over all the imghdr test data files into the email package's test data directory. This way when imghdr is actually removed, it won't affect the MIMEImage guessing tests. * Rewrite and extend the MIMEImage tests to test for all supported auto-detected MIME image subtypes. * Remove the now redundant PyBanner048.gif data file. * See https://github.com/python/cpython/pull/91461#discussion_r850313336 Co-authored-by: Oleg Iarygin <dralife@yandex.ru> Co-authored-by: Oleg Iarygin <dralife@yandex.ru>
Diffstat (limited to 'Lib/test/test_email/test_email.py')
-rw-r--r--Lib/test/test_email/test_email.py34
1 files changed, 27 insertions, 7 deletions
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index b87dae22de1..6ead5947acb 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -798,7 +798,7 @@ class TestMessageAPI(TestEmailBase):
class TestEncoders(unittest.TestCase):
def test_EncodersEncode_base64(self):
- with openfile('PyBanner048.gif', 'rb') as fp:
+ with openfile('python.gif', 'rb') as fp:
bindata = fp.read()
mimed = email.mime.image.MIMEImage(bindata)
base64ed = mimed.get_payload()
@@ -1555,24 +1555,44 @@ class TestMIMEAudio(unittest.TestCase):
# Test the basic MIMEImage class
class TestMIMEImage(unittest.TestCase):
- def setUp(self):
- with openfile('PyBanner048.gif', 'rb') as fp:
+ def _make_image(self, ext):
+ with openfile(f'python.{ext}', 'rb') as fp:
self._imgdata = fp.read()
self._im = MIMEImage(self._imgdata)
def test_guess_minor_type(self):
- self.assertEqual(self._im.get_content_type(), 'image/gif')
+ for ext, subtype in {
+ 'bmp': None,
+ 'exr': None,
+ 'gif': None,
+ 'jpg': 'jpeg',
+ 'pbm': None,
+ 'pgm': None,
+ 'png': None,
+ 'ppm': None,
+ 'ras': 'rast',
+ 'sgi': 'rgb',
+ 'tiff': None,
+ 'webp': None,
+ 'xbm': None,
+ }.items():
+ self._make_image(ext)
+ subtype = ext if subtype is None else subtype
+ self.assertEqual(self._im.get_content_type(), f'image/{subtype}')
def test_encoding(self):
+ self._make_image('gif')
payload = self._im.get_payload()
self.assertEqual(base64.decodebytes(bytes(payload, 'ascii')),
- self._imgdata)
+ self._imgdata)
def test_checkSetMinor(self):
+ self._make_image('gif')
im = MIMEImage(self._imgdata, 'fish')
self.assertEqual(im.get_content_type(), 'image/fish')
def test_add_header(self):
+ self._make_image('gif')
eq = self.assertEqual
self._im.add_header('Content-Disposition', 'attachment',
filename='dingusfish.gif')
@@ -1747,7 +1767,7 @@ class TestMIMEText(unittest.TestCase):
# Test complicated multipart/* messages
class TestMultipart(TestEmailBase):
def setUp(self):
- with openfile('PyBanner048.gif', 'rb') as fp:
+ with openfile('python.gif', 'rb') as fp:
data = fp.read()
container = MIMEBase('multipart', 'mixed', boundary='BOUNDARY')
image = MIMEImage(data, name='dingusfish.gif')
@@ -3444,7 +3464,7 @@ multipart/report
def test_mime_classes_policy_argument(self):
with openfile('audiotest.au', 'rb') as fp:
audiodata = fp.read()
- with openfile('PyBanner048.gif', 'rb') as fp:
+ with openfile('python.gif', 'rb') as fp:
bindata = fp.read()
classes = [
(MIMEApplication, ('',)),