|
2 | 2 |
|
3 | 3 | from PIL import Image, TiffImagePlugin |
4 | 4 | from PIL._util import py3 |
| 5 | + |
| 6 | +from io import BytesIO |
5 | 7 | import os |
| 8 | +import sys |
6 | 9 |
|
7 | 10 |
|
8 | 11 | class TestImage(PillowTestCase): |
@@ -62,8 +65,7 @@ def test_width_height(self): |
62 | 65 |
|
63 | 66 | def test_invalid_image(self): |
64 | 67 | if py3: |
65 | | - import io |
66 | | - im = io.BytesIO(b'') |
| 68 | + im = BytesIO(b'') |
67 | 69 | else: |
68 | 70 | import StringIO |
69 | 71 | im = StringIO.StringIO('') |
@@ -324,8 +326,29 @@ def test_registered_extensions(self): |
324 | 326 | for ext in ['.cur', '.icns', '.tif', '.tiff']: |
325 | 327 | self.assertIn(ext, extensions) |
326 | 328 |
|
327 | | - def test_no_convert_mode(self): |
328 | | - self.assertTrue(not hasattr(TiffImagePlugin, '_convert_mode')) |
| 329 | + def test_supported_modes(self): |
| 330 | + for format in Image.MIME.keys(): |
| 331 | + try: |
| 332 | + save_handler = Image.SAVE[format] |
| 333 | + except KeyError: |
| 334 | + continue |
| 335 | + plugin = sys.modules[save_handler.__module__] |
| 336 | + if not hasattr(plugin, '_supported_modes'): |
| 337 | + continue |
| 338 | + |
| 339 | + # Check that the supported modes list is accurate |
| 340 | + supported_modes = plugin._supported_modes() |
| 341 | + for mode in ['1', 'L', 'P', 'RGB', 'RGBA', 'CMYK', 'YCbCr', 'LAB', |
| 342 | + 'HSV', 'I', 'F', 'LA', 'La', 'RGBX', 'RGBa']: |
| 343 | + out = BytesIO() |
| 344 | + im = Image.new(mode, (100, 100)) |
| 345 | + if mode in supported_modes: |
| 346 | + im.save(out, format) |
| 347 | + else: |
| 348 | + self.assertRaises(Exception, im.save, out, format) |
| 349 | + |
| 350 | + def test_no_supported_modes_method(self): |
| 351 | + self.assertTrue(not hasattr(TiffImagePlugin, '_supported_modes')) |
329 | 352 |
|
330 | 353 | temp_file = self.tempfile("temp.tiff") |
331 | 354 |
|
|
0 commit comments