summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-05-26 13:29:45 (GMT)
committerGitHub <noreply@github.com>2023-05-26 13:29:45 (GMT)
commite399f46a77263621610b350453e0f50252c6dc08 (patch)
treec90da37d75dffaba32a031488c406fea1d7db022 /Lib/test
parentba73473f4c18ba4cf7ab18d84d94a47d2d37a0c5 (diff)
downloadcpython-e399f46a77263621610b350453e0f50252c6dc08.zip
cpython-e399f46a77263621610b350453e0f50252c6dc08.tar.gz
cpython-e399f46a77263621610b350453e0f50252c6dc08.tar.bz2
gh-104773: PEP 594: Remove the imghdr module (#104777)
* Remove the Lib/test/imghdrdata/ directory. * Copy 5 pictures (gif, png, ppm, pgm, xbm) from removed Lib/test/imghdrdata/ to a new Lib/test/tkinterdata/ directory. * Update Sphinx from 4.5 to 6.2 in Doc/requirements.txt.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/imghdrdata/python-raw.jpgbin525 -> 0 bytes
-rw-r--r--Lib/test/imghdrdata/python.bmpbin1162 -> 0 bytes
-rw-r--r--Lib/test/imghdrdata/python.exrbin2635 -> 0 bytes
-rw-r--r--Lib/test/imghdrdata/python.jpgbin543 -> 0 bytes
-rw-r--r--Lib/test/imghdrdata/python.pbm3
-rw-r--r--Lib/test/imghdrdata/python.rasbin1056 -> 0 bytes
-rw-r--r--Lib/test/imghdrdata/python.sgibin1967 -> 0 bytes
-rw-r--r--Lib/test/imghdrdata/python.tiffbin1326 -> 0 bytes
-rw-r--r--Lib/test/imghdrdata/python.webpbin432 -> 0 bytes
-rw-r--r--Lib/test/test_imghdr.py144
-rw-r--r--Lib/test/test_tkinter/test_images.py8
-rw-r--r--Lib/test/test_tkinter/widget_tests.py2
-rw-r--r--Lib/test/tkinterdata/python.gif (renamed from Lib/test/imghdrdata/python.gif)bin405 -> 405 bytes
-rw-r--r--Lib/test/tkinterdata/python.pgm (renamed from Lib/test/imghdrdata/python.pgm)bin269 -> 269 bytes
-rw-r--r--Lib/test/tkinterdata/python.png (renamed from Lib/test/imghdrdata/python.png)bin1020 -> 1020 bytes
-rw-r--r--Lib/test/tkinterdata/python.ppm (renamed from Lib/test/imghdrdata/python.ppm)bin781 -> 781 bytes
-rw-r--r--Lib/test/tkinterdata/python.xbm (renamed from Lib/test/imghdrdata/python.xbm)0
17 files changed, 5 insertions, 152 deletions
diff --git a/Lib/test/imghdrdata/python-raw.jpg b/Lib/test/imghdrdata/python-raw.jpg
deleted file mode 100644
index 11940b3..0000000
--- a/Lib/test/imghdrdata/python-raw.jpg
+++ /dev/null
Binary files differ
diff --git a/Lib/test/imghdrdata/python.bmp b/Lib/test/imghdrdata/python.bmp
deleted file mode 100644
index 675f951..0000000
--- a/Lib/test/imghdrdata/python.bmp
+++ /dev/null
Binary files differ
diff --git a/Lib/test/imghdrdata/python.exr b/Lib/test/imghdrdata/python.exr
deleted file mode 100644
index 773c81e..0000000
--- a/Lib/test/imghdrdata/python.exr
+++ /dev/null
Binary files differ
diff --git a/Lib/test/imghdrdata/python.jpg b/Lib/test/imghdrdata/python.jpg
deleted file mode 100644
index 21222c0..0000000
--- a/Lib/test/imghdrdata/python.jpg
+++ /dev/null
Binary files differ
diff --git a/Lib/test/imghdrdata/python.pbm b/Lib/test/imghdrdata/python.pbm
deleted file mode 100644
index 1848ba7..0000000
--- a/Lib/test/imghdrdata/python.pbm
+++ /dev/null
@@ -1,3 +0,0 @@
-P4
-16 16
-ûñ¿úßÕ­±[ñ¥a_ÁX°°ðððð?ÿÿ \ No newline at end of file
diff --git a/Lib/test/imghdrdata/python.ras b/Lib/test/imghdrdata/python.ras
deleted file mode 100644
index 130e96f..0000000
--- a/Lib/test/imghdrdata/python.ras
+++ /dev/null
Binary files differ
diff --git a/Lib/test/imghdrdata/python.sgi b/Lib/test/imghdrdata/python.sgi
deleted file mode 100644
index ffe9081..0000000
--- a/Lib/test/imghdrdata/python.sgi
+++ /dev/null
Binary files differ
diff --git a/Lib/test/imghdrdata/python.tiff b/Lib/test/imghdrdata/python.tiff
deleted file mode 100644
index 39d0bfc..0000000
--- a/Lib/test/imghdrdata/python.tiff
+++ /dev/null
Binary files differ
diff --git a/Lib/test/imghdrdata/python.webp b/Lib/test/imghdrdata/python.webp
deleted file mode 100644
index e824ec7..0000000
--- a/Lib/test/imghdrdata/python.webp
+++ /dev/null
Binary files differ
diff --git a/Lib/test/test_imghdr.py b/Lib/test/test_imghdr.py
deleted file mode 100644
index 208c8ee..0000000
--- a/Lib/test/test_imghdr.py
+++ /dev/null
@@ -1,144 +0,0 @@
-import io
-import os
-import pathlib
-import unittest
-import warnings
-from test.support import findfile, warnings_helper
-from test.support.os_helper import TESTFN, unlink
-
-imghdr = warnings_helper.import_deprecated("imghdr")
-
-
-TEST_FILES = (
- ('python.png', 'png'),
- ('python.gif', 'gif'),
- ('python.bmp', 'bmp'),
- ('python.ppm', 'ppm'),
- ('python.pgm', 'pgm'),
- ('python.pbm', 'pbm'),
- ('python.jpg', 'jpeg'),
- ('python-raw.jpg', 'jpeg'), # raw JPEG without JFIF/EXIF markers
- ('python.ras', 'rast'),
- ('python.sgi', 'rgb'),
- ('python.tiff', 'tiff'),
- ('python.xbm', 'xbm'),
- ('python.webp', 'webp'),
- ('python.exr', 'exr'),
-)
-
-class UnseekableIO(io.FileIO):
- def tell(self):
- raise io.UnsupportedOperation
-
- def seek(self, *args, **kwargs):
- raise io.UnsupportedOperation
-
-class TestImghdr(unittest.TestCase):
- @classmethod
- def setUpClass(cls):
- cls.testfile = findfile('python.png', subdir='imghdrdata')
- with open(cls.testfile, 'rb') as stream:
- cls.testdata = stream.read()
-
- def tearDown(self):
- unlink(TESTFN)
-
- def test_data(self):
- for filename, expected in TEST_FILES:
- filename = findfile(filename, subdir='imghdrdata')
- self.assertEqual(imghdr.what(filename), expected)
- with open(filename, 'rb') as stream:
- self.assertEqual(imghdr.what(stream), expected)
- with open(filename, 'rb') as stream:
- data = stream.read()
- self.assertEqual(imghdr.what(None, data), expected)
- self.assertEqual(imghdr.what(None, bytearray(data)), expected)
-
- def test_pathlike_filename(self):
- for filename, expected in TEST_FILES:
- with self.subTest(filename=filename):
- filename = findfile(filename, subdir='imghdrdata')
- self.assertEqual(imghdr.what(pathlib.Path(filename)), expected)
-
- def test_register_test(self):
- def test_jumbo(h, file):
- if h.startswith(b'eggs'):
- return 'ham'
- imghdr.tests.append(test_jumbo)
- self.addCleanup(imghdr.tests.pop)
- self.assertEqual(imghdr.what(None, b'eggs'), 'ham')
-
- def test_file_pos(self):
- with open(TESTFN, 'wb') as stream:
- stream.write(b'ababagalamaga')
- pos = stream.tell()
- stream.write(self.testdata)
- with open(TESTFN, 'rb') as stream:
- stream.seek(pos)
- self.assertEqual(imghdr.what(stream), 'png')
- self.assertEqual(stream.tell(), pos)
-
- def test_bad_args(self):
- with self.assertRaises(TypeError):
- imghdr.what()
- with self.assertRaises(AttributeError):
- imghdr.what(None)
- with self.assertRaises(TypeError):
- imghdr.what(self.testfile, 1)
- with self.assertRaises(AttributeError):
- imghdr.what(os.fsencode(self.testfile))
- with open(self.testfile, 'rb') as f:
- with self.assertRaises(AttributeError):
- imghdr.what(f.fileno())
-
- def test_invalid_headers(self):
- for header in (b'\211PN\r\n',
- b'\001\331',
- b'\x59\xA6',
- b'cutecat',
- b'000000JFI',
- b'GIF80'):
- self.assertIsNone(imghdr.what(None, header))
-
- def test_string_data(self):
- with warnings.catch_warnings():
- warnings.simplefilter("ignore", BytesWarning)
- for filename, _ in TEST_FILES:
- filename = findfile(filename, subdir='imghdrdata')
- with open(filename, 'rb') as stream:
- data = stream.read().decode('latin1')
- with self.assertRaises(TypeError):
- imghdr.what(io.StringIO(data))
- with self.assertRaises(TypeError):
- imghdr.what(None, data)
-
- def test_missing_file(self):
- with self.assertRaises(FileNotFoundError):
- imghdr.what('missing')
-
- def test_closed_file(self):
- stream = open(self.testfile, 'rb')
- stream.close()
- with self.assertRaises(ValueError) as cm:
- imghdr.what(stream)
- stream = io.BytesIO(self.testdata)
- stream.close()
- with self.assertRaises(ValueError) as cm:
- imghdr.what(stream)
-
- def test_unseekable(self):
- with open(TESTFN, 'wb') as stream:
- stream.write(self.testdata)
- with UnseekableIO(TESTFN, 'rb') as stream:
- with self.assertRaises(io.UnsupportedOperation):
- imghdr.what(stream)
-
- def test_output_stream(self):
- with open(TESTFN, 'wb') as stream:
- stream.write(self.testdata)
- stream.seek(0)
- with self.assertRaises(OSError) as cm:
- imghdr.what(stream)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/Lib/test/test_tkinter/test_images.py b/Lib/test/test_tkinter/test_images.py
index b6f8b79..c07de86 100644
--- a/Lib/test/test_tkinter/test_images.py
+++ b/Lib/test/test_tkinter/test_images.py
@@ -66,7 +66,7 @@ class BitmapImageTest(AbstractTkTest, unittest.TestCase):
@classmethod
def setUpClass(cls):
AbstractTkTest.setUpClass.__func__(cls)
- cls.testfile = support.findfile('python.xbm', subdir='imghdrdata')
+ cls.testfile = support.findfile('python.xbm', subdir='tkinterdata')
def test_create_from_file(self):
image = tkinter.BitmapImage('::img::test', master=self.root,
@@ -150,7 +150,7 @@ class PhotoImageTest(AbstractTkTest, unittest.TestCase):
@classmethod
def setUpClass(cls):
AbstractTkTest.setUpClass.__func__(cls)
- cls.testfile = support.findfile('python.gif', subdir='imghdrdata')
+ cls.testfile = support.findfile('python.gif', subdir='tkinterdata')
def create(self):
return tkinter.PhotoImage('::img::test', master=self.root,
@@ -163,7 +163,7 @@ class PhotoImageTest(AbstractTkTest, unittest.TestCase):
return tkinter._join(args)
def check_create_from_file(self, ext):
- testfile = support.findfile('python.' + ext, subdir='imghdrdata')
+ testfile = support.findfile('python.' + ext, subdir='tkinterdata')
image = tkinter.PhotoImage('::img::test', master=self.root,
file=testfile)
self.assertEqual(str(image), '::img::test')
@@ -178,7 +178,7 @@ class PhotoImageTest(AbstractTkTest, unittest.TestCase):
self.assertNotIn('::img::test', self.root.image_names())
def check_create_from_data(self, ext):
- testfile = support.findfile('python.' + ext, subdir='imghdrdata')
+ testfile = support.findfile('python.' + ext, subdir='tkinterdata')
with open(testfile, 'rb') as f:
data = f.read()
image = tkinter.PhotoImage('::img::test', master=self.root,
diff --git a/Lib/test/test_tkinter/widget_tests.py b/Lib/test/test_tkinter/widget_tests.py
index 85b0511..f60087a 100644
--- a/Lib/test/test_tkinter/widget_tests.py
+++ b/Lib/test/test_tkinter/widget_tests.py
@@ -250,7 +250,7 @@ class StandardOptionsTests:
widget = self.create()
self.checkParam(widget, 'bitmap', 'questhead')
self.checkParam(widget, 'bitmap', 'gray50')
- filename = test.support.findfile('python.xbm', subdir='imghdrdata')
+ filename = test.support.findfile('python.xbm', subdir='tkinterdata')
self.checkParam(widget, 'bitmap', '@' + filename)
# Cocoa Tk widgets don't detect invalid -bitmap values
# See https://core.tcl.tk/tk/info/31cd33dbf0
diff --git a/Lib/test/imghdrdata/python.gif b/Lib/test/tkinterdata/python.gif
index efa0be3..efa0be3 100644
--- a/Lib/test/imghdrdata/python.gif
+++ b/Lib/test/tkinterdata/python.gif
Binary files differ
diff --git a/Lib/test/imghdrdata/python.pgm b/Lib/test/tkinterdata/python.pgm
index 8349f2a..8349f2a 100644
--- a/Lib/test/imghdrdata/python.pgm
+++ b/Lib/test/tkinterdata/python.pgm
Binary files differ
diff --git a/Lib/test/imghdrdata/python.png b/Lib/test/tkinterdata/python.png
index 1a987f7..1a987f7 100644
--- a/Lib/test/imghdrdata/python.png
+++ b/Lib/test/tkinterdata/python.png
Binary files differ
diff --git a/Lib/test/imghdrdata/python.ppm b/Lib/test/tkinterdata/python.ppm
index 7d9cdb3..7d9cdb3 100644
--- a/Lib/test/imghdrdata/python.ppm
+++ b/Lib/test/tkinterdata/python.ppm
Binary files differ
diff --git a/Lib/test/imghdrdata/python.xbm b/Lib/test/tkinterdata/python.xbm
index cfbee2e..cfbee2e 100644
--- a/Lib/test/imghdrdata/python.xbm
+++ b/Lib/test/tkinterdata/python.xbm